GithubHelp home page GithubHelp logo

guangie88 / spdlog_setup Goto Github PK

View Code? Open in Web Editor NEW
77.0 9.0 39.0 325 KB

spdlog setup initialization via file configuration for convenience.

License: MIT License

CMake 4.92% C++ 94.50% Shell 0.34% C 0.24%
spdlog setup initialize init logging logger log cpp config configuration

spdlog_setup's Introduction

spdlog_setup (spdlog setup)

Overview

Header-only spdlog file-based setup library for convenience in initializing spdlog. Inspired by spdlog-config for using TOML configuration, a format that is simple and easy-to-read.

Build Status Build status codecov

Requirements

Requires at least CMake 3.3, g++-4.9 for Linux, or MSVC2015 with MSBuild for Windows, providing sufficient C++11 features.

g++-4.8 will notably fail because of the missing std::regex implementation. MSVC2013 will fail too as it does not accept noexcept, which is used in some of the functions.

Tested against:

  • g++-4.9
  • g++-5
  • g++-6
  • g++-7
  • g++-8
  • clang-3.6
  • clang-3.7
  • clang-3.8
  • clang-3.9
  • clang-4.0
  • clang-5.0
  • clang-6.0
  • clang-7
  • cl (v140 / MSVC2015)
  • cl (v141 / MSVC2017)

Features

  • Header-only (check How to Install to extract out the header files).
  • Initialization of spdlog sinks, patterns and loggers based on TOML configuration file.
  • Tag replacement (e.g. "{tagname}-log.txt") within the TOML configuration file.
  • Throw exception describing the error during the parsing of the config file.

Changelog

See CHANGELOG.md for more details.

Repository Checkout

Since this repository has other git-based dependencies as git submodules, use the command: git clone --recursive https://github.com/guangie88/spdlog_setup.git in order to clone all the submodule dependencies.

If the repository has already been cloned without the submodules, then instead run: git submodule update --init --recursive in order to clone all the submodule dependencies.

Dependencies

This repository uses the following external dependencies directly:

  • Catch (only for unit-tests, not included in installation)
  • spdlog

In addition, the following dependencies are inlined as part of the include:

How to Build

This guide prefers a CMake out-of-source build style. For build with unit tests, add -DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON during the CMake configuration.

How to Install

If a recent enough spdlog is already available, and unit tests are not to be run, it is possible to just copy the spdlog_setup directory within include into another solution for header-only include, as long as spdlog can be found in that solution.

If spdlog is not available, the installation step of CMake can copy out the entire list of header files required for spdlog_setup into the installation directory, including spdlog. To change the installation directory, add -DCMAKE_INSTALL_PREFIX=<path-to-install> during the CMake configuration.

Linux (GCC)

In the root directory after git cloning:

Debug without Installation

  • mkdir build-debug
  • cd build-debug
  • cmake .. -DCMAKE_BUILD_TYPE=Debug -DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON
  • cmake --build .

Now the unit test executable should be compiled and residing in build-debug/spdlog_setup_unit_test.

Release with Installation

  • mkdir build-release
  • cd build-release
  • cmake .. -DCMAKE_BUILD_TYPE=Release -DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON -DCMAKE_INSTALL_PREFIX=install
  • cmake --build . --target install

Now the unit test executable should be compiled and residing in build-release/spdlog_setup_unit_test.

The header files should be installed in build-release/install/include.

Windows (MSVC2015 as Example)

Ensure that Microsoft Build Tools 2015 and Visual C++ Build Tools 2015 (or Visual Studio 2015) have been installed.

In the root directory after git cloning:

  • mkdir build
  • cd build
  • cmake .. -G "Visual Studio 14 Win64" -DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON -DCMAKE_INSTALL_PREFIX=install
  • (Debug) cmake --build . --config Debug
  • (Release with installation) cmake --build . --config Release --target install

