From 52883c8cafcdab96a38f12f58f43d96a98c2fa63 Mon Sep 17 00:00:00 2001 From: emabee Date: Fri, 3 Feb 2023 13:45:13 +0100 Subject: [PATCH] [0.24.3] Fix some issues - fix #132 - fix #133 - Improve documentation of feature dependencies --- CHANGELOG.md | 16 +++++++++++++++- Cargo.toml | 6 +++--- README.md | 6 +++--- scripts/qualify.rs | 6 +++--- src/deferred_now.rs | 26 ++++++++++++++------------ src/flexi_error.rs | 5 +++++ src/log_specification.rs | 3 +++ src/logger.rs | 3 ++- src/logger_handle.rs | 1 + src/trc.rs | 1 + src/write_mode.rs | 2 ++ src/writers.rs | 2 ++ src/writers/file_log_writer/state.rs | 2 +- 13 files changed, 55 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eea1d4..31c13e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,24 @@ 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.24.2] - unpublished +## [0.25.0] - 2023-02-03 + +Fix issues #132 and #133. + +Update dependencies. + +Bump MSRV to 1.60, because toml needs it now. + +Improve documentation of feature dependencies. + +Minor stuff. + +## [0.24.2] - 2022-12-15 Move from unmaintained `ansi_term` to `nu-ansi-term`. +Fix new clippies. + ## [0.24.1] - 2022-11-01 Some improvements in respect to `use_utc`: diff --git a/Cargo.toml b/Cargo.toml index 1f1a76f..227743f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flexi_logger" -version = "0.24.2" +version = "0.25.0" authors = ["emabee "] categories = ["development-tools::debugging"] description = """ @@ -15,7 +15,7 @@ keywords = ["file", "logger"] license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/emabee/flexi_logger" -rust-version = "1.59.0" +rust-version = "1.60.0" [lib] doctest = false @@ -55,7 +55,7 @@ regex = {version = "1.1", optional = true} serde = {version = "1.0", optional = true} serde_derive = {version = "1.0", optional = true} thiserror = "1.0" -toml = {version = "0.5", optional = true } +toml = {version = "0.7", optional = true } tracing-subscriber = {version = "0.3", optional = true, features = ["env-filter"]} tracing = {version = "0.1.36", optional = true} diff --git a/README.md b/README.md index ee39cba..e02c1b2 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ and you use the ```log``` macros to write log lines from your code): ```toml [dependencies] -flexi_logger = "0.24" +flexi_logger = "0.25" log = "0.4" ``` @@ -68,7 +68,7 @@ Make use of the non-default features by specifying them in your `Cargo.toml`, e. ```toml [dependencies] -flexi_logger = { version = "0.24", features = ["async", "specfile", "compress"] } +flexi_logger = { version = "0.25", features = ["async", "specfile", "compress"] } log = "0.4" ``` @@ -76,7 +76,7 @@ or, to get the smallest footprint (and no colors), switch off even the default f ```toml [dependencies] -flexi_logger = { version = "0.24", default_features = false } +flexi_logger = { version = "0.25", default_features = false } log = "0.4" ``` diff --git a/scripts/qualify.rs b/scripts/qualify.rs index 9569b3c..cc2e66e 100644 --- a/scripts/qualify.rs +++ b/scripts/qualify.rs @@ -47,8 +47,8 @@ fn main() { // Build in important variants std::fs::remove_file("Cargo.lock").ok(); - run_command!("cargo", "+1.59.0", "build", "--no-default-features"); - run_command!("cargo", "+1.59.0", "build", "--all-features"); + run_command!("cargo", "+1.60.0", "build", "--no-default-features"); + run_command!("cargo", "+1.60.0", "build", "--all-features"); std::fs::remove_file("Cargo.lock").ok(); run_command!("cargo", "build"); @@ -65,7 +65,7 @@ fn main() { run_command!("cargo", "+nightly", "clippy", "--all-targets", "--all-features", "--", "-D", "warnings"); // Run tests in important variants - run_command!("cargo", "+1.59.0", "test", "--all-features"); + run_command!("cargo", "+1.60.0", "test", "--all-features"); run_command!("cargo", "test", "--release", "--all-features"); run_command!("cargo", "test", "--no-default-features"); run_command!("cargo", "test", "--release"); diff --git a/src/deferred_now.rs b/src/deferred_now.rs index 44effb3..eec3ba0 100644 --- a/src/deferred_now.rs +++ b/src/deferred_now.rs @@ -46,10 +46,11 @@ impl<'a> DeferredNow { } } - // The format described in RFC 3339; example: 1985-04-12T23:20:50.523Z - #[cfg(feature = "syslog_writer")] - pub(crate) fn format_rfc3339(&mut self) -> DelayedFormat> { - self.format("%Y-%m-%dT%H:%M:%S%.3fZ") + /// Produces a preformatted object suitable for printing. + /// + /// The format described in RFC 3339 is used. Example: 1985-04-12T23:20:50.523Z + pub fn format_rfc3339(&mut self) -> DelayedFormat> { + self.format("%Y-%m-%dT%H:%M:%S%.3f%Z") } // format_rfc3164: Mmm dd hh:mm:ss, where @@ -172,13 +173,14 @@ mod test { fn test_format_rfc3339() { // The format described in RFC 3339; example: 1985-04-12T23:20:50.52Z let s = super::DeferredNow::new().format_rfc3339().to_string(); - let bytes = s.into_bytes(); - assert_eq!(bytes[4], b'-'); - assert_eq!(bytes[7], b'-'); - assert_eq!(bytes[10], b'T'); - assert_eq!(bytes[13], b':'); - assert_eq!(bytes[16], b':'); - assert_eq!(bytes[19], b'.'); - assert_eq!(bytes[23], b'Z'); + let bytes = s.clone().into_bytes(); + assert_eq!(bytes[4], b'-', "s = {s}"); + assert_eq!(bytes[7], b'-', "s = {s}"); + assert_eq!(bytes[10], b'T', "s = {s}"); + assert_eq!(bytes[13], b':', "s = {s}"); + assert_eq!(bytes[16], b':', "s = {s}"); + assert_eq!(bytes[19], b'.', "s = {s}"); + assert_eq!(bytes[23], b'+', "s = {s}"); + assert_eq!(bytes[26], b':', "s = {s}"); } } diff --git a/src/flexi_error.rs b/src/flexi_error.rs index 6d09a18..a9b3655 100644 --- a/src/flexi_error.rs +++ b/src/flexi_error.rs @@ -37,21 +37,25 @@ pub enum FlexiLoggerError { /// Filesystem notifications for the specfile could not be set up. #[error("Filesystem notifications for the specfile or the log file could not be set up")] #[cfg(feature = "notify")] + #[cfg_attr(docsrs, doc(cfg(feature = "notify")))] Notify(#[from] notify::Error), /// Parsing the configured logspec toml-file failed. #[error("Parsing the configured logspec toml-file failed")] #[cfg(feature = "specfile_without_notification")] + #[cfg_attr(docsrs, doc(cfg(feature = "specfile")))] SpecfileToml(#[from] toml::de::Error), /// Specfile cannot be accessed or created. #[error("Specfile cannot be accessed or created")] #[cfg(feature = "specfile_without_notification")] + #[cfg_attr(docsrs, doc(cfg(feature = "specfile")))] SpecfileIo(std::io::Error), /// Specfile has an unsupported extension. #[error("Specfile has an unsupported extension")] #[cfg(feature = "specfile_without_notification")] + #[cfg_attr(docsrs, doc(cfg(feature = "specfile")))] SpecfileExtension(&'static str), /// Invalid level filter. @@ -85,6 +89,7 @@ pub enum FlexiLoggerError { /// #[cfg(feature = "trc")] + #[cfg_attr(docsrs, doc(cfg(feature = "trc")))] #[error("Tracing initialization failed")] TracingSetup(#[from] tracing::subscriber::SetGlobalDefaultError), } diff --git a/src/log_specification.rs b/src/log_specification.rs index 67acfe8..e799498 100644 --- a/src/log_specification.rs +++ b/src/log_specification.rs @@ -249,6 +249,7 @@ impl LogSpecification { /// /// [`FlexiLoggerError::Parse`] if the input is malformed. #[cfg(feature = "specfile_without_notification")] + #[cfg_attr(docsrs, doc(cfg(feature = "specfile")))] pub fn from_toml>(s: S) -> Result { #[derive(Clone, Debug, serde_derive::Deserialize)] struct LogSpecFileFormat { @@ -307,6 +308,7 @@ impl LogSpecification { /// /// [`FlexiLoggerError::SpecfileIo`] if writing fails. #[cfg(feature = "specfile_without_notification")] + #[cfg_attr(docsrs, doc(cfg(feature = "specfile")))] pub fn to_toml(&self, w: &mut dyn std::io::Write) -> Result<(), FlexiLoggerError> { self.to_toml_impl(w).map_err(FlexiLoggerError::SpecfileIo) } @@ -609,6 +611,7 @@ impl LogSpecBuilder { /// /// This method is only avaible if the dafault feature `textfilter` is not switched off. #[cfg(feature = "textfilter")] + #[cfg_attr(docsrs, doc(cfg(feature = "textfilter")))] #[must_use] pub fn build_with_textfilter(&self, tf: Option) -> LogSpecification { LogSpecification { diff --git a/src/logger.rs b/src/logger.rs index a2cc10d..25bbdd6 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -802,7 +802,7 @@ impl Logger { /// # Errors /// /// Several variants of [`FlexiLoggerError`] can occur. - #[cfg_attr(docsrs, doc(cfg(feature = "specfile_without_notification")))] + #[cfg_attr(docsrs, doc(cfg(feature = "specfile")))] #[cfg(feature = "specfile_without_notification")] pub fn start_with_specfile>( self, @@ -822,6 +822,7 @@ impl Logger { /// # Errors /// /// Several variants of [`FlexiLoggerError`] can occur. + #[cfg_attr(docsrs, doc(cfg(feature = "specfile")))] #[cfg(feature = "specfile_without_notification")] pub fn build_with_specfile>( self, diff --git a/src/logger_handle.rs b/src/logger_handle.rs index 0b735b8..343a3af 100644 --- a/src/logger_handle.rs +++ b/src/logger_handle.rs @@ -309,6 +309,7 @@ impl Drop for WritersHandle { /// Trait that allows to register for changes to the log specification. #[cfg(feature = "specfile_without_notification")] +#[cfg_attr(docsrs, doc(cfg(feature = "specfile")))] pub trait LogSpecSubscriber: 'static + Send { /// Apply a new `LogSpecification`. /// diff --git a/src/trc.rs b/src/trc.rs index f4f5506..1a9ee29 100644 --- a/src/trc.rs +++ b/src/trc.rs @@ -82,6 +82,7 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber}; /// /// Several variants of [`FlexiLoggerError`] can occur. #[cfg(feature = "specfile_without_notification")] +#[cfg_attr(docsrs, doc(cfg(feature = "specfile")))] pub fn subscribe_to_specfile>( specfile: P, reloader: Box, diff --git a/src/write_mode.rs b/src/write_mode.rs index 52f241a..f81edb4 100644 --- a/src/write_mode.rs +++ b/src/write_mode.rs @@ -9,11 +9,13 @@ pub const DEFAULT_FLUSH_INTERVAL: Duration = Duration::from_secs(1); /// Default size of the message pool; /// a higher value could further reduce allocations during log file rotation and cleanup. #[cfg(feature = "async")] +#[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub const DEFAULT_POOL_CAPA: usize = 50; /// Default capacity for the message buffers; /// a higher value reduces allocations when longer log lines are used. #[cfg(feature = "async")] +#[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub const DEFAULT_MESSAGE_CAPA: usize = 200; /// Describes whether the log output should be written synchronously or asynchronously, diff --git a/src/writers.rs b/src/writers.rs index 75cf40b..616f496 100644 --- a/src/writers.rs +++ b/src/writers.rs @@ -102,9 +102,11 @@ pub(crate) mod file_log_writer; mod log_writer; #[cfg(feature = "syslog_writer")] +#[cfg_attr(docsrs, doc(cfg(feature = "syslog_writer")))] mod syslog_writer; #[cfg(feature = "syslog_writer")] +#[cfg_attr(docsrs, doc(cfg(feature = "syslog_writer")))] pub use self::syslog_writer::{ LevelToSyslogSeverity, Syslog, SyslogFacility, SyslogSeverity, SyslogWriter, }; diff --git a/src/writers/file_log_writer/state.rs b/src/writers/file_log_writer/state.rs index 83232f7..4e2d1ea 100644 --- a/src/writers/file_log_writer/state.rs +++ b/src/writers/file_log_writer/state.rs @@ -593,7 +593,7 @@ pub(crate) fn remove_or_compress_too_old_logfiles_impl( for (index, file) in list_of_log_and_compressed_files(file_spec).enumerate() { if index >= log_limit + compress_limit { // delete (log or log.gz) - std::fs::remove_file(&file)?; + std::fs::remove_file(file)?; } else if index >= log_limit { #[cfg(feature = "compress")] {