-
Notifications
You must be signed in to change notification settings - Fork 752
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
Give more control over file names in tracing-appender #1477
Comments
I think the second approach you proposed where a rolling appender can optionally be constructed with a closure, seems like the most flexible approach, so I'd prefer to go with that. You're right that, to avoid breaking changes, we may want to either add new constructors for the file appenders that take a closure. We could add new Another approach could be to add a new trait for generating a file name, which is implemented by Is this something you're interested in helping to implement? |
I think making the shortcut functions ( If we decide to use a trait instead of a String/&str/Path inside the internal functions, then what should we pass to the trait functions when formatting ? If we pass the raw |
I have created a branch on my github account which contains a first draft implementation of this feature. There is currently two problems with this implementation: first the Another problem is that the newtype used to wrap the lambda must be public, this is required because |
I would also like to have the ability to have the current log always just be Also on a related note, existing rollover implementations (including macOS's handling of |
Would this feature be implemented soon? |
@HaeSe0ng -- I don't think anyone is actively working on this at the moment, but we'd be glad to accept PRs. |
## Motivation The `RollingFileAppender` currently only supports a filename suffix. A lot of editors have support for log files using the `.log` extension. It would be nice to be able to configure what gets added after the date. ## Solution - Add a `Builder::filename_suffix` method, taking a string. - If the string is non-empty, this gets appended to the filename after the date. - This isn't an `AsRef<Path>` because it's not supposed to be a `Path` - Update the date appending logic to handle cases when the suffix or prefix is empty - Split each part with a `.` so the final output would be `prefix.date.suffix` - Make sure to remove unnecessary `.` when a prefix or suffix is empty - Add tests related to those changes ## Notes It would probably be nicer to simply have a completely configurable file name format, but I went with the easiest approach that achieved what I needed. Closes #1477
## Motivation The `RollingFileAppender` currently only supports a filename suffix. A lot of editors have support for log files using the `.log` extension. It would be nice to be able to configure what gets added after the date. ## Solution - Add a `Builder::filename_suffix` method, taking a string. - If the string is non-empty, this gets appended to the filename after the date. - This isn't an `AsRef<Path>` because it's not supposed to be a `Path` - Update the date appending logic to handle cases when the suffix or prefix is empty - Split each part with a `.` so the final output would be `prefix.date.suffix` - Make sure to remove unnecessary `.` when a prefix or suffix is empty - Add tests related to those changes ## Notes It would probably be nicer to simply have a completely configurable file name format, but I went with the easiest approach that achieved what I needed. Closes #1477
## Motivation The `RollingFileAppender` currently only supports a filename suffix. A lot of editors have support for log files using the `.log` extension. It would be nice to be able to configure what gets added after the date. ## Solution - Add a `Builder::filename_suffix` method, taking a string. - If the string is non-empty, this gets appended to the filename after the date. - This isn't an `AsRef<Path>` because it's not supposed to be a `Path` - Update the date appending logic to handle cases when the suffix or prefix is empty - Split each part with a `.` so the final output would be `prefix.date.suffix` - Make sure to remove unnecessary `.` when a prefix or suffix is empty - Add tests related to those changes ## Notes It would probably be nicer to simply have a completely configurable file name format, but I went with the easiest approach that achieved what I needed. Closes #1477
Feature Request
Crates
This concerns the
tracing-appender
crate.Motivation
Add more control over the resulting file name(s) when using
tracing-appender
. In some case, it can be better to have all log files ends with the same extension (.log
for example) which is currently not possible achieve withtracig-appender
as the crate create file names with a date appended at the end and the user can only control the file prefix (example:logs_directory/log_file_name_prefix.yyyy-MM-dd-HH-mm
).Proposal
a) Add a way to set a suffix for file names, similar to how the prefix work.
or
b) Add a way to set a custom formatter for file names, which would take parameters such as the date to include and return a file name to use for example :
(this is only an example, an implementation of this feature could use a new "constructor" function to avoid creating a breaking change)
The text was updated successfully, but these errors were encountered: