-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat(logging)!: Move logging setup to setup_logging
, disable bevy LogPlugin, add logging to file system
#446
Conversation
Updated this to remove This does a few things:
Logging to filestracing-appender crate is used, it's very light on deps and handles non-blocking writing to log files, and rotating log files based on More docs on fn main() {
let log_file =
match LogPath::find_app_data_dir(("org".into(), "fishfolk".into(), "jumpy".into())) {
Ok(log_path) => Some(LogFileConfig {
log_path,
rotation: LogFileRotation::Daily,
file_name_prefix: "Jumpy.log".to_string(),
max_log_files: Some(7),
}),
Err(err) => {
// Cannot use error! macro as logging not configured yet.
//
// Note that on wasm, this will not log to console - will fail silently.
eprintln!("Failed to configure file logging: {err}");
None
}
};
let _log_guard = bones_framework::logging::setup_logging(LogSettings {
log_file,
..default()
});
// ...
} Where the logs end up:
Updating BonesWith Bevy LogPlugin disabled, bones users will need to call |
setup_logging
, disable bevy LogPlugin, add logging to file system
setup_logging
, disable bevy LogPlugin, add logging to file systemsetup_logging
, disable bevy LogPlugin, add logging to file system
Hmm miri fails with Will need to see if this is just something unsupported by miri / how to resolve, thinking it's not a real issue. |
Nice job. If Will help to keep examples cleaner with just a straightforward 1-line path, and advanced cases can do the 10 line approach. |
Yeah, Miri can't run syscalls IIRC. We might be able to put a Also, is it necessary to have the |
I put a description on our We are using a async writer to files which does not flush on every write, is buffered. When the guard is dropped, it flushes the buffers ensuring that during a exit or unwind in panic, that the buffered traces are flushed and nothing is lost. The guard must be help / kept alive, if it is dropped will stop writing to file system. As we init logging in main, keeping guard on the stack in |
The |
Hmm... I do think the guard is confusing / will make people have to think about it more then they probably want to. That said there is complexity here for good reason, and hiding it can lead to mistakes. If someone was to conditionally use bones setup logging based on either a feature flag, or a
Obviously can add good docs helping communicate this pitfall, and complex uses could also not use macro. And we could add a I'm just a bit wary of hiding complexity and possibly trading visual appeal for bugs or unexpected issues for first time users. Even if ugly, at least most folks can probably feel confident copy and pasting a line with |
Added Added
|
Implement LogPlugin in bones based off Bevy's LogPlugin.
Shouldn't be much of a change in behavior, just 1st step in adding additional log functionality in bones, such as saving game log files to disk.
One difference is that it no longer includes the
tracing_error
crate layer, I will review how this is used in bevy and see if we want to add this dependency. Want to make sure not going to degrade in error reporting quality for errors originating in bevy. (Plus maybe there is something can learn from this / use in bones). Context: https://github.com/bevyengine/bevy/blob/3cf70ba4f9d62396240b186ff379d27a312d2aa2/crates/bevy_log/src/lib.rs#L205Logging is behind a feature flag, enabled by default. May be removed if user wants their own global subscriber configured.