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

Add option to use formatter inside systemd sink #2320

Closed
Delgan opened this issue Mar 24, 2022 · 2 comments · Fixed by #2324
Closed

Add option to use formatter inside systemd sink #2320

Delgan opened this issue Mar 24, 2022 · 2 comments · Fixed by #2324

Comments

@Delgan
Copy link
Contributor

Delgan commented Mar 24, 2022

Hi.

We are migrating from file_sink to systemd_sink and we would like to preserve the spdlog format. It's dropped (by design, I understand) during conversion because journald implements its own structured logging. That makes sense, but we're losing some important fields in the process.

Basically, I'm looking #1289 but using the alternative approach proposed.
That is, adding a boolean to constructor and re-implement #1107 for systemd_sink.

I understand that I can create my own sink to implement it this way, but I having this feature upstream is of course preferable (avoid duplication and guarantees further updates).

I can definitely open a Pull Request if you think this is an acceptable addition.

I have also just one question: sd_journal_send() being thread safe, does that mean I can safely use systemd_sink_st in a multi-threaded environment with multiple loggers? Is there any reason to prefer systemd_sink_mt?

@gabime
Copy link
Owner

gabime commented Mar 26, 2022

I can definitely open a Pull Request if you think this is an acceptable addition.

Sure, please open a pr.

does that mean I can safely use systemd_sink_st in a multi-threaded environment with multiple loggers? Is there any reason to prefer systemd_sink_mt?

I guess so, unless you will use the future version with the formatter in which case it must be mutex protected since the formatter is not thread safe.

@Delgan
Copy link
Contributor Author

Delgan commented Mar 27, 2022

Sure, please open a pr.

Great, thanks!
PR opened in #2324.

I guess so, unless you will use the future version with the formatter in which case it must be mutex protected since the formatter is not thread safe.

Oh, yeah, I didn't realize the formatters weren't thread-safe for optimization reasons. I was hoping to avoid different threads blocking each other, but it's certainly negligible in view of the overall performance of spdlog anyway. Thanks for the clarification, it's better to use the _mt sink.

gabime added a commit that referenced this issue Mar 29, 2022
Add option to enable formatting of systemd sink
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

Successfully merging a pull request may close this issue.

2 participants