-
Notifications
You must be signed in to change notification settings - Fork 158
Description
Why
A Windows Service has no stout, so all logs are lost. Moreover, it would be nice to log to a custom sink such as files or Windows EventLog.
What
Provide some methods in a public header that allows the library user to redirect the logs to a custom spdlog sink.
How
The simplest way IMHO is to introduce a static variable std::shared_ptr<spdlog::sinks::dist_sink<std::mutex>> common_sink which can be referenced by user code. Finally, you provide that same instance to the constructor of
depthai-core/src/utility/Logging.cpp
Line 50 in 5b4daba
| Logging::Logging() : logger("depthai", {std::make_shared<spdlog::sinks::stdout_color_sink_mt>()}) { |
and
depthai-core/src/device/DeviceBase.cpp
Line 259 in 5b4daba
| DeviceLogger logger{"host", stdoutColorSink}; |
Thereby, clients are then free add or remove custom sinks, simply by calling
void spdlog::sinks::dist_sink<std::mutex>::set_sinks(std::vector<std::shared_ptr<spdlog::sinks::sink>> sinks).
Notes
I have attached a patch that I currently use for DepthAI v2.30 to register both loggers in the spdlog register. However, I currently statically link all dependencies.