bevyengine / bevyengine/bevy

Bevy Log Output to Files

Open
#5,233 7 comments 10 reactions 0 assignees View on GitHub
A-Diagnostics C-Docs C-Usability
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## 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:

```rust
// Either use a RollingFileAppender that you can configure yourself, or just simply output to some path...
// Maybe someone can think of better options...
enum FileLogger {
Rolling(RollingFileAppender),
Path(PathBuf),
}

app.insert_resource(LogSettings {
...
file: vec![
"log1".into(),
tracing_appender::rolling::hourly("logs", "log_prefix").into(),
]
});
```
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 the `let subscriber...` line with:

```rust
let file_appender = tracing_appender::rolling::hourly("logs", "log"); // This should be user configurable
let (non_blocking, worker_guard) = tracing_appender::non_blocking(file_appender);
let file_fmt_layer = tracing_subscriber::fmt::Layer::default()
.with_ansi(false) // disable terminal color escape sequences
.with_writer(non_blocking);
app.insert_resource(worker_guard); // have to keep this from being dropped

let subscriber = subscriber.with(fmt_layer).with(file_fmt_layer);
```

So it'd be nice if this were built in so I don't have to duplicate the `LogPlugin` code.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.