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

Adding on demand truncation for basic file sinks #3280

Merged

Conversation

matteodelseppia
Copy link
Contributor

@matteodelseppia matteodelseppia commented Dec 2, 2024

Sometimes log rotation can be overkill. There are use cases where it is sufficient to simply truncate without the need for managing rotated logs or archiving. To address this, I have introduced a feature that allows a basic file sink to truncate its log file on demand.

@@ -26,6 +26,11 @@ SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const {
return file_helper_.filename();
}

template <typename Mutex>
SPDLOG_INLINE void basic_file_sink<Mutex>::truncate() {
file_helper_.reopen(true);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be locked using the mutex in the base class. See other sinks for example code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gosh, sorry for that. Updated.

@gabime gabime merged commit 65e388e into gabime:v1.x Dec 2, 2024
16 checks passed
@gabime
Copy link
Owner

gabime commented Dec 2, 2024

Thanks @matteodelseppia

@matteodelseppia matteodelseppia deleted the basic_file_sink_truncate_on_demand branch December 3, 2024 06:24
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.

2 participants