GithubHelp home page GithubHelp logo

guangie88 / spdlog_setup Goto Github PK

View Code? Open in Web Editor NEW
77.0 9.0 40.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 Issues

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.

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?

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.

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]

[[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"

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.

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.

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.

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?

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

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.

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

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)

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

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

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

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

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?

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

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.

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.