Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 34 additions & 23 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ members = ["crates/*"]
[workspace.package]
repository = "https://github.com/rust-cli/env_logger"
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.71" # MSRV
edition = "2024"
rust-version = "1.85" # MSRV
include = [
"/build.rs",
"/src/**/*",
Expand Down Expand Up @@ -112,7 +112,7 @@ panic = "abort"
panic = "abort"
codegen-units = 1
lto = true
# debug = "line-tables-only" # requires Cargo 1.71
debug = "line-tables-only"

[package]
name = "env_logger"
Expand Down Expand Up @@ -155,7 +155,7 @@ unstable-kv = ["kv"]
[dependencies]
log = { version = "0.4.29", features = ["std"] }
env_filter = { version = "2.0.0", path = "crates/env_filter", default-features = false, features = ["std"] }
jiff = { version = "0.2.22", default-features = false, features = ["std"], optional = true }
jiff = { version = "1.0.1", default-features = false, features = ["std"], optional = true }
anstream = { version = "1.0.0", default-features = false, features = ["wincon"], optional = true }
anstyle = { version = "1.0.13", optional = true }

Expand Down
10 changes: 5 additions & 5 deletions crates/env_filter/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use core::{fmt, mem};

use log::{LevelFilter, Metadata, Record};

use crate::enabled;
use crate::parse_spec;
use crate::parser::ParseResult;
use crate::Directive;
use crate::FilterOp;
use crate::ParseError;
use crate::enabled;
use crate::parse_spec;
use crate::parser::ParseResult;

/// A builder for a log filter.
///
Expand Down Expand Up @@ -102,7 +102,7 @@ impl Builder {
/// [Enabling Logging]: ../index.html#enabling-logging
#[cfg(feature = "std")]
pub fn parse(&mut self, filters: &str) -> &mut Self {
#![allow(clippy::print_stderr)] // compatibility
#![allow(clippy::print_stderr, reason = "compatibility")]

let ParseResult {
directives,
Expand Down Expand Up @@ -264,7 +264,7 @@ mod tests {
use log::{Level, LevelFilter};
use snapbox::{assert_data_eq, str};

use super::{enabled, Builder, Directive, Filter};
use super::{Builder, Directive, Filter, enabled};

fn make_logger_filter(dirs: Vec<Directive>) -> Filter {
let mut logger = Builder::new().build();
Expand Down
2 changes: 1 addition & 1 deletion crates/env_filter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ mod filtered_log;
mod op;
mod parser;

use directive::enabled;
use directive::Directive;
use directive::enabled;
use op::FilterOp;
use parser::parse_spec;

Expand Down
7 changes: 3 additions & 4 deletions crates/env_filter/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ impl Display for ParseError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for ParseError {}
impl core::error::Error for ParseError {}

/// Parse a logging specification string (e.g: `crate1,crate2::mod3,crate3::x=error/foo`)
/// and return a vector with log directives.
Expand Down Expand Up @@ -119,9 +118,9 @@ pub(crate) fn parse_spec(spec: &str) -> ParseResult {
mod tests {
use crate::ParseError;
use log::LevelFilter;
use snapbox::{assert_data_eq, str, Data, IntoData};
use snapbox::{Data, IntoData, assert_data_eq, str};

use super::{parse_spec, ParseResult};
use super::{ParseResult, parse_spec};

impl IntoData for ParseError {
fn into_data(self) -> Data {
Expand Down
2 changes: 1 addition & 1 deletion examples/filters_from_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Specify logging filters in code instead of using an environment variable.

use env_logger::Builder;

use log::{debug, error, info, trace, warn, LevelFilter};
use log::{LevelFilter, debug, error, info, trace, warn};

fn main() {
Builder::new().filter_level(LevelFilter::max()).init();
Expand Down
2 changes: 1 addition & 1 deletion src/fmt/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn hidden_kv_format(_formatter: &mut Formatter, _fields: &dyn Source) -> io:
pub fn default_kv_format(formatter: &mut Formatter, fields: &dyn Source) -> io::Result<()> {
fields
.visit(&mut DefaultVisitSource(formatter))
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
.map_err(io::Error::other)
}

struct DefaultVisitSource<'a>(&'a mut Formatter);
Expand Down
2 changes: 1 addition & 1 deletion src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ use crate::writer::{Buffer, Writer};
/// Seconds give precision of full seconds, milliseconds give thousands of a
/// second (3 decimal digits), microseconds are millionth of a second (6 decimal
/// digits) and nanoseconds are billionth of a second (9 decimal digits).
#[allow(clippy::exhaustive_enums)] // compatibility
#[allow(clippy::exhaustive_enums, reason = "compatibility")]
#[derive(Copy, Clone, Debug)]
pub enum TimestampPrecision {
/// Full second precision (0 decimal digits)
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(clippy::print_stderr)]
#![warn(clippy::print_stdout)]
#![allow(clippy::test_attr_in_doctest)]
#![allow(
clippy::test_attr_in_doctest,
reason = "documenting the writing of tests"
)]

mod logger;
mod writer;
Expand Down
23 changes: 15 additions & 8 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,8 @@ mod tests {

#[test]
fn env_get_filter_reads_from_var_if_set() {
env::set_var("env_get_filter_reads_from_var_if_set", "from var");
// SAFETY: In rust-only tests, no C code to race with
unsafe { env::set_var("env_get_filter_reads_from_var_if_set", "from var") };

let env = Env::new().filter_or("env_get_filter_reads_from_var_if_set", "from default");

Expand All @@ -1008,7 +1009,8 @@ mod tests {

#[test]
fn env_get_filter_reads_from_default_if_var_not_set() {
env::remove_var("env_get_filter_reads_from_default_if_var_not_set");
// SAFETY: In rust-only tests, no C code to race with
unsafe { env::remove_var("env_get_filter_reads_from_default_if_var_not_set") };

let env = Env::new().filter_or(
"env_get_filter_reads_from_default_if_var_not_set",
Expand All @@ -1020,7 +1022,8 @@ mod tests {

#[test]
fn env_get_write_style_reads_from_var_if_set() {
env::set_var("env_get_write_style_reads_from_var_if_set", "from var");
// SAFETY: In rust-only tests, no C code to race with
unsafe { env::set_var("env_get_write_style_reads_from_var_if_set", "from var") };

let env =
Env::new().write_style_or("env_get_write_style_reads_from_var_if_set", "from default");
Expand All @@ -1030,7 +1033,8 @@ mod tests {

#[test]
fn env_get_write_style_reads_from_default_if_var_not_set() {
env::remove_var("env_get_write_style_reads_from_default_if_var_not_set");
// SAFETY: In rust-only tests, no C code to race with
unsafe { env::remove_var("env_get_write_style_reads_from_default_if_var_not_set") };

let env = Env::new().write_style_or(
"env_get_write_style_reads_from_default_if_var_not_set",
Expand All @@ -1042,10 +1046,13 @@ mod tests {

#[test]
fn builder_parse_env_overrides_existing_filters() {
env::set_var(
"builder_parse_default_env_overrides_existing_filters",
"debug",
);
// SAFETY: In rust-only tests, no C code to race with
unsafe {
env::set_var(
"builder_parse_default_env_overrides_existing_filters",
"debug",
);
};
let env = Env::new().filter("builder_parse_default_env_overrides_existing_filters");

let mut builder = Builder::new();
Expand Down
4 changes: 2 additions & 2 deletions src/writer/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl BufferWriter {
}

pub(crate) fn print(&self, buf: &Buffer) -> io::Result<()> {
#![allow(clippy::print_stdout)] // enabled for tests only
#![allow(clippy::print_stderr)] // enabled for tests only
#![allow(clippy::print_stdout, reason = "enabled for tests only")]
#![allow(clippy::print_stderr, reason = "enabled for tests only")]

use std::io::Write as _;

Expand Down
3 changes: 1 addition & 2 deletions src/writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) use buffer::Buffer;
pub use target::Target;

/// Whether or not to print styles to the target.
#[allow(clippy::exhaustive_enums)] // By definition don't need more
#[allow(clippy::exhaustive_enums, reason = "by definition don't need more")]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Default)]
pub enum WriteStyle {
/// Try to print styles, but don't force the issue.
Expand Down Expand Up @@ -109,7 +109,6 @@ impl Builder {
}

/// Whether or not to capture logs for `cargo test`.
#[allow(clippy::wrong_self_convention)]
pub(crate) fn is_test(&mut self, is_test: bool) -> &mut Self {
self.is_test = is_test;
self
Expand Down
2 changes: 1 addition & 1 deletion tests/init-twice-retains-filter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::unwrap_used)]
#![allow(clippy::unwrap_used, reason = "in test")]

use std::env;
use std::process;
Expand Down
2 changes: 1 addition & 1 deletion tests/log-in-log.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::unwrap_used)]
#![allow(clippy::unwrap_used, reason = "in test")]

#[macro_use]
extern crate log;
Expand Down
2 changes: 1 addition & 1 deletion tests/log_tls_dtors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::unwrap_used)]
#![allow(clippy::unwrap_used, reason = "in test")]

#[macro_use]
extern crate log;
Expand Down
2 changes: 1 addition & 1 deletion tests/regexp_filter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::unwrap_used)]
#![allow(clippy::unwrap_used, reason = "in test")]

#[macro_use]
extern crate log;
Expand Down
Loading