Skip to content

Commit

Permalink
Respect RUST_LOG when specifying --verbose (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrdl-github authored Oct 21, 2024
1 parent c14e2ec commit 6bcc592
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
26 changes: 24 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ tokio-stream = "0.1.11"
toml = "0.8.0"
tracing = "0.1.37"
tracing-appender = "0.2.2"
tracing-subscriber = "0.3.16"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
unicode-width = "0.1.10"
uuid = { version = "1.2", features = ["v4"] }
whoami = "1.2.3"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ keybindings in `gurk.toml` using the format `keybindings.<mode>.<keycombination>
alt-j, ctrl-f, backspace, pagedown`. The default keybindings can be disabled by
setting `default_keybindings = false`. An empty command removes an existing
binding if it exists in the given mode. Configuration troubleshooted by running
`gurk --verbose` and examining the resulting `gurk.log`.
`RUST_LOG=gurk=trace,presage=trace,libsignal=trace gurk --verbose` and examining the resulting `gurk.log`.

### Supported commands
```
Expand Down
17 changes: 6 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use ratatui::{backend::CrosstermBackend, Terminal};
use tokio::select;
use tokio_stream::StreamExt;
use tracing::debug;
use tracing::{error, info, metadata::LevelFilter};
use tracing::{error, info};

const TARGET_FPS: u64 = 144;
const RECEIPT_TICK_PERIOD: u64 = 144;
Expand All @@ -35,9 +35,9 @@ const RECEIPT_BUDGET: Duration = Duration::from_millis(RECEIPT_TICK_PERIOD * 100
#[derive(Debug, Parser)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Enables logging to `gurk.log` in the current working directory
#[clap(short, long = "verbose", action = clap::ArgAction::Count)]
verbosity: u8,
/// Enables logging to `gurk.log` in the current working directory according to RUST_LOG
#[clap(short, long = "verbose")]
verbosity: bool,
/// Relinks the device (helpful when device was unlinked)
#[clap(long)]
relink: bool,
Expand All @@ -47,16 +47,11 @@ struct Args {
async fn main() -> anyhow::Result<()> {
let args = Args::parse();

let _guard = if args.verbosity > 0 {
let _guard = if args.verbosity {
let file_appender = tracing_appender::rolling::never("./", "gurk.log");
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
tracing_subscriber::fmt::fmt()
.with_max_level(match args.verbosity {
0 => LevelFilter::OFF,
1 => LevelFilter::INFO,
2 => LevelFilter::DEBUG,
_ => LevelFilter::TRACE,
})
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_writer(non_blocking)
.with_ansi(false)
.init();
Expand Down

0 comments on commit 6bcc592

Please sign in to comment.