-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Bevy Log Output to Files #5233
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
Comments
Since Bevy delegates logging to the It seems that implementing file logging internally in Bevy is opening the door to more asks in the same vein (logging to networked file, logging to remote networked host, logging to I'm not disagreeing file logging is needed (I agree that's important to have), but rather how we get there. Instead of the proposed approach, can we rather expose what's necessary for you @samcarey or someone else to simplify writing a file output customized to your use case? What is |
Exposing what's necessary would work for me! In order to factor out my file-logging-specific code, I could imagine having a field on the for layer in settings.extra_layers.iter() {
subscriber = subscriber.with(layer);
} Would that interface be general enough to cover most other cases like you mentioned? |
I would like to be able to add arbitrary layers to Bevy's tracing subscriber. While logging to files is nice, I would also like to direct trace messages to the console, for example. |
An alternative might be to raise an event on trace. |
I'm also interested! |
Add a dependency on tracing-appender For reasons I don't know, tracing-appender didn't support custom suffix. This means it's impossible to log to a file with a .log extension. I submitted a fix that was merged to add support for it, but there has been no release of tracing-appender in almost a year Closes: bevyengine#5233
Add a dependency on tracing-appender For reasons I don't know, tracing-appender didn't support custom suffix. This means it's impossible to log to a file with a .log extension. I submitted a fix that was merged to add support for it, but there has been no release of tracing-appender in almost a year Closes: bevyengine#5233
Add a dependency on tracing-appender For reasons I don't know, tracing-appender didn't support custom suffix. This means it's impossible to log to a file with a .log extension. I submitted a fix that was merged to add support for it, but there has been no release of tracing-appender in almost a year Closes: bevyengine#5233
This isn't wholly complete just yet, but the ability to customize the subscriber (added in #10822) seems to allow for this. |
I think this issue should be closed since it has already been resolved in #13159. use std::sync::OnceLock;
use tracing_appender::{non_blocking::WorkerGuard, rolling}
use bevy::prelude::*;
use bevy::log::{
LogPlugin,
tracing_subscriber::Layer,
BoxedLayer,
};
static LOG_GUARD: OnceLock<WorkerGuard> = OnceLock::new();
fn custom_layer(_app: &mut App) -> Option<BoxedLayer> {
let file_appender = rolling::daily("logs", "app.log");
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
let _ = LOG_GUARD.set(guard);
Some(bevy::log::tracing_subscriber::fmt::layer()
.with_writer(non_blocking)
.with_file(true)
.with_line_number(true)
.boxed())
}
fn main() {
let mut app = App::new();
app.add_plugins(
DefaultPlugins
.set(LogPlugin {
custom_layer,
..default()
})
).run();
} |
What problem does this solve or what need does it fill?
Bevy log can output to console, but I don't know of a way to easily output this to the filesystem as well.
It seems to me that this would be a common use case, where an app could log what happens to a file for later inspection (especially if it crashes for some reason).
What solution would you like?
I'm imagining an interface something like this:
where log output would be duplicated in the console and all FileLogger configurations.
What alternative(s) have you considered?
I currently have a working workaround in an app where I disabled the
LogPlugin
, and substituted my own that's exactly the same except that I replaced thelet subscriber...
line with:So it'd be nice if this were built in so I don't have to duplicate the
LogPlugin
code.The text was updated successfully, but these errors were encountered: