diff --git a/CHANGELOG.md b/CHANGELOG.md index c9d10b6..346a18a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ 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). +## [unpublished] + +Remove the RwLock around the color palette. + ## [0.29.3] - 2024-10-12 Removed dependency to `glob` by implementing the necessary file searches explicitly, diff --git a/examples/write_writer.rs b/examples/write_writer.rs index 0e3a718..1e1acff 100644 --- a/examples/write_writer.rs +++ b/examples/write_writer.rs @@ -1,4 +1,3 @@ -#![allow(dead_code)] use flexi_logger::writers::LogWriter; use std::{ io::{Error, ErrorKind}, @@ -7,6 +6,7 @@ use std::{ fn main() {} +#[allow(dead_code)] struct MyWriter { file: Arc>, } diff --git a/src/deferred_now.rs b/src/deferred_now.rs index e27d48e..f742669 100644 --- a/src/deferred_now.rs +++ b/src/deferred_now.rs @@ -19,9 +19,9 @@ impl<'a> DeferredNow { Self(None) } - #[allow(dead_code)] + #[cfg(test)] #[must_use] - pub(crate) fn new_from_datetime(dt: DateTime) -> Self { + fn new_from_datetime(dt: DateTime) -> Self { Self(Some(dt)) } diff --git a/src/logger.rs b/src/logger.rs index 4acea5a..9da39b5 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,4 +1,6 @@ use crate::formats::AdaptiveFormat; +#[cfg(feature = "colors")] +use crate::set_palette; use crate::{ filter::LogLineFilter, flexi_logger::FlexiLogger, @@ -672,7 +674,7 @@ impl Logger { /// Several variants of [`FlexiLoggerError`] can occur. pub fn build(mut self) -> Result<(Box, LoggerHandle), FlexiLoggerError> { #[cfg(feature = "colors")] - crate::formats::set_palette(self.o_palette.as_deref())?; + set_palette(self.o_palette.as_deref())?; if self.use_utc { self.flwb = self.flwb.use_utc(); diff --git a/src/logger_handle.rs b/src/logger_handle.rs index 2eb94a6..9ea6a66 100644 --- a/src/logger_handle.rs +++ b/src/logger_handle.rs @@ -133,7 +133,6 @@ impl LoggerHandle { } /// Replaces the active `LogSpecification`. - #[allow(clippy::missing_panics_doc)] pub fn set_new_spec(&self, new_spec: LogSpecification) { self.writers_handle .set_new_spec(new_spec) @@ -151,7 +150,7 @@ impl LoggerHandle { Ok(()) } - /// Replaces the active `LogSpecification` and pushes the previous one to a Stack. + /// Replaces the active `LogSpecification` and pushes the previous one to a stack. #[allow(clippy::missing_panics_doc)] pub fn push_temp_spec(&mut self, new_spec: LogSpecification) { self.writers_handle diff --git a/src/primary_writer/std_writer.rs b/src/primary_writer/std_writer.rs index 4429f59..3189bd1 100644 --- a/src/primary_writer/std_writer.rs +++ b/src/primary_writer/std_writer.rs @@ -99,7 +99,7 @@ impl StdWriter { EffectiveWriteMode::BufferDontFlushWith(capacity) => { InnerStdWriter::Buffered(Mutex::new(BufWriter::with_capacity(capacity, stdstream))) } - EffectiveWriteMode::BufferAndFlushWith(_, _) => { + EffectiveWriteMode::BufferAndFlushWith(_) => { unreachable!("Sync InnerStdWriter with own flushing is not implemented") } #[cfg(feature = "async")] diff --git a/src/threads.rs b/src/threads.rs index 3a36af6..75f8007 100644 --- a/src/threads.rs +++ b/src/threads.rs @@ -21,9 +21,8 @@ use { std::{sync::Mutex, thread::JoinHandle}, }; -// no clue why we get a warning if this allow is omitted; if we omit the use, we get an error -#[allow(unused_imports)] #[cfg(feature = "async")] +#[cfg(test)] use std::io::Write; #[cfg(feature = "async")] diff --git a/src/trc.rs b/src/trc.rs index 7af7e8b..9f40ab7 100644 --- a/src/trc.rs +++ b/src/trc.rs @@ -138,9 +138,10 @@ impl LogSpecSubscriber for TraceLogSpecSubscriber { } } -#[allow(dead_code)] // not really appropriate, seems to be a bug in clippy /// Rereads the specfile if it was updated and forwards the update to `tracing`'s filter. -pub struct SpecFileNotifier(Option>); +pub struct SpecFileNotifier { + _watcher: Option>, +} /// Set up tracing to write into the specified `FileLogWriter`, /// and to use the (optionally) specified specfile. @@ -166,19 +167,21 @@ pub fn setup_tracing( .with_filter_reloading(); // Set up specfile watching - let spec_file_notifier = SpecFileNotifier(match o_specfile { - Some(specfile) => { - let reload_handle = Box::new(subscriber_builder.reload_handle()); - subscribe_to_specfile( - specfile, - Box::new(move |logspec| { - { reload_handle.reload(LogSpecAsFilter(logspec)) }.unwrap(/* OK */); - }), - initial_logspec, - )? - } - None => None, - }); + let spec_file_notifier = SpecFileNotifier { + _watcher: match o_specfile { + Some(specfile) => { + let reload_handle = Box::new(subscriber_builder.reload_handle()); + subscribe_to_specfile( + specfile, + Box::new(move |logspec| { + { reload_handle.reload(LogSpecAsFilter(logspec)) }.unwrap(/* OK */); + }), + initial_logspec, + )? + } + None => None, + }, + }; // Get ready to trace tracing::subscriber::set_global_default(subscriber_builder.finish())?; diff --git a/src/write_mode.rs b/src/write_mode.rs index 72c1a74..a908c69 100644 --- a/src/write_mode.rs +++ b/src/write_mode.rs @@ -114,26 +114,6 @@ pub enum WriteMode { flush_interval: Duration, }, } - -pub(crate) enum EffectiveWriteMode { - Direct, - #[allow(dead_code)] // introduced due to a bug in clippy, should be removed again - BufferAndFlushWith(usize, Duration), - #[cfg_attr(docsrs, doc(cfg(feature = "async")))] - #[cfg(feature = "async")] - AsyncWith { - /// Capacity of the pool for the message buffers. - pool_capa: usize, - /// Capacity of an individual message buffer. - message_capa: usize, - /// The interval for flushing the output. - /// - /// With `Duration::ZERO` flushing is suppressed. - flush_interval: Duration, - }, - BufferDontFlushWith(usize), -} - impl WriteMode { pub(crate) fn inner(&self) -> EffectiveWriteMode { match *self { @@ -144,12 +124,9 @@ impl WriteMode { Self::BufferDontFlushWith(duration) => { EffectiveWriteMode::BufferDontFlushWith(duration) } - Self::BufferAndFlush => EffectiveWriteMode::BufferAndFlushWith( - DEFAULT_BUFFER_CAPACITY, - DEFAULT_FLUSH_INTERVAL, - ), - Self::BufferAndFlushWith(bufsize, duration) => { - EffectiveWriteMode::BufferAndFlushWith(bufsize, duration) + Self::BufferAndFlush => EffectiveWriteMode::BufferAndFlushWith(DEFAULT_BUFFER_CAPACITY), + Self::BufferAndFlushWith(bufsize, _duration) => { + EffectiveWriteMode::BufferAndFlushWith(bufsize) } #[cfg(feature = "async")] Self::Async => EffectiveWriteMode::AsyncWith { @@ -198,7 +175,7 @@ impl WriteMode { pub(crate) fn buffersize(&self) -> Option { match self.inner() { EffectiveWriteMode::Direct => None, - EffectiveWriteMode::BufferAndFlushWith(bufsize, _) + EffectiveWriteMode::BufferAndFlushWith(bufsize) | EffectiveWriteMode::BufferDontFlushWith(bufsize) => Some(bufsize), #[cfg(feature = "async")] EffectiveWriteMode::AsyncWith { @@ -227,3 +204,21 @@ impl WriteMode { } } } + +pub(crate) enum EffectiveWriteMode { + Direct, + BufferAndFlushWith(usize), + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] + #[cfg(feature = "async")] + AsyncWith { + /// Capacity of the pool for the message buffers. + pool_capa: usize, + /// Capacity of an individual message buffer. + message_capa: usize, + /// The interval for flushing the output. + /// + /// With `Duration::ZERO` flushing is suppressed. + flush_interval: Duration, + }, + BufferDontFlushWith(usize), +} diff --git a/src/writers/file_log_writer.rs b/src/writers/file_log_writer.rs index c42d28c..9bbfcc5 100644 --- a/src/writers/file_log_writer.rs +++ b/src/writers/file_log_writer.rs @@ -38,7 +38,7 @@ impl FileLogWriter { ) -> FileLogWriter { let state_handle = match state.config().write_mode.inner() { EffectiveWriteMode::Direct - | EffectiveWriteMode::BufferAndFlushWith(_, _) + | EffectiveWriteMode::BufferAndFlushWith(_) | EffectiveWriteMode::BufferDontFlushWith(_) => { StateHandle::new_sync(state, format_function) } diff --git a/src/writers/file_log_writer/state.rs b/src/writers/file_log_writer/state.rs index f387956..94750d4 100644 --- a/src/writers/file_log_writer/state.rs +++ b/src/writers/file_log_writer/state.rs @@ -333,9 +333,8 @@ impl State { } else { let fmt = InfixFormat::custom(ts_fmt); let ts = latest_timestamp_file(&self.config, !self.config.append, &fmt); - let naming_state = NamingState::Timestamps(ts, None, fmt.clone()); let infix = infix_from_timestamp(&ts, self.config.use_utc, &fmt); - (naming_state, infix) + (NamingState::Timestamps(ts, None, fmt), infix) } } Naming::Numbers => ( @@ -591,7 +590,6 @@ fn validate_logs_in_file( assert!(buf.is_empty(), "Found more log lines than expected: {buf} "); } -#[allow(clippy::type_complexity)] fn open_log_file( config: &FileLogWriterConfig, o_infix: Option<&str>, diff --git a/src/writers/file_log_writer/state_handle.rs b/src/writers/file_log_writer/state_handle.rs index 66c65d6..6de8540 100644 --- a/src/writers/file_log_writer/state_handle.rs +++ b/src/writers/file_log_writer/state_handle.rs @@ -183,7 +183,7 @@ impl StateHandle { } } - #[allow(clippy::unnecessary_wraps)] + #[allow(clippy::unnecessary_wraps)] // necessary if not compiled with feature = "async" #[inline] pub(super) fn write(&self, now: &mut DeferredNow, record: &Record) -> std::io::Result<()> { match &self { diff --git a/src/writers/syslog/formats.rs b/src/writers/syslog/formats.rs index 9e81f4d..d9dde1d 100644 --- a/src/writers/syslog/formats.rs +++ b/src/writers/syslog/formats.rs @@ -4,7 +4,10 @@ use log::Record; /// Default way of writing the message to the syslog. /// /// Just uses the `Display` implementation of `record.args()`. -#[allow(clippy::missing_errors_doc)] +/// +/// # Errors +/// +/// `std:io::Error` from writing to the given output stram. pub fn syslog_default_format( w: &mut dyn std::io::Write, _now: &mut DeferredNow, @@ -15,7 +18,10 @@ pub fn syslog_default_format( /// Similar to `syslog_default_format`, but inserts the thread name in the beginning of the message, /// encapsulated in square brackets. -#[allow(clippy::missing_errors_doc)] +/// +/// # Errors +/// +/// `std:io::Error` from writing to the given output stram. pub fn syslog_format_with_thread( w: &mut dyn std::io::Write, _now: &mut DeferredNow, diff --git a/tests/test_error_channel_error.rs b/tests/test_error_channel_error.rs index 90dba45..8a8c06b 100644 --- a/tests/test_error_channel_error.rs +++ b/tests/test_error_channel_error.rs @@ -77,7 +77,6 @@ fn controller() { fn parent(panic: bool) { let progpath = std::env::args().next().unwrap(); // spawn child and terminate directly, thus destroying the child's stderr - #[allow(clippy::zombie_processes)] Command::new(progpath) .env(CTRL_INDEX, if panic { "child_panic" } else { "child" }) .stdout(Stdio::null()) diff --git a/tests/test_multi_threaded_numbers.rs b/tests/test_multi_threaded_numbers.rs index a077afa..3c5b43a 100644 --- a/tests/test_multi_threaded_numbers.rs +++ b/tests/test_multi_threaded_numbers.rs @@ -50,8 +50,6 @@ fn multi_threaded() { verify the log" ); - // clippy ignores the Drop implementation of the inner log handle :-( - #[allow(clippy::redundant_clone)] let logger2 = logger.clone(); let cond_sync = CondSync::new(0_usize);