Skip to content

Commit

Permalink
Merge pull request #454 from JakeStanger/fix/logging
Browse files Browse the repository at this point in the history
fix(logging): log file growing indefinitely
  • Loading branch information
JakeStanger authored Feb 14, 2024
2 parents 584300a + e26e213 commit 7f3663a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ See the [Configuration Guide](https://github.com/JakeStanger/ironbar/wiki/config

Ironbar can be launched using the `ironbar` binary.

Log verbosity can be changed using `IRONBAR_LOG` or `IRONBAR_FILE_LOG`. You can use any of `error`, `warn`, `info`, `debug` or `trace`.
The `IRONBAR_LOG` and `IRONBAR_FILE_LOG` environment variables can be set
to change console and file log verbosity respectively.
You can use any of `error`, `warn`, `info`, `debug` or `trace`.

These default to `IRONBAR_LOG=info` and `IRONBAR_FILE_LOG=error`.
These default to `IRONBAR_LOG=info` and `IRONBAR_FILE_LOG=warn`.
Note that you cannot increase the file log verbosity above console verbosity.

File output can be found at `~/.local/share/ironbar/error.log`.
Log files can be found at `~/.local/share/ironbar/.log`.

## Status

Expand Down
9 changes: 8 additions & 1 deletion src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{env, panic};
use strip_ansi_escapes::Writer;
use tracing::error;
use tracing_appender::non_blocking::{NonBlocking, WorkerGuard};
use tracing_appender::rolling::Rotation;
use tracing_error::ErrorLayer;
use tracing_subscriber::fmt::{Layer, MakeWriter};
use tracing_subscriber::prelude::*;
Expand Down Expand Up @@ -67,7 +68,13 @@ fn install_tracing() -> Result<WorkerGuard> {

let log_path = data_dir().unwrap_or(env::current_dir()?).join("ironbar");

let appender = tracing_appender::rolling::never(log_path, "error.log");
let appender = tracing_appender::rolling::Builder::new()
.rotation(Rotation::DAILY)
.filename_prefix("ironbar")
.filename_suffix("log")
.max_log_files(3)
.build(log_path)?;

let (file_writer, guard) = tracing_appender::non_blocking(appender);

tracing_subscriber::registry()
Expand Down

0 comments on commit 7f3663a

Please sign in to comment.