-
Notifications
You must be signed in to change notification settings - Fork 782
Create a symlink to latest log file #1979
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
base: v0.1.x
Are you sure you want to change the base?
Conversation
@clia in general, we prefer to merge new features to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, I agree that this is definitely a feature that's worth having!
I think we probably want to make the symlinking behavior configurable, rather than always doing it by default. I left some comments discussing this. Also, if you're able to, it would be nice to add some tests to ensure this works as intended?
@@ -24,6 +24,7 @@ rust-version = "1.53.0" | |||
crossbeam-channel = "0.5.0" | |||
time = { version = "0.3", default-features = false, features = ["formatting"] } | |||
parking_lot = { optional = true, version = "0.12.0" } | |||
symlink = "0.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this adds a new dependency, and some users may not want the symlink feature, I think it would be preferable to feature flag this?
|
||
// Create a symlink to latest log file. | ||
let latest_path = Path::new(&filename); | ||
let symlink_path = Path::new(&log_directory).join(&log_filename_prefix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if using the log filename prefix for the name of the symlink is the best solution. The prefix may contain a trailing separator character. For example, I might want my log files to have names like myapp-log-<DATE>
, so the prefix might be myapp-log-
. Therefore, I think we probably want to allow users to configure the name of the symlink separately from the log file's name. Also, some users may want to give the symlink a special name like <LOGFILE_NAME>.latest
or similar.
PR #1779 adds a builder interface for configuring new RollingFileAppender
instances, in order to support compression of log files. I think once that PR merges, we may want to add a builder method for configuring the symlink generation, instead?
// Create a symlink to latest log file. | ||
let latest_path = Path::new(&filename); | ||
let symlink_path = Path::new(&log_directory).join(&log_filename_prefix); | ||
let _ = remove_symlink_file(&symlink_path); | ||
if let Err(err) = symlink_file(&latest_path, &symlink_path) { | ||
eprintln!("Couldn't create symlink: {}", err); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take it or leave it: the code for re-creating the symlink in Inner::refresh_writer
is identical to this code...I wonder if we want to consider making a function for creating/updating the symlink, and call it in both places?
Any status on this? Would be a great feature to have. I'm willing to work on this |
Motivation
When monitoring logs of rotating files, it will be very helpful to create a symlink
to the latest log file when creating and rotating the log file.
Then you can
tail -F symlink_file
to keep watching the new created log file.Solution
Create a symlink file when creating and rotating the log file.
Use a
symlink
crate to achieve a system compatible implementation.It's necessary to remove the old symlink file before creating it, otherwise it may cause failure.