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 sync to file_helper #2343

Merged
merged 1 commit into from
Jan 15, 2023
Merged

Add sync to file_helper #2343

merged 1 commit into from
Jan 15, 2023

Conversation

espkk
Copy link
Contributor

@espkk espkk commented Apr 16, 2022

Since file_helper already works well for managing file sinks and generally can be reused, it seems reasonable to me to implement fsync there which is required in some cases.
This adds sync() method to file_helper. It doesn't affect existing sinks and doesn't touch public interfaces.

@gabime
Copy link
Owner

gabime commented Apr 18, 2022

Thanks. However since it is not used by any of spdlog sinks, I prefer not to add unused code,

1 similar comment
@gabime
Copy link
Owner

gabime commented Apr 18, 2022

Thanks. However since it is not used by any of spdlog sinks, I prefer not to add unused code,

@gabime
Copy link
Owner

gabime commented Jan 15, 2023

@espkk Reopened due to popular demand for fsync. Could you please fix the code so it passes the tests?

@espkk
Copy link
Contributor Author

espkk commented Jan 15, 2023

Should be good now. I could add a sink for it but the use-cases can be different. I need it for termination, but someone might need it after each flush

@espkk espkk marked this pull request as ready for review January 15, 2023 13:30
@gabime gabime merged commit f29f369 into gabime:v1.x Jan 15, 2023
@gabime
Copy link
Owner

gabime commented Jan 15, 2023

Thanks @espkk . I am wondering myself whether to

  1. add fsync() to the logger api.
  2. or add fsync()just to file sinks.
  3. or perhaps provide auto sync by using logger->set_auto_fsync(true/false)

@espkk
Copy link
Contributor Author

espkk commented Jan 15, 2023

Thanks @espkk . I am wondering myself whether to

  1. add fsync() to the logger api.
  2. or add fsync()just to file sinks.
  3. or perhaps provide auto sync by using logger->set_auto_fsync(true/false)

IMO, fsync on file sink should be flexible enough, while I would still prefer implementing custom sink if the desired behavior is sync-after-write

@cpp977
Copy link

cpp977 commented Jan 16, 2023

For my use case (#2605), the third option would be the most convenient.
logger->set_auto_sync() would then lead to a call to fsync after each flush. One could then just use the existing spdlog::flush_every() to also have a regular fsync call.

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 this pull request may close these issues.

3 participants