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

How to share a logger between processes? #29

Closed
ruipacheco opened this issue Jan 7, 2015 · 6 comments
Closed

How to share a logger between processes? #29

ruipacheco opened this issue Jan 7, 2015 · 6 comments

Comments

@ruipacheco
Copy link
Contributor

My application needs to fork an unknown number of processes but I want them all to log to the same file at runtime. Is it possible and advisable to share an instance of shared_ptr between all processes?

@gabime
Copy link
Owner

gabime commented Jan 7, 2015

The library does not support this. It could work, but it was not intended to be used this way.

@ruipacheco
Copy link
Contributor Author

Do you think it's possible to add ZeroMQ as a sink? Or should I just write a message to a ZeroMQ socket and have a thread/process read from it and have that thread/process then write to spdlog?

@gabime
Copy link
Owner

gabime commented Jan 8, 2015

Both options seem reasonable. Simpler option would be send thru a named pipe to a reading process that would write to the file

@ruipacheco
Copy link
Contributor Author

I'm concerned about the second option because of timestamps - there will be a difference.

If spdlog were to write to 0MQ what would be sent? The string I just wrote or some sort of data structure with more than just the message?

@gabime
Copy link
Owner

gabime commented Jan 8, 2015

I would just send the final formatted string to a named pipe which in turn would be consumed by a simple process that writes to file using spdlog ro directly. 0MQ is overkill for this.

This process can use spdlog to write to the actual file without reformatting the (already formatted) messages (set_formatter("%v")). This way the original timestamp would be preserved

@ruipacheco
Copy link
Contributor Author

And then from 0MQ I'd have to write it to the file...

Ok, thanks, closing the issue.

bachittle pushed a commit to bachittle/spdlog that referenced this issue Dec 22, 2022
* Add timestamp

* Reword

* Reword

* Fix build for gcc48

* Fix cmake tests

* Update timestamp storage

* Reformat

* Split timestamp into a system and steady type
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

2 participants