Skip to content

Commit

Permalink
Switch logging to env_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon committed Nov 21, 2023
1 parent 7e9d788 commit 79ac6fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
16 changes: 13 additions & 3 deletions Cargo.lock

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

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ debug = true
[features]
dev = ["prost", "base64"]

#[dependencies]
#presage = { git = "https://github.com/whisperfish/presage", rev = "23c157b" }
#resage-store-sled = { git = "https://github.com/whisperfish/presage", rev = "23c157b" }
[dependencies]
presage = { git = "https://github.com/whisperfish/presage", rev = "23c157b" }
presage-store-sled = { git = "https://github.com/whisperfish/presage", rev = "23c157b" }
presage = { path = "../presage/presage" }
presage-store-sled = { path = "../presage/presage-store-sled" }

anyhow = "1.0.66"
async-trait = "0.1.58"
Expand Down Expand Up @@ -58,7 +61,7 @@ uuid = { version = "1.2", features = ["v4"] }
whoami = "1.2.3"
tracing = "0.1.37"
tracing-appender = "0.2.2"
tracing-subscriber = "0.3.16"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
futures-channel = "0.3.25"
qr2term = { git = "https://github.com/boxdot/qr2term-rs", rev = "ed8ae7f" }
clap = { version = "4.0.19", features = ["derive"] }
Expand Down
15 changes: 5 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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,8 +35,8 @@ const RECEIPT_BUDGET: Duration = Duration::from_millis(RECEIPT_TICK_PERIOD * 100
#[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,
#[clap(short, long = "verbose")]
verbose: bool,
/// Relinks the device (helpful when device was unlinked)
#[clap(long)]
relink: bool,
Expand All @@ -46,16 +46,11 @@ struct Args {
async fn main() -> anyhow::Result<()> {
let args = Args::parse();

let _guard = if args.verbosity > 0 {
let _guard = if args.verbose {
let file_appender = tracing_appender::rolling::never("./", "gurk.log");
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
tracing_subscriber::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 79ac6fd

Please sign in to comment.