From 81ceb65008892826f3a813e9029a4e678beff87a Mon Sep 17 00:00:00 2001 From: Michael Wigard Date: Tue, 5 Sep 2023 19:18:40 +0200 Subject: [PATCH 1/2] attributes: fix instrument with "log" feature (#2599) ## Motivation The instrument macro currently doesn't work with the "log" crate feature: #2585 ## Solution Change the generated code to create a span if either `tracing::if_log_enabled!` or `tracing::level_enabled!`. I'm not sure how to add a test for this or if this is the best solution. Fixes #2585 --- tracing-attributes/src/expand.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing-attributes/src/expand.rs b/tracing-attributes/src/expand.rs index bedff8e833..2a55bd0f7f 100644 --- a/tracing-attributes/src/expand.rs +++ b/tracing-attributes/src/expand.rs @@ -343,7 +343,7 @@ fn gen_block( // regression in case the level is enabled. let __tracing_attr_span; let __tracing_attr_guard; - if tracing::level_enabled!(#level) { + if tracing::level_enabled!(#level) || tracing::if_log_enabled!(#level, {true} else {false}) { __tracing_attr_span = #span; #follows_from __tracing_attr_guard = __tracing_attr_span.enter(); From 9a7257d7ffcd3ab4de313c524c0a5bf83deee9f0 Mon Sep 17 00:00:00 2001 From: C L Eckhardt <29362105+CLEckhardt@users.noreply.github.com> Date: Tue, 5 Sep 2023 12:20:06 -0500 Subject: [PATCH 2/2] appender: clarify file appender docs (#2689) ## Motivation There are a few errors in the file appender docs - this fixes them. It also wasn't clear/apparent to me that you can create a non-rolling file appender with the `rolling` module - this calls that out more clearly. ## Solution Updates to docs. --- tracing-appender/src/lib.rs | 26 ++++++++++++++++++++------ tracing-appender/src/rolling.rs | 10 +++++----- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tracing-appender/src/lib.rs b/tracing-appender/src/lib.rs index 97ad8d4d58..0555ba0435 100644 --- a/tracing-appender/src/lib.rs +++ b/tracing-appender/src/lib.rs @@ -26,20 +26,34 @@ //! - Using a combination of [`NonBlocking`] and [`RollingFileAppender`] to allow writes to a log file //! without blocking. //! -//! ## Rolling File Appender +//! ## File Appender +//! +//! The [`rolling` module][rolling] provides functions to create rolling and non-rolling file +//! appenders. +//! +//! Rolling file appender rotation options are [`Rotation::MINUTELY`](rolling::Rotation::MINUTELY), +//! [`Rotation::HOURLY`](rolling::Rotation::HOURLY), and +//! [`Rotation::DAILY`](rolling::Rotation::DAILY). +//! +//! To create a non-rolling file appender, use +//! [`tracing_appender::rolling::never(/*...*/)`](rolling::never) or +//! [`Rotation::NEVER`](rolling::Rotation::NEVER). +//! +//! The following example creates an hourly rotating file appender that writes to +//! `/some/directory/prefix.log.YYYY-MM-DD-HH`: //! //! ```rust //! # fn docs() { //! let file_appender = tracing_appender::rolling::hourly("/some/directory", "prefix.log"); //! # } //! ``` -//! This creates an hourly rotating file appender that writes to `/some/directory/prefix.log.YYYY-MM-DD-HH`. -//! [`Rotation::DAILY`](rolling::Rotation::DAILY) and [`Rotation::NEVER`](rolling::Rotation::NEVER) are the other available options. //! -//! The file appender implements [`std::io::Write`][write]. To be used with [`tracing_subscriber::FmtSubscriber`][fmt_subscriber], -//! it must be combined with a [`MakeWriter`][make_writer] implementation to be able to record tracing spans/event. +//! The file appender implements [`std::io::Write`][write]. To be used with +//! [`tracing_subscriber::FmtSubscriber`][fmt_subscriber], it must be combined with a +//! [`MakeWriter`][make_writer] implementation to be able to record tracing spans/event. //! -//! The [`rolling` module][rolling]'s documentation provides more detail on how to use this file appender. +//! See the [`rolling` module][rolling]'s documentation for more detail on how to use this file +//! appender. //! //! ## Non-Blocking Writer //! diff --git a/tracing-appender/src/rolling.rs b/tracing-appender/src/rolling.rs index 1585c3a087..d82646933a 100644 --- a/tracing-appender/src/rolling.rs +++ b/tracing-appender/src/rolling.rs @@ -264,7 +264,7 @@ impl fmt::Debug for RollingFileAppender { } } -/// Creates a minutely, rolling file appender. This will rotate the log file once per minute. +/// Creates a minutely-rotating file appender. This will rotate the log file once per minute. /// /// The appender returned by `rolling::minutely` can be used with `non_blocking` to create /// a non-blocking, minutely file appender. @@ -299,7 +299,7 @@ pub fn minutely( RollingFileAppender::new(Rotation::MINUTELY, directory, file_name_prefix) } -/// Creates an hourly, rolling file appender. +/// Creates an hourly-rotating file appender. /// /// The appender returned by `rolling::hourly` can be used with `non_blocking` to create /// a non-blocking, hourly file appender. @@ -334,7 +334,7 @@ pub fn hourly( RollingFileAppender::new(Rotation::HOURLY, directory, file_name_prefix) } -/// Creates a file appender that rotates daily. +/// Creates a daily-rotating file appender. /// /// The appender returned by `rolling::daily` can be used with `non_blocking` to create /// a non-blocking, daily file appender. @@ -370,13 +370,13 @@ pub fn daily( RollingFileAppender::new(Rotation::DAILY, directory, file_name_prefix) } -/// Creates a non-rolling, file appender +/// Creates a non-rolling file appender. /// /// The appender returned by `rolling::never` can be used with `non_blocking` to create /// a non-blocking, non-rotating appender. /// /// The location of the log file will be specified the `directory` passed in. -/// `file_name` specifies the prefix of the log file. No date or time is appended. +/// `file_name` specifies the complete name of the log file (no date or time is appended). /// /// # Examples ///