Now the unit test executable should be compiled and residing in

  • (Debug) build/Debug/spdlog_setup_unit_test.exe or
  • (Release) build/Release/spdlog_setup_unit_test.exe.

The header files should be installed in build/install/include.

Supported Sinks

  • stdout_sink_st
  • stdout_sink_mt
  • stderr_sink_st
  • stderr_sink_mt
  • color_stdout_sink_st
  • color_stdout_sink_mt
  • color_stderr_sink_st
  • color_stderr_sink_mt
  • basic_file_sink_st
  • basic_file_sink_mt
  • rotating_file_sink_st
  • rotating_file_sink_mt
  • daily_file_sink_st
  • daily_file_sink_mt
  • null_sink_st
  • null_sink_mt
  • syslog_sink (only for Linux, SPDLOG_ENABLE_SYSLOG preprocessor definition must be defined before any spdlog/spdlog_setup header is included)

Currently ostream_sink and dist_sink do not fit into the use case and are not supported.

For more information about how the above sinks work in spdlog, please refer to the original spdlog sinks wiki page at: https://github.com/gabime/spdlog/wiki/4.-Sinks.

TOML Configuration Example

Static File Configuration

# 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)

# only works for Windows
[[sink]]
name = "msvc_st"
type = "msvc_sink_st"

# only works for Windows
[[sink]]
name = "msvc_mt"
type = "msvc_sink_mt"

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

[[logger]]
name = "root"
sinks = [
    "console_st", "console_mt",
    "color_console_st", "color_console_mt",
    "daily_out", "daily_err",
    "file_out", "file_err",
    "rotate_out", "rotate_err",
    "null_sink_st", "null_sink_mt",
    "syslog_st", "syslog_mt"]
level = "trace"

[[logger]]
name = "windows_only"
sinks = ["msvc_st", "msvc_mt"]

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

# Async

[global_thread_pool]
queue_size = 8192
num_threads = 1

[[thread_pool]]
name = "tp"
queue_size = 4096
num_threads = 2

[[logger]]
type = "async"
name = "global_async"
sinks = ["console_mt"]
pattern = "succient"

[[logger]]
type = "async"
name = "local_async"
sinks = ["console_mt"]
pattern = "succient"
thread_pool = "tp"
overflow_policy = "overrun_oldest"  # block (default) | overrun_oldest

Tagged-Base Pre-TOML File Configuration

# level is optional for both sinks and loggers
# level for error logging is 'err', not 'error'

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

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

[[sink]]
name = "rotate_out"
type = "rotating_file_sink_mt"
base_filename = "log/{index}-info/simple-{path}.log"
max_size = "1M"
max_files = 10
level = "info"
# optional flag to indicate the set - up to create the log dir first
create_parent_dir = true

[[sink]]
name = "simple_err"
type = "basic_file_sink_mt"
filename = "log/{index}-err/simple-{path}.log"
truncate = false
level = "err"
# optional flag to indicate the set - up to create the log dir first
create_parent_dir = true

[[logger]]
name = "root"
sinks = ["console", "rotate_out", "simple_err"]
level = "trace"

Use Examples

Static Configuration File

#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
        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");

        // ...
    } catch (const spdlog_setup::setup_error &) {
        // ...
    } catch (const std::exception &) {
        // ...
    }
}

Tagged Based Configuration File

#include "spdlog_setup/conf.h"

#include <string>

int main(const int argc, const char * argv[]) {
    // assumes both index and path are given by command line arguments

    try {
        // gets index integer, e.g. 123
        const auto index = std::stoi(argv[1]);

        // gets path string, e.g. a/b/c
        const auto path = std::string(argv[2]);

        // performs parsing with dynamic tag value replacements
        // tags are anything content that contains {xxx}, where xxx is the name
        // of the tag to be replaced
        spdlog_setup::from_file_with_tag_replacement(
            "log_conf.pre.toml",
            // replaces {index} with actual value in current variable index via
            // fmt mechanism
            fmt::arg("index", index),
            // replaces {path} with actual value in current variable path
            fmt::arg("path", path));

        auto logger = spdlog::get("root");
        // ...
    } catch (const spdlog_setup::setup_error &) {
        // ...
    } catch (const std::exception &) {
        // ...
    }
}

