syslog support
Few things about syslog support:
-
Wondering why syslog implementation is under SPDLOG_ENABLE_SYSLOG macro ?
-
I don't see any comments on this, but is this multi-thread safe ?
-
Is there a async version for this ? How do I NOT log in the calling threads context, but let a backend thread write to syslog file ?
-
Can a same thread create a logger instance for traces and another logger instance for syslogs ? I see calls like
spdlog::set_level(spdlog::level::debug); spdlog::set_pattern("%L [%Y-%m-%d %H:%M:%S.%e%z] %v");
and these are not tied to logger instance. So, it is not clear how to do this per instance.
I don't see any detailed examples on this. If someone can provide details I can try it out. May be this is just a documentation issue.
Wondering why syslog implementation is under SPDLOG_ENABLE_SYSLOG macro ?
Just to reduce resulting bin size and compilation time (most users don't use syslog)
I don't see any comments on this, but is this multi-thread safe ?
Yes, as long as syslog itself is thread safe (and it should be - https://stackoverflow.com/a/20668879)
Is there a async version for this ? How do I NOT log in the calling threads context, but let a backend thread write to syslog file ?
Set async mode before creating the logger:
spdlog::set_async_mode(8196);
auto syslog_logger = spd::syslog_logger("syslog", "my-ident", LOG_PID);
or create directlty
auto logger = spdlog::create_async("logger_name", syslog_shared_ptr, q_size,..);
and these are not tied to logger instance. So, it is not clear how to do this per instance.
You can use
logger->set_level(..);
logger->set_pattern(..);
I don't see any detailed examples on this
Plenty examples in the wiki docs..
Thanks for clarifying few things ... I am using spdlog::set_async_mode() currently but this looks like global setting. However, this is one of those global settings. How do I create a sync logger and another async logger ? Or is the recommended approach is to use flush() or flush_on() ?
Please refer to the docs about how to create loggers
@gabime -- In the 1.x release, the tweakme.h file no longer contains the dummy SPDLOG_ENABLE_SYSLOG value. The documentation still refers to it being necessary (though it hasn't been updated since September 2017). It's also not mentioned in the 1.x release log. Is this value still necessary?
Thanks.
No. No need for SPDLOG_ENABLE_SYSLOG anymore.Just include the syslog_sink.h file. Where is it documented ? The doc need to be fixed
Thanks for the clarification and response. It's in two places: https://github.com/gabime/spdlog/wiki/4.-Sinks https://github.com/gabime/spdlog/wiki/8.-Tweaking
Fixed. Thanks for pointing this out.