Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a log zone prefix to default logger #3068

Closed
laped83 opened this issue Apr 15, 2024 · 2 comments
Closed

Set a log zone prefix to default logger #3068

laped83 opened this issue Apr 15, 2024 · 2 comments

Comments

@laped83
Copy link

laped83 commented Apr 15, 2024

We have a set of c++ modules with a custom logging framework that prints with a log zone prefix that can be shared between 1 or more c++ modules.

myapp: DEFAULT main:42 -- main message.
myapp: CONNECTIVITY test:44 -- another log message.
myapp: SYSTEM foo:45 -- another log message.

The logzones prefixes provides a quick way to filter the log output.

The module files sets a zone name definition in the top of the cpp file and prints to a default logger where the zone definition gets prefixed. The default zone will get used if one hasn't been set in the cpp file.

I have checked the spdlog documentation, but can't seem to find a way to do this, except by creating a logger by cloning the default and changing the logger name. This would require multiple lines for each module instead of just defining which log zone to use and print to default logger.

So do anyone have an idea on how to do this? 😃

@tt4g
Copy link
Contributor

tt4g commented Apr 15, 2024

spdlog does not provide the ability for loggers to reference additional information from the outside.
The only way to do this would be to treat the logger name as a zone.
See also #617

@gabime
Copy link
Owner

gabime commented Apr 15, 2024

There is a new “Mapped Diagnostic Context” feature you can try. see pr #2907

@gabime gabime closed this as completed Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants