guangie88 / spdlog_setup Goto Github PK
View Code? Open in Web Editor NEWspdlog setup initialization via file configuration for convenience.
License: MIT License
spdlog setup initialization via file configuration for convenience.
License: MIT License
Push master branch to "v0.3.0-alpha.2" tag
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:
EXCLUDE_FROM_ALL
, the spdlog
library is compiledspdlog::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.
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?
fmt
from dependency, since it is no longer part of this repo, but included from spdlog
insteadspdlog
is supported.Makes it hard for people to locate all the include files in a single place.
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]
Please, pretty please, add conan support for this great library! It is the last remaining dependency (out of 7) in our project that is not available on Conan Center. For inspiration, one can look at this project: https://github.com/jgsogo/conan-spdlog_setup.
Thanks!
Hi @guangie88 , Is it at all possible to fetch environment variable directly in the TOML file other than the tag-based approach?
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"
Need to be applied in the function from_file_and_override_with_tag_replacement
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.
Should support both global and per logger format patterns.
linked dll with big size, it take 16MB in mingw, and 2M in vs2019, only with demo
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:
default_config.toml
is never touchedcustom_config.toml
is created and saved to disc.default_config.toml
it looks for a custom_config.toml
and prefers this over the default_config.toml
if found.default_config.toml
at any time and the custom_config.toml
is deleted.default_config.toml
since it cant find any other.How do you think? Could you imagine such a feature?
Cheers!
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.
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.
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.
This is caused by the missing last argument. This argument is added to syslog sink constructor in commit gabime/spdlog@e68cf1c .
https://github.com/guangie88/spdlog_setup/blob/master/include/spdlog_setup/details/conf_impl.h#L861
return make_shared<SyslogSink>(ident, syslog_option, syslog_facility);
Adding a boolean argument at the end of the list, or using the syslog sink factory fixes the issue.
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?
Suggest to use CreateDirectoryA
.
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
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.
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
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)
https://github.com/pantor/inja looks good.
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
Hello,
The library does not compile when C++20 is enabled. The std::result_of has been in removed in this version (https://en.cppreference.com/w/cpp/types/result_of).
Would it be possible to fix it?
Thank you.
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
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).
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?
spdlog has the ability to set the flush policy
It would be great to be able to have that control from spdlog_setup as well.
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
Add pass and fail individual pattern, logger, sink string content parsing.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.