Skip to content

Commit

Permalink
Merge pull request #39 from epage/log
Browse files Browse the repository at this point in the history
docs: Clarify relationship with log / tracing
  • Loading branch information
epage committed Jun 13, 2022
2 parents 299177b + def3047 commit 305d3b6
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .clippy.toml
@@ -1 +1 @@
msrv = "1.54.0" # MSRV
msrv = "1.56.0" # MSRV
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -51,15 +51,15 @@ jobs:
- name: No-default features
run: cargo test --workspace --no-default-features
msrv:
name: "Check MSRV: 1.54.0"
name: "Check MSRV: 1.56.0"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.54.0 # MSRV
toolchain: 1.56.0 # MSRV
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.54.0 # MSRV
toolchain: 1.56.0 # MSRV
profile: minimal
override: true
components: clippy
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust-next.yml
Expand Up @@ -57,9 +57,9 @@ jobs:
strategy:
matrix:
rust:
- 1.54.0 # MSRV
- 1.56.0 # MSRV
- stable
continue-on-error: ${{ matrix.rust != '1.54.0' }} # MSRV
continue-on-error: ${{ matrix.rust != '1.56.0' }} # MSRV
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Expand Up @@ -6,7 +6,8 @@ authors = ["Pascal Hertleif <killercup@gmail.com>"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-clique/clap-verbosity-flag"
readme = "README.md"
edition = "2018"
edition = "2021"
rust-version = "1.56.0" # MSRV
include = [
"src/**/*",
"Cargo.toml",
Expand All @@ -33,3 +34,6 @@ clap = { version = "3.0", default-features = false, features = ["std", "derive"]

[dev-dependencies]
env_logger = "0.9.0"
tracing = "0.1"
tracing-subscriber = "0.2"
tracing-log = "0.1.3"
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
# clap-verbosity-flag
# clap-verbosity-flag for `log`

[![Documentation](https://img.shields.io/badge/docs-master-blue.svg)][Documentation]
![License](https://img.shields.io/crates/l/clap-verbosity-flag.svg)
Expand Down
6 changes: 6 additions & 0 deletions examples/example.rs
Expand Up @@ -14,4 +14,10 @@ fn main() {
env_logger::Builder::new()
.filter_level(cli.verbose.log_level_filter())
.init();

log::error!("Engines exploded");
log::warn!("Engines smoking");
log::info!("Engines exist");
log::debug!("Engine temperature is 200 degrees");
log::trace!("Engine subsection is 300 degrees");
}
34 changes: 34 additions & 0 deletions examples/example_tracing.rs
@@ -0,0 +1,34 @@
use clap::Parser;
use clap_verbosity_flag::Verbosity;

/// Foo
#[derive(Debug, Parser)]
struct Cli {
#[clap(flatten)]
verbose: Verbosity,
}

fn main() {
let cli = Cli::parse();

tracing_subscriber::fmt()
.with_max_level(convert_filter(cli.verbose.log_level_filter()))
.init();

log::error!("Engines exploded");
log::warn!("Engines smoking");
log::info!("Engines exist");
log::debug!("Engine temperature is 200 degrees");
log::trace!("Engine subsection is 300 degrees");
}

fn convert_filter(filter: log::LevelFilter) -> tracing_subscriber::filter::LevelFilter {
match filter {
log::LevelFilter::Off => tracing_subscriber::filter::LevelFilter::OFF,
log::LevelFilter::Error => tracing_subscriber::filter::LevelFilter::ERROR,
log::LevelFilter::Warn => tracing_subscriber::filter::LevelFilter::WARN,
log::LevelFilter::Info => tracing_subscriber::filter::LevelFilter::INFO,
log::LevelFilter::Debug => tracing_subscriber::filter::LevelFilter::DEBUG,
log::LevelFilter::Trace => tracing_subscriber::filter::LevelFilter::TRACE,
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
@@ -1,4 +1,4 @@
//! Easily add a `--verbose` flag to CLIs using Structopt
//! Control `log` level with a `--verbose` flag for your CLI
//!
//! # Examples
//!
Expand Down

0 comments on commit 305d3b6

Please sign in to comment.