diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f4f025..5018fa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.28.5] - 2024-06-21 + +Remove unnecessary dependency to `is-terminal`. + +Add impl `From` for `LogSpecification`. + +Kudos to [Oakchris1955](https://github.com/Oakchris1955). + ## [0.28.4] - 2024-06-14 Fix [issue #162](https://github.com/emabee/flexi_logger/issues/162) diff --git a/Cargo.toml b/Cargo.toml index 31649ab..42e5f40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flexi_logger" -version = "0.28.4" +version = "0.28.5" authors = ["emabee "] categories = ["development-tools::debugging"] description = """ diff --git a/examples/colors.rs b/examples/colors.rs index 794de2e..35daabe 100644 --- a/examples/colors.rs +++ b/examples/colors.rs @@ -4,8 +4,8 @@ fn main() { #[cfg(feature = "colors")] { - use std::io::IsTerminal; use nu_ansi_term::Color; + use std::io::IsTerminal; for i in 0..=255 { println!("{}: {}", i, Color::Fixed(i).paint(i.to_string())); diff --git a/scripts/qualify.rs b/scripts/qualify.rs index d2fafba..e3ea8e1 100755 --- a/scripts/qualify.rs +++ b/scripts/qualify.rs @@ -54,7 +54,6 @@ fn main() { std::fs::remove_file("Cargo.lock").ok(); run_command!("cargo build"); run_command!("cargo build --no-default-features"); - #[rustfmt::skip] run_command!("cargo build --all-features"); run_command!("cargo build --release"); run_command!("cargo build --release --all-features"); @@ -62,7 +61,6 @@ fn main() { // Clippy in important variants run_command!("cargo clippy -- -D warnings"); run_command!("cargo clippy --all-features -- -D warnings"); - #[rustfmt::skip] run_command!("cargo +nightly clippy --all-targets --all-features -- -D warnings"); // Run tests in important variants @@ -70,12 +68,10 @@ fn main() { run_command!("cargo test --release --all-features"); run_command!("cargo test --no-default-features"); run_command!("cargo test --release"); - #[rustfmt::skip] run_command!("cargo test --release --features specfile_without_notification"); // doc run_command!("cargo +nightly test --all-features --doc"); - #[rustfmt::skip] run_command!("cargo +nightly doc --all-features --no-deps --open"); // check version consistency diff --git a/src/code_examples.md b/src/code_examples.md index c0f8c2f..6bac39b 100644 --- a/src/code_examples.md +++ b/src/code_examples.md @@ -36,7 +36,7 @@ and call `start()` immediately: # Ok(())} ``` -- Combine both options: +- Combine both options, with env having precendence over the given parameter value: ```rust # use flexi_logger::{Logger,FlexiLoggerError}; @@ -45,11 +45,11 @@ and call `start()` immediately: # Ok(())} ``` -or, even shorter, use: + or, even shorter, use: -```rust -flexi_logger::init(); -``` + ```rust + flexi_logger::init(); + ``` After that, you just use the log-macros from the log crate. Those log lines that match the log specification are then written to the default output channel (stderr). diff --git a/src/log_specification.rs b/src/log_specification.rs index 8cc071d..d144ccc 100644 --- a/src/log_specification.rs +++ b/src/log_specification.rs @@ -449,12 +449,14 @@ impl std::fmt::Display for LogSpecification { Ok(()) } } + impl std::convert::TryFrom<&str> for LogSpecification { type Error = FlexiLoggerError; fn try_from(value: &str) -> Result { LogSpecification::parse(value) } } + impl std::convert::TryFrom<&String> for LogSpecification { type Error = FlexiLoggerError; fn try_from(value: &String) -> Result { diff --git a/src/logger.rs b/src/logger.rs index 795d71d..576c005 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -11,12 +11,12 @@ use crate::{ LoggerHandle, Naming, WriteMode, }; -use std::io::IsTerminal; use log::LevelFilter; #[cfg(feature = "specfile")] use std::sync::Mutex; use std::{ collections::HashMap, + io::IsTerminal, path::PathBuf, sync::{Arc, RwLock}, time::Duration, @@ -80,9 +80,24 @@ enum LogTarget { /// loglevel-specification. impl Logger { /// Creates a Logger that you provide with an explicit [`LogSpecification`]. + /// + /// ## Examples + /// + /// ```rust + /// use log::LevelFilter; + /// use flexi_logger::Logger; + /// let logger = Logger::with(LevelFilter::Info).start().unwrap(); + /// ``` + /// + /// ```rust + /// use flexi_logger::{Logger, LogSpecification}; + /// let logger = Logger::with( + /// LogSpecification::parse("info, critical_mod = trace").unwrap() + /// ).start().unwrap(); + /// ``` #[must_use] - pub fn with(logspec: LogSpecification) -> Self { - Self::from_spec_and_errs(logspec) + pub fn with(logspec: impl Into) -> Self { + Self::from_spec_and_errs(logspec.into()) } /// Creates a Logger that reads the [`LogSpecification`] from a `String` or `&str`. @@ -134,13 +149,11 @@ impl Logger { format_for_file: default_format, #[cfg(feature = "colors")] - format_for_stdout: AdaptiveFormat::Default.format_function( - std::io::stdout().is_terminal() - ), + format_for_stdout: AdaptiveFormat::Default + .format_function(std::io::stdout().is_terminal()), #[cfg(feature = "colors")] - format_for_stderr: AdaptiveFormat::Default.format_function( - std::io::stderr().is_terminal() - ), + format_for_stderr: AdaptiveFormat::Default + .format_function(std::io::stderr().is_terminal()), #[cfg(not(feature = "colors"))] format_for_stdout: default_format,