Skip to content

[Feature-Request] Public logging facility #1462

@roboptica-mlugli

Description

@roboptica-mlugli

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

Logging::Logging() : logger("depthai", {std::make_shared<spdlog::sinks::stdout_color_sink_mt>()}) {

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

depthai-core.logger.patch

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions