GithubHelp home page GithubHelp logo

Comments (5)

guangie88 avatar guangie88 commented on June 16, 2024

There is no restriction as to where you should be saving your TOML config for spdlog_setup, it works the same way as you would do ifstream to open file based on your pwd. You can first try with ifstream to open the file and read out the file string content, and if it works, spdlog_setup::from_file will work with the same given path.

To try to provide additional help, assuming you have your working directory at /path/to/your/dir and your compiled progam is named yourprogram, and your program follows the example to read like this spdlog_setup::from_file("log_conf.toml");, you should have your CMD/bash to be be in /path/to/your/dir first, then execute your program with ./yourprogram (or yourprogram.exe if CMD).

If you are still unable to get it working, you should clarify how where are your executable and config file are located.

from spdlog_setup.

nj2901 avatar nj2901 commented on June 16, 2024

No i put it in the same directory (my code and the config file) but i am getting setup error :

#include "spdlog_setup/conf.h"

#include <iostream>
#include <string>

int main() {
    try {
        // spdlog_setup::setup_error thrown if file not found
        spdlog_setup::from_file("log_conf.toml");

        // assumes that root logger has been initialized
        
        std::cout<<"Printing data\n"<<std::flush;
        auto logger = spdlog::get("root");
        logger->trace("trace message");
        logger->debug("debug message");
        logger->info("info message");
        logger->warn("warn message");
        logger->error("error message");
        logger->critical("critical message");
        logger->info("Print data");
        std::cout<<"Printing data\n"<<std::flush;

        // ...
    } catch (const spdlog_setup::setup_error &) {
        std::cout<<"Printing data in 1st catch\n"<<std::flush; // this statement is printing for me
        // ...
    } catch (const std::exception &) {
        std::cout<<"Printing data in 2nd catch\n"<<std::flush;
        // ...
    }
}


I am compiling as below :

clang++ -o staticConfigFileSetup staticConfigFileSetup.cpp

and my config file resides in the same path as of my code.

Moreover,

You can first try with ifstream to open the file and read out the file string content, and if it works, 

i tried this and it works fine.

from spdlog_setup.

guangie88 avatar guangie88 commented on June 16, 2024

Okay then in that case, I will assume that you have your binary + config TOML file + you are running your command with relative path in the same dir as the binary.

I will need you to do these two things before I can help:

  1. Show the content log_conf.toml that you are using that gives the error.
  2. Do the following to show what is the error message in setup_error:
} catch (const spdlog_setup::setup_error &e) {
    std::cout << e.what() << "\n";
} ...

from spdlog_setup.

nj2901 avatar nj2901 commented on June 16, 2024

e.what()

Printing data in 1st catch
Sink 'syslog_st' error:
 > Invalid sink type 'syslog_sink_st' found

log_conf.toml


# level is optional for both sinks and loggers
# level for error logging is 'err', not 'error'
# _st => single threaded, _mt => multi threaded
# syslog_sink is automatically thread-safe by default, no need for _mt suffix

# max_size supports suffix
# - T (terabyte)
# - G (gigabyte)
# - M (megabyte)
# - K (kilobyte)
# - or simply no suffix (byte)

# check out https: // github.com/gabime/spdlog/wiki/3.-Custom-formatting
global_pattern = "[%Y-%m-%dT%T%z] [%L] <%n>: %v"

[[sink]]
name = "console_st"
type = "stdout_sink_st"

[[sink]]
name = "console_mt"
type = "stdout_sink_mt"

[[sink]]
name = "color_console_st"
type = "color_stdout_sink_st"

[[sink]]
name = "color_console_mt"
type = "color_stdout_sink_mt"

[[sink]]
name = "file_out"
type = "basic_file_sink_st"
filename = "log/spdlog_setup.log"
# truncate field is optional
# truncate = false (default)
level = "info"
# optional flag to indicate the set - up to create the log dir first
create_parent_dir = true

[[sink]]
name = "file_err"
type = "basic_file_sink_mt"
filename = "log/spdlog_setup_err.log"
truncate = true
level = "err"
# to show that create_parent_dir is indeed optional(defaults to false)

[[sink]]
name = "rotate_out"
type = "rotating_file_sink_st"
base_filename = "log/rotate_spdlog_setup.log"
max_size = "1M"
max_files = 10
level = "info"

[[sink]]
name = "rotate_err"
type = "rotating_file_sink_mt"
base_filename = "log/rotate_spdlog_setup_err.log"
max_size = "1M"
max_files = 10
level = "err"

[[sink]]
name = "daily_out"
type = "daily_file_sink_st"
base_filename = "log/daily_spdlog_setup.log"
rotation_hour = 17
rotation_minute = 30
level = "info"

[[sink]]
name = "daily_err"
type = "daily_file_sink_mt"
base_filename = "log/daily_spdlog_setup_err.log"
rotation_hour = 17
rotation_minute = 30
level = "err"

[[sink]]
name = "null_sink_st"
type = "null_sink_st"

[[sink]]
name = "null_sink_mt"
type = "null_sink_mt"

# only works for Linux
[[sink]]
name = "syslog_st"
type = "syslog_sink_st"
# generally no need to fill up the optional fields below
# ident = "" (default)
# syslog_option = 0 (default)
# syslog_facility = LOG_USER (default macro value)

# only works for Linux
[[sink]]
name = "syslog_mt"
type = "syslog_sink_mt"
# generally no need to fill up the optional fields below
# ident = "" (default)
# syslog_option = 0 (default)
# syslog_facility = LOG_USER (default macro value)

[[pattern]]
name = "succient"
value = "%c-%L: %v"

[[logger]]
name = "root"
sinks = [
    "color_console_mt",
    "rotate_out", "rotate_err"]
level = "trace"

[[logger]]
name = "console"
sinks = ["console_st", "console_mt"]
pattern = "succient"

from spdlog_setup.

guangie88 avatar guangie88 commented on June 16, 2024

I will be assuming that you are on Linux, since syslog is not supported on Windows (OSX should be fine I think?)

Based on the error message: "Invalid sink type 'syslog_sink_st' found", the most likely reason is that your spdlog_setup is not from the latest tag v0.3.0-alpha.2 (or latest commit, whichever is fine).

There was a breaking change between v0.3.0-alpha.1 and v0.3.0-alpha.2; v0.3.0-alpha.1 only supports pre-v1.X spdlog and uses syslog_sink instead of syslog_sink_st (see: https://github.com/guangie88/spdlog_setup/tree/v0.3.0-alpha.1#static-file-configuration, and search for syslog_sink), while v0.3.0-alpha.2 uses both syslog_sink_st and syslog_sink_mt (which follows the same example as the current master README.md). So in order to fix the problem, do make sure you are using either the latest commit of spdlog_setup, or use v0.3.0-alpha.2.

In any case, you might not need syslog sink (or the many other types of sink in the example) to begin with, so it will also work if you just remove syslog sinks from your TOML config.

Hope this helps to make your set-up work.

from spdlog_setup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.