Notes

  • Make sure that the directory for the log files to reside in exists before using spdlog, unless the create_parent_dir flag is set to true for the sink.
  • For the current set of unit tests, the working directory must be at the git root directory or in build directory so that the TOML configuration files in config directory can be found.

Contributions

Pull requests are welcome!

To make the code formatting more objective, clang-format is used to format all the source code files.

Please try to run

./run-clang-format.sh

which will pull the appropriate Docker image to run the formatting command over the entire repository directory.

If your docker command requires sudo, then you will need to run it as

sudo sh ./run-clang-format.sh

Alternatively, you could also try to set up your own clang-format (currently this repository uses version 7), and run

clang-format -i path_to_h_cpp_file

over the changed files.

spdlog_setup's People

Contributors

davidwed avatar gegles avatar guangie88 avatar hramoser avatar jakecobb avatar nextsilicon-itay-bookstein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spdlog_setup's Issues

Find package fail when installed using submodule spdlog

Somewhat related PR and issue: #21, #22

If spdlog_setup was installed with its spdlog found using find_package (i.e. no submodule spdlog), creating a dummy set-up to find_package(spdlog_setup) works perfectly after #22.

However using submodule causes the spdlog::spdlog import to fail using the dummy set-up:

CMake Error at CMakeLists.txt:5 (find_package):
  Found package configuration file:

    /usr/local/lib/cmake/spdlog_setup/spdlog_setup-config.cmake

  but it set spdlog_setup_FOUND to FALSE so package "spdlog_setup" is
  considered to be NOT FOUND.  Reason given by package:

  The following imported targets are referenced, but are missing:
  spdlog::spdlog

Clean up README

  • Fix tag replacement portion once templating engine is publicly usable
  • Remove fmt from dependency, since it is no longer part of this repo, but included from spdlog instead
  • Make it specific as to which version range of spdlog is supported.

external spdlog package not found

I have build spdlog library separately and copied the exported cmake package of it.
I tried to build spdlog_setup librabies unittests using the -DCMAKE_PREFIX_PATH= command line switch.
cmake has found the package correctly and initialized the spdlog_DIR:PATH= to the correct value

But the "AdditionalIncludeDirectories" entry inside the vcxproj does not includes path to spdlog include folder.

As a result the build of unittest project fails since the spdlog inlude is not found

Full command line
cmake.exe -H. -B_builds "-GVisual Studio 15 2017" -DCMAKE_INSTALL_PREFIX=package -DCMAKE_BUILD_TYPE=Release -DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON -DCMAKE_PREFIX_PATH=d:\spdlog\release.32

cmake.exe --build _builds --config Release

Compilation error
include\spdlog_setup\details\conf_impl.h(20): fatal error C10
83: Cannot open include file: 'spdlog/spdlog.h': No such file or directory [testing_ut
2\spdlog_setup_builds\spdlog_setup_unit_test.vcxproj]

Is the building of spdlog_setup using external spdlog library supported?

Save Modified Config File

Hi,

I came over from the original spdlog repo after I found this awesome extension for spdlog. After the removal of the dependencies its really much leaner and I am planning to use this in our production software. I extended spdlog myself before in a similar way, making it possible to load only log levels from a file. Being able to fully setup the loggers and sinks via config file is a very good improvement. The only thing my implementation provided which is missing now is the option to permanently change the config during runtime. Do you think a option like this could be implemented here also?

I could imagine a solution wich looks like this:

  • The default_config.toml is never touched
  • If the user modifies the log level during runtime and wants this change to persist he can save this.
  • A new custom_config.toml is created and saved to disc.
  • When the program starts and tries to load the default_config.toml it looks for a custom_config.toml and prefers this over the default_config.toml if found.
  • The user can also reset to default_config.toml at any time and the custom_config.toml is deleted.
  • A restart of the program would now load the default_config.toml since it cant find any other.

How do you think? Could you imagine such a feature?

Cheers!

Invalid Format String Error on using "from_file_with_tag_replacement()"

Hi @guangie88 , I am facing a strange problem while using the method "from_file_with_tag_replacement". I have written the following code

   try{
        const auto path_arg = fmt::arg("path", "log");
        spdlog_setup::from_file_with_tag_replacement(
            "log_conf.toml",
            path_arg
        );
        auto file_logger = spdlog::get("root");
        spdlog::set_default_logger(file_logger);
    }
    catch ( const spdlog_setup::setup_error err)
    {
        std::cout<<err.what();
    }

I get the output as invalid format string.

The config TOML file log_conf.toml looks like this

global_pattern = "{\"timestamp\"=\"%Y-%m-%d %H:%M:%S.%f %z\", \"logger\"=\"%n\", \"severity\"=\"%l\", \"file\"=\"%s\", \"line\"=\"%#\", \"message\"=\"%v\"}"

[[sink]]
name = "basic_logger"
type = "basic_file_sink_st"
filename = "{path}/spdlog_setup.log"
create_parent_dir = true

[[logger]]
name = "root"
sinks = ["basic_logger"]
level = "critical"

Please help me solve this problem. I have wasted a lot of time on this without much success.

Allow to use external deps?

If a project already uses one of the deps (especially if it’s within the same cmake build), it would nice to be able to tell spdlog_setup to use them.

Getting " error LNK2005" on Windows

In my project, I checkout spdlog & spdlog_setup as submodules and use add_subdirectory to add them to my project. This works fine on all platforms, but on Windows I get:

spdlogd.lib(fmt.obj) : error LNK2005: "public: void __cdecl fmt::v6::internal::error_handler::on_error(char const *)" (?on_error@error_handler@internal@v6@fmt@@QEAAXPEBD@Z) already define
d in gateway_main.obj [C:\Users\gegles\Workspaces\ibm\fasp.io\_builds\windows-vs\cpp\gateway\fasp.io-gateway.vcxproj]
spdlogd.lib(fmt.obj) : error LNK2005: "public: virtual __cdecl fmt::v6::format_error::~format_error(void)" (??1format_error@v6@fmt@@UEAA@XZ) already defined in gateway_main.obj [C:\Users\
gegles\Workspaces\ibm\fasp.io\_builds\windows-vs\cpp\gateway\fasp.io-gateway.vcxproj]
C:\Users\gegles\Workspaces\ibm\fasp.io\_builds\windows-vs\bin\Debug\fasp.io-gateway.exe : fatal error LNK1169: one or more multiply defined symbols found [C:\Users\gegles\Workspaces\ibm\f
asp.io\_builds\windows-vs\cpp\gateway\fasp.io-gateway.vcxproj]

I've tried different things (e.g. checkout fmt also as a submodule and use SPDLOG_FMT_EXTERNAL) but I get the same error.

Any thoughts?

Windows build problem C:2280

when i using this library to compile in windows i am getting following error
unwind semantics are not enabled. Specify /EHsc [D:\Open_source_latest_build\nov-decoder-develop\node-test\build\convertaddon.vcxproj]
d:\open_source_latest_build\nov-decoder-develop\node-test\lib\includelib\spdlog_setup\details\third_party\cpptoml.h(577): error C2280: 'std::share
d_ptr<cpptoml::value> std::dynamic_pointer_cast<cpptoml::value,cpptoml::base>(const std::shared_ptrcpptoml::base &) noexcept': a
ttempting to reference a deleted function [D:\Open_source_latest_build\nov-decoder-develop\node-test\build\convertaddon.vcxproj]

Where to store config file

Hi,
its a wonderful work here but i was trying to execute the examples given and getting setup error .

Can you please help that where should i be saving my conf.toml file ?
I am saving it in the same folder as of my script. but i am getting exception of setup_Error

Global pattern not used for multiple loggers

Only the first logger uses global_pattern. Following loggers are assigned an empty pattern.
Reason: global_pattern_opt is moved instead of assigned (conf_impl.h, line 1113).

Feature request: yaml configuration file

Hello,

thank you for your great work. I've kept wondering why you are using .toml file, which are less common than for example .yaml file, and more tedious to read (especially when you don't have a plugin, like in Eclipse).

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

# only works for Linux
[[sink]]
name = "syslog_st"
type = "syslog_sink_st"

whereas you could have a more elegant and less redundant:

sink:
    null_sink_mt: 
           type: null_sink_mt
           level: info
    syslog_st: # only work for Linux
           type: syslog_sink_st

Thank you for your time.

Cross Compiling Broken

The recent changes to the CMakeLists.txt broke cross compiling for the package.

The compiler gives the following error message:

-- Check if compiler accepts -pthread
CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
   THREADS_PTHREAD_ARG (advanced)
For details see /builds/buildroot/output/build/spdlog_setup-b18c8577ce0edc1c35b0ec5b7c45d7bffdd6dd18/TryRunResults.cmake
-- Check if compiler accepts -pthread - no
-- Found Threads: TRUE
-- The C compiler identification is GNU 7.3.0

It seems the changes you made to thread linking broke it for some reason.

#17 should fix this

Compilation error: spdlog update?!

Trying to compile spdlog_setup with the recent version (github) of spdlog:

/usr/local/include/spdlog_setup/details/conf_impl.h:18:10: fatal error: spdlog/sinks/file_sinks.h: No such file or directory

and yes, it looks that the file was renamed.

Multiply defined symbols linker error when using with compiled spdlog lib

When using spdlog as a compiled library in a project, trying to use spdlog_setup will result in multiply defined symbols linker errors:

spdlog.lib(fmt.cpp.obj) : error LNK2005: "public: virtual __cdecl fmt::v6::format_error::~format_error(void)" (??1format_error@v6@fmt@@UEAA@XZ) already defined in core_application.cpp.obj

This led me to fmtlib/fmt#372 (comment) which in turn led me to look for this in spdlog_setup sources.

In conf_impl.h, changing

#ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY
#endif

to

#if !defined(SPDLOG_COMPILED_LIB) && !defined(FMT_HEADER_ONLY)
#define FMT_HEADER_ONLY
#endif

seems to correctly not set FMT_HEADER_ONLY and allows linking on windows.

Pattern takes the last entry

Hello.

It seems that different loggers cannot have different patterns anymore (they could previously, but not in the present version of the code, I updated yesterday after a few months). I couldn't spot in which commit the difference appeared.

Here is a code to reproduce the issue (root writes its output with a 'simple' pattern where it should have a 'complex' one). Apparently, the last "pattern" found in the config file is used for every 'logger' used with "console". On the contrary, the debug level works well.

#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
        auto logger = spdlog::get("root");
        logger->trace("trace message");
        logger->debug("debug message");
        logger->info("info message");

        auto logger2 = spdlog::get("other");
        logger2->trace("trace message");
        logger2->debug("debug message");
        logger2->info("info message");

        // ...
    } catch (const spdlog_setup::setup_error & exception) {
        // ...
    } catch (const std::exception & exception) {
   }
}

with toml file :

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

[[pattern]]
name = "complex"
value = "[%Y-%m-%d %T,%e %n] <%l> %v"
[[pattern]]
name = "simple"
value = "%n %v"

[[logger]]
name = "root"
sinks = ["console"]
level = "trace"
pattern = "complex"

[[logger]]
name = "other"
sinks = ["console"]
level = "debug"
pattern = "simple"

outputs

root trace message
root debug message
root info message
other debug message
other info message

set logger type (sync/async) failed with exception

setup below logger with async type failed with exception. Possibly because we create a static logger inited before global SYNC_MAP (which is empty according to debugger)

[[logger]]
name = "root"
sinks = ["console"]
level = "debug"
type = "async"
image

spdlog_setup tries to find spdlog but doesn't exist

I have a cmake project which fetches spdlog from git using FetchContent. This effectively defines a spdlog::spdlog target since it includes spdlog CMakeLists into my project.

Then I also fetch spdlog_setup. This step fails because spdlog_setup assumes we are going to use spdlog from deps/spdlog or from system (via find_package(spdlog REQUIRED). Since there is no package in system, it fails.

If spdlog::spdlog target is already defined, it shouldn't call find_package(spdlog REQUIRED)

[[thread_pool]] has bug

const auto thread_pools_map = setup_thread_pools(config); // set up loggers, setting the respective sinks and patterns setup_loggers(config, sinks_map, patterns_map, thread_pools_map);

thread_pools_map has contain std::shared_ptr, out of scope, thread_pool will be released, but logger still in use;logger has a thread_pool variable, the thread_pool variable is std::weak_ptr, that do not own raw ptr.

spdlog define
SPDLOG_INLINE spdlog::async_logger::async_logger( std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy) : async_logger(std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy) {}

logger write log, will throw exception。

"async log: thread pool doesn't exist anymore"

Support for async logging

I've looked everywhere but can't seem to find how to enable async logging via spdlog_setup.

Am I missing something? Is this planned to be supported soon?

Failed to initialize logger from file if one of the loggers already exists (spdlog 1.3.1)

If logger with specific name was created prior to call spdlog_setup::from_file_with_tag_replacement and logger with the same name encountered in the toml file - the spdlog library will throw the exception throw spdlog_ex("logger with name '" + logger_name + "' already exists"); when trying to create logger as a result whole initialization fails.

Probably better approach would be before trying to create logger with const auto logger = make_shared<spdlog::logger>( name, logger_sinks.cbegin(), logger_sinks.cend());
to query spdlog and if logger exists just replace the sinks using logger::sinks() api

CMake config uses wrong target name

Version 2.0 but I glanced at master and it seems to have the same issue.

spdlog_setup-target.cmake defines the spdlog_setup::spdlog_setup target, but spdlog_setup-config.cmake tries to reference the spdlog_setup target. This causes an error for my find_package on CMake 3.9.2. Manually editing spdlog_setup-config.cmake to reference spdlog_setup::spdlog_setup instead fixed it for me.

Properly "link" with the right spdlog target

In my project's 3rdparty directory I have submodules for spdlog and spdlog_setup, defined as follows in the 3rdparty/CMakeLists.txt:

### spdlog  
add_subdirectory(spdlog EXCLUDE_FROM_ALL)

### spdlog_setup
option(SPDLOG_SETUP_CPPTOML_EXTERNAL "Use external CPPTOML library instead of bundled" ON)
add_subdirectory(spdlog_setup EXCLUDE_FROM_ALL)

spdlog_setup refers to the spdlog target here like this:

target_link_libraries(spdlog_setup
  INTERFACE
    spdlog)

This seems to have 2 undesirable effects:

  1. Despite the EXCLUDE_FROM_ALL, the spdlog library is compiled
  2. Even when spdlog::spdlog_header_only is being used (as a dep) by the top-level executable, the spdlog static library is also being add the to linker... (to be verified, but it would make sense).

Could spdlog_setup be changed to simply use target_link_libraries(spdlog_setup INTERFACE spdlog::spdlog_header_only) or to have some logic to determine whether to use spdlog::spdlog or spdlog::spdlog_header_only as an INTERFACE library?

Thx.

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.