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

syslog formatting (request) #729

Closed
hramoser opened this issue Jun 14, 2018 · 6 comments
Closed

syslog formatting (request) #729

hramoser opened this issue Jun 14, 2018 · 6 comments

Comments

@hramoser
Copy link

spdlog does not write formatted messages to syslog. In syslog_sink.h:
::syslog(syslog_prio_from_level(msg), "%s", msg.raw.str().c_str());

Is this behavior by design?
I would prefer to get a formatted message also for syslog:
::syslog(syslog_prio_from_level(msg), "%s", msg.formatted.str().c_str());

@gabime
Copy link
Owner

gabime commented Jun 14, 2018

Yes, it is by design, since syslog already formats the messages.

@gabime gabime closed this as completed Jun 19, 2018
@singlaive
Copy link

@gabime , I understand why you design like this, but will you consider providing the option to format syslog as well?
In my case I would like the log formating done by spdlog and leave syslog only show the raw message. Because I need logs rendered both to console and syslog, and I need them in exactly the same format.
Can I do the same formatting in syslog? Maybe, but first it is duplicated effort; secondly, I would like the log line display the current version of the software (form text file), to do that I might need to write a string generator for syslog. That's double waste of effort.
Does this make sense?

@gabime
Copy link
Owner

gabime commented Nov 7, 2018

A possible approach would be to inherit syslog sink (override the sink_it_ method) to do what you need (for this the private section of the syslog sink should be comverted to protected though).

@singlaive
Copy link

Thanks for advice. Indeed that is the approach I had chosen. But to be honest, unless a user only uses a single syslog sink, he may face the awkward situation about replicating the formatting for syslog.

@gabime
Copy link
Owner

gabime commented Nov 7, 2018

That happens anyway in spdlog. Each sink has it's own private formatter copy, and use it to format the message, so that's fine. Most of the time the formatting is so fast that this it doens't matter.

@gabime
Copy link
Owner

gabime commented Jun 18, 2019

Implemented with additional boolean to ctor (true to format).

bachittle pushed a commit to bachittle/spdlog that referenced this issue Dec 22, 2022
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