From 10d78d677388aba55cdfaec2a01b6bc0157bf85a Mon Sep 17 00:00:00 2001 From: andylokandy Date: Fri, 2 Aug 2024 00:55:08 +0800 Subject: [PATCH 1/5] refactor: re-desgin api --- examples/fn_layout_filter.rs | 21 +-- examples/json_stdio.rs | 7 +- examples/no_color_stdio.rs | 7 +- examples/rolling_file.rs | 7 +- examples/simple_stdio.rs | 15 +- src/append/boxdyn.rs | 60 -------- src/append/fastrace.rs | 13 +- src/append/mod.rs | 103 ++----------- src/append/opentelemetry.rs | 16 +- src/append/{file => rolling_file}/README.md | 0 src/append/{file => rolling_file}/append.rs | 11 +- src/append/{file => rolling_file}/mod.rs | 0 .../{file => rolling_file}/non_blocking.rs | 4 +- src/append/{file => rolling_file}/rolling.rs | 0 src/append/{file => rolling_file}/worker.rs | 2 +- src/append/stdio.rs | 18 +-- src/dynlog.rs | 77 ---------- src/filter/{boxdyn.rs => custom.rs} | 36 ++--- src/filter/{log_level.rs => min_level.rs} | 30 ++-- src/filter/mod.rs | 28 ++-- src/layout/custom.rs | 2 +- src/layout/identical.rs | 10 +- src/layout/{simple_json.rs => json.rs} | 12 +- src/layout/{kv_display.rs => kv.rs} | 0 src/layout/mod.rs | 28 ++-- src/layout/{simple_text.rs => text.rs} | 20 +-- src/lib.rs | 9 +- src/logger.rs | 140 +++++++----------- 28 files changed, 192 insertions(+), 484 deletions(-) delete mode 100644 src/append/boxdyn.rs rename src/append/{file => rolling_file}/README.md (100%) rename src/append/{file => rolling_file}/append.rs (77%) rename src/append/{file => rolling_file}/mod.rs (100%) rename src/append/{file => rolling_file}/non_blocking.rs (98%) rename src/append/{file => rolling_file}/rolling.rs (100%) rename src/append/{file => rolling_file}/worker.rs (98%) delete mode 100644 src/dynlog.rs rename src/filter/{boxdyn.rs => custom.rs} (55%) rename src/filter/{log_level.rs => min_level.rs} (65%) rename src/layout/{simple_json.rs => json.rs} (91%) rename src/layout/{kv_display.rs => kv.rs} (100%) rename src/layout/{simple_text.rs => text.rs} (85%) diff --git a/examples/fn_layout_filter.rs b/examples/fn_layout_filter.rs index b4a1cad..1e600cf 100644 --- a/examples/fn_layout_filter.rs +++ b/examples/fn_layout_filter.rs @@ -13,27 +13,28 @@ // limitations under the License. use log::LevelFilter; -use logforth::append; -use logforth::filter; -use logforth::filter::FilterResult; -use logforth::layout; -use logforth::logger::Dispatch; -use logforth::logger::Logger; +use logforth::{ + append, + filter::{CustomFilter, FilterResult}, + layout::CustomLayout, + Dispatch, Logger, +}; fn main() { Logger::new() .dispatch( - Dispatch::builder(append::Stdout) - .filter(filter::BoxDyn::new(|metadata: &log::Metadata| { + Dispatch::new() + .filter(CustomFilter::new(|metadata: &log::Metadata| { if metadata.level() > LevelFilter::Info { FilterResult::Accept } else { FilterResult::Reject } })) - .layout(layout::CustomLayout::new(|record, f| { + .layout(CustomLayout::new(|record, f| { f(format_args!("[system alert] {}", record.args())) - })), + })) + .append(append::Stdout), ) .apply() .unwrap(); diff --git a/examples/json_stdio.rs b/examples/json_stdio.rs index a69b50f..60b3811 100644 --- a/examples/json_stdio.rs +++ b/examples/json_stdio.rs @@ -22,9 +22,10 @@ use logforth::logger::Logger; fn main() { Logger::new() .dispatch( - Dispatch::builder(append::Stdout) - .filter(filter::LogLevel::new(LevelFilter::Trace)) - .layout(layout::SimpleJson), + Dispatch::new() + .filter(LevelFilter::Trace) + .layout(layout::JsonLayout) + .append(append::Stdout), ) .apply() .unwrap(); diff --git a/examples/no_color_stdio.rs b/examples/no_color_stdio.rs index f09ec71..0adb3bb 100644 --- a/examples/no_color_stdio.rs +++ b/examples/no_color_stdio.rs @@ -22,9 +22,10 @@ use logforth::logger::Logger; fn main() { Logger::new() .dispatch( - Dispatch::builder(append::Stdout) - .filter(filter::LogLevel::new(LevelFilter::Trace)) - .layout(layout::SimpleText::default()), + Dispatch::new() + .filter(LevelFilter::Trace) + .layout(layout::Text::default()) + .append(append::Stdout), ) .apply() .unwrap(); diff --git a/examples/rolling_file.rs b/examples/rolling_file.rs index e433b05..8370c8a 100644 --- a/examples/rolling_file.rs +++ b/examples/rolling_file.rs @@ -34,9 +34,10 @@ fn main() { Logger::new() .dispatch( - Dispatch::builder(append::RollingFile::new(writer)) - .filter(filter::LogLevel::new(LevelFilter::Trace)) - .layout(layout::SimpleJson), + Dispatch::new() + .filter(LevelFilter::Trace) + .layout(layout::JsonLayout) + .append(append::RollingFile::new(writer)), ) .apply() .unwrap(); diff --git a/examples/simple_stdio.rs b/examples/simple_stdio.rs index f09ec71..cd612f9 100644 --- a/examples/simple_stdio.rs +++ b/examples/simple_stdio.rs @@ -12,19 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -use log::LevelFilter; -use logforth::append; -use logforth::filter; -use logforth::layout; -use logforth::logger::Dispatch; -use logforth::logger::Logger; +use log::Level; +use logforth::{append, filter::MinLevel, layout::TextLayout, Dispatch, Logger}; fn main() { Logger::new() .dispatch( - Dispatch::builder(append::Stdout) - .filter(filter::LogLevel::new(LevelFilter::Trace)) - .layout(layout::SimpleText::default()), + Dispatch::new() + .filter(MinLevel(Level::Trace)) + .layout(TextLayout::default()) + .append(append::Stdout), ) .apply() .unwrap(); diff --git a/src/append/boxdyn.rs b/src/append/boxdyn.rs deleted file mode 100644 index eef0eea..0000000 --- a/src/append/boxdyn.rs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2024 tison -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::fmt::Debug; - -use log::Record; - -use crate::append::Append; -use crate::append::AppendImpl; -use crate::filter::FilterImpl; -use crate::layout::Layout; - -pub struct BoxDyn(Box); - -impl BoxDyn { - pub fn new(append: impl Append + Send + Sync + 'static) -> Self { - Self(Box::new(append)) - } -} - -impl Debug for BoxDyn { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "BoxDynAppend {{ ... }}") - } -} - -impl Append for BoxDyn { - fn try_append(&self, record: &Record) -> anyhow::Result<()> { - (*self.0).try_append(record) - } - - fn flush(&self) { - (*self.0).flush() - } - - fn default_layout(&self) -> Layout { - (*self.0).default_layout() - } - - fn default_filters(&self) -> Option> { - (*self.0).default_filters() - } -} - -impl From for AppendImpl { - fn from(append: BoxDyn) -> Self { - AppendImpl::BoxDyn(append) - } -} diff --git a/src/append/fastrace.rs b/src/append/fastrace.rs index d50b5e6..2cefb83 100644 --- a/src/append/fastrace.rs +++ b/src/append/fastrace.rs @@ -17,14 +17,13 @@ use std::time::SystemTime; use log::Record; use crate::append::Append; -use crate::append::AppendImpl; use crate::layout::KvDisplay; #[derive(Default, Debug, Clone)] -pub struct Fastrace; +pub struct FastraceEvent; -impl Append for Fastrace { - fn try_append(&self, record: &Record) -> anyhow::Result<()> { +impl Append for FastraceEvent { + fn append(&self, record: &Record) -> anyhow::Result<()> { let message = format!( "{} {:>5} {}{}", humantime::format_rfc3339_micros(SystemTime::now()), @@ -35,10 +34,8 @@ impl Append for Fastrace { fastrace::Event::add_to_local_parent(message, || []); Ok(()) } -} -impl From for AppendImpl { - fn from(append: Fastrace) -> Self { - AppendImpl::Fastrace(append) + fn flush(&self) { + fastrace::flush(); } } diff --git a/src/append/mod.rs b/src/append/mod.rs index 92cbe51..19cc35c 100644 --- a/src/append/mod.rs +++ b/src/append/mod.rs @@ -12,32 +12,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub use boxdyn::*; +use std::fmt; + #[cfg(feature = "fastrace")] pub use fastrace::*; -#[cfg(feature = "file")] -pub use file::*; #[cfg(feature = "opentelemetry")] pub use opentelemetry::*; pub use stdio::*; -use crate::dynlog::DynLog; -use crate::filter::FilterImpl; -use crate::layout; +use crate::filter::Filter; +use crate::layout::IdenticalLayout; use crate::layout::Layout; -mod boxdyn; #[cfg(feature = "fastrace")] mod fastrace; -#[cfg(feature = "file")] -mod file; #[cfg(feature = "opentelemetry")] mod opentelemetry; +#[cfg(feature = "file")] +pub mod rolling_file; mod stdio; -pub trait Append { +pub trait Append: fmt::Debug + Send + Sync + 'static { /// Dispatches a log record to the append target. - fn try_append(&self, record: &log::Record) -> anyhow::Result<()>; + fn append(&self, record: &log::Record) -> anyhow::Result<()>; /// Flushes any buffered records. fn flush(&self) {} @@ -45,88 +42,12 @@ pub trait Append { /// Default layout to use when [Dispatch][crate::logger::Dispatch] does not configure a /// preferred layout. fn default_layout(&self) -> Layout { - Layout::Identical(layout::Identical) + Layout::Identical(IdenticalLayout) } /// Default filters associated to this append. [log::Log] is mixed with - /// [Filter][crate::filter::Filter] and [Append]. - fn default_filters(&self) -> Option> { - None - } -} - -#[derive(Debug)] -pub enum AppendImpl { - BoxDyn(BoxDyn), - DynLog(DynLog), - #[cfg(feature = "fastrace")] - Fastrace(Fastrace), - #[cfg(feature = "opentelemetry")] - OpenTelemetryLog(OpenTelemetryLog), - #[cfg(feature = "file")] - RollingFile(RollingFile), - Stdout(Stdout), - Stderr(Stderr), -} - -impl Append for AppendImpl { - fn try_append(&self, record: &log::Record) -> anyhow::Result<()> { - match self { - AppendImpl::BoxDyn(append) => append.try_append(record), - AppendImpl::DynLog(append) => append.try_append(record), - #[cfg(feature = "fastrace")] - AppendImpl::Fastrace(append) => append.try_append(record), - #[cfg(feature = "opentelemetry")] - AppendImpl::OpenTelemetryLog(append) => append.try_append(record), - #[cfg(feature = "file")] - AppendImpl::RollingFile(append) => append.try_append(record), - AppendImpl::Stdout(append) => append.try_append(record), - AppendImpl::Stderr(append) => append.try_append(record), - } - } - - fn flush(&self) { - match self { - AppendImpl::BoxDyn(append) => append.flush(), - AppendImpl::DynLog(append) => append.flush(), - #[cfg(feature = "fastrace")] - AppendImpl::Fastrace(append) => append.flush(), - #[cfg(feature = "opentelemetry")] - AppendImpl::OpenTelemetryLog(append) => append.flush(), - #[cfg(feature = "file")] - AppendImpl::RollingFile(append) => append.flush(), - AppendImpl::Stdout(append) => append.flush(), - AppendImpl::Stderr(append) => append.flush(), - } - } - - fn default_layout(&self) -> Layout { - match self { - AppendImpl::BoxDyn(append) => append.default_layout(), - AppendImpl::DynLog(append) => append.default_layout(), - #[cfg(feature = "fastrace")] - AppendImpl::Fastrace(append) => append.default_layout(), - #[cfg(feature = "opentelemetry")] - AppendImpl::OpenTelemetryLog(append) => append.default_layout(), - #[cfg(feature = "file")] - AppendImpl::RollingFile(append) => append.default_layout(), - AppendImpl::Stdout(append) => append.default_layout(), - AppendImpl::Stderr(append) => append.default_layout(), - } - } - - fn default_filters(&self) -> Option> { - match self { - AppendImpl::BoxDyn(append) => append.default_filters(), - AppendImpl::DynLog(append) => append.default_filters(), - #[cfg(feature = "fastrace")] - AppendImpl::Fastrace(append) => append.default_filters(), - #[cfg(feature = "opentelemetry")] - AppendImpl::OpenTelemetryLog(append) => append.default_filters(), - #[cfg(feature = "file")] - AppendImpl::RollingFile(append) => append.default_filters(), - AppendImpl::Stdout(append) => append.default_filters(), - AppendImpl::Stderr(append) => append.default_filters(), - } + /// [Filter] and [Append]. + fn default_filters(&self) -> Vec { + vec![] } } diff --git a/src/append/opentelemetry.rs b/src/append/opentelemetry.rs index 7bca949..b8e54b4 100644 --- a/src/append/opentelemetry.rs +++ b/src/append/opentelemetry.rs @@ -23,17 +23,17 @@ use opentelemetry::InstrumentationLibrary; use opentelemetry_otlp::WithExportConfig; use opentelemetry_sdk::logs::LoggerProvider; -use crate::append::{Append, AppendImpl}; +use crate::append::Append; #[derive(Debug)] -pub struct OpenTelemetryLog { +pub struct OpentelemetryLog { name: String, category: String, library: Arc, provider: LoggerProvider, } -impl OpenTelemetryLog { +impl OpentelemetryLog { pub fn new( name: impl Into, category: impl Into, @@ -68,8 +68,8 @@ impl OpenTelemetryLog { } } -impl Append for OpenTelemetryLog { - fn try_append(&self, log_record: &Record) -> anyhow::Result<()> { +impl Append for OpentelemetryLog { + fn append(&self, log_record: &Record) -> anyhow::Result<()> { let provider = self.provider.clone(); let logger = provider.library_logger(self.library.clone()); @@ -107,9 +107,3 @@ fn log_level_to_otel_severity(level: log::Level) -> Severity { log::Level::Trace => Severity::Trace, } } - -impl From for AppendImpl { - fn from(append: OpenTelemetryLog) -> Self { - AppendImpl::OpenTelemetryLog(append) - } -} diff --git a/src/append/file/README.md b/src/append/rolling_file/README.md similarity index 100% rename from src/append/file/README.md rename to src/append/rolling_file/README.md diff --git a/src/append/file/append.rs b/src/append/rolling_file/append.rs similarity index 77% rename from src/append/file/append.rs rename to src/append/rolling_file/append.rs index 6a78b4d..055a6aa 100644 --- a/src/append/file/append.rs +++ b/src/append/rolling_file/append.rs @@ -14,9 +14,8 @@ use log::Record; -use crate::append::file::non_blocking::NonBlocking; +use crate::append::rolling_file::non_blocking::NonBlocking; use crate::append::Append; -use crate::append::AppendImpl; #[derive(Debug)] pub struct RollingFile { @@ -30,15 +29,9 @@ impl RollingFile { } impl Append for RollingFile { - fn try_append(&self, record: &Record) -> anyhow::Result<()> { + fn append(&self, record: &Record) -> anyhow::Result<()> { let bytes = format!("{}\n", record.args()).into_bytes(); self.writer.send(bytes)?; Ok(()) } } - -impl From for AppendImpl { - fn from(append: RollingFile) -> Self { - AppendImpl::RollingFile(append) - } -} diff --git a/src/append/file/mod.rs b/src/append/rolling_file/mod.rs similarity index 100% rename from src/append/file/mod.rs rename to src/append/rolling_file/mod.rs diff --git a/src/append/file/non_blocking.rs b/src/append/rolling_file/non_blocking.rs similarity index 98% rename from src/append/file/non_blocking.rs rename to src/append/rolling_file/non_blocking.rs index b1e9da7..b826e9d 100644 --- a/src/append/file/non_blocking.rs +++ b/src/append/rolling_file/non_blocking.rs @@ -22,8 +22,8 @@ use crossbeam_channel::unbounded; use crossbeam_channel::SendTimeoutError; use crossbeam_channel::Sender; -use crate::append::file::worker::Worker; -use crate::append::file::Message; +use crate::append::rolling_file::worker::Worker; +use crate::append::rolling_file::Message; #[derive(Debug)] pub struct WorkerGuard { diff --git a/src/append/file/rolling.rs b/src/append/rolling_file/rolling.rs similarity index 100% rename from src/append/file/rolling.rs rename to src/append/rolling_file/rolling.rs diff --git a/src/append/file/worker.rs b/src/append/rolling_file/worker.rs similarity index 98% rename from src/append/file/worker.rs rename to src/append/rolling_file/worker.rs index 3d3c336..7845a18 100644 --- a/src/append/file/worker.rs +++ b/src/append/rolling_file/worker.rs @@ -19,7 +19,7 @@ use crossbeam_channel::Receiver; use crossbeam_channel::RecvError; use crossbeam_channel::TryRecvError; -use crate::append::file::Message; +use crate::append::rolling_file::Message; pub(super) struct Worker { writer: T, diff --git a/src/append/stdio.rs b/src/append/stdio.rs index c3c1c29..59d4510 100644 --- a/src/append/stdio.rs +++ b/src/append/stdio.rs @@ -15,13 +15,12 @@ use std::io::Write; use crate::append::Append; -use crate::append::AppendImpl; #[derive(Default, Debug)] pub struct Stdout; impl Append for Stdout { - fn try_append(&self, record: &log::Record) -> anyhow::Result<()> { + fn append(&self, record: &log::Record) -> anyhow::Result<()> { let bytes = format!("{}\n", record.args()).into_bytes(); std::io::stdout().write_all(&bytes)?; Ok(()) @@ -32,16 +31,11 @@ impl Append for Stdout { } } -impl From for AppendImpl { - fn from(append: Stdout) -> Self { - AppendImpl::Stdout(append) - } -} - #[derive(Default, Debug)] pub struct Stderr; + impl Append for Stderr { - fn try_append(&self, record: &log::Record) -> anyhow::Result<()> { + fn append(&self, record: &log::Record) -> anyhow::Result<()> { let bytes = format!("{}\n", record.args()).into_bytes(); std::io::stderr().write_all(&bytes)?; Ok(()) @@ -51,9 +45,3 @@ impl Append for Stderr { let _ = std::io::stderr().flush(); } } - -impl From for AppendImpl { - fn from(append: Stderr) -> Self { - AppendImpl::Stderr(append) - } -} diff --git a/src/dynlog.rs b/src/dynlog.rs deleted file mode 100644 index 62d222c..0000000 --- a/src/dynlog.rs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2024 tison -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use log::Record; -use log::{Log, Metadata}; -use std::fmt::Debug; -use std::sync::Arc; - -use crate::append::Append; -use crate::append::AppendImpl; -use crate::filter::{Filter, FilterImpl, FilterResult}; - -pub struct DynLog(Arc); - -impl Debug for DynLog { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "DynLog {{ ... }}") - } -} - -impl DynLog { - pub fn new(log: impl Log + 'static) -> Self { - Self(Arc::new(log)) - } - - pub fn new_arc(log: Arc) -> Self { - Self(log) - } -} - -impl Append for DynLog { - fn try_append(&self, record: &Record) -> anyhow::Result<()> { - (*self.0).log(record); - Ok(()) - } - - fn flush(&self) { - (*self.0).flush() - } - - fn default_filters(&self) -> Option> { - Some(vec![Self::new_arc(self.0.clone()).into()]) - } -} - -impl Filter for DynLog { - fn filter_metadata(&self, metadata: &Metadata) -> FilterResult { - if self.0.enabled(metadata) { - FilterResult::Neutral - } else { - FilterResult::Reject - } - } -} - -impl From for AppendImpl { - fn from(append: DynLog) -> Self { - AppendImpl::DynLog(append) - } -} - -impl From for FilterImpl { - fn from(filter: DynLog) -> Self { - FilterImpl::DynLog(filter) - } -} diff --git a/src/filter/boxdyn.rs b/src/filter/custom.rs similarity index 55% rename from src/filter/boxdyn.rs rename to src/filter/custom.rs index 7bbc8a8..0553e7f 100644 --- a/src/filter/boxdyn.rs +++ b/src/filter/custom.rs @@ -17,37 +17,33 @@ use std::fmt::Debug; use log::Metadata; use crate::filter::Filter; -use crate::filter::FilterImpl; use crate::filter::FilterResult; -pub struct BoxDyn(Box); - -impl Debug for BoxDyn { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "BoxDynFilter {{ ... }}") - } +pub struct CustomFilter { + #[allow(clippy::type_complexity)] + f: Box FilterResult + Send + Sync + 'static>, } -impl BoxDyn { - pub fn new(filter: impl Filter + Send + Sync + 'static) -> Self { - Self(Box::new(filter)) +impl Debug for CustomFilter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "CustomFilter {{ ... }}") } } -impl Filter for BoxDyn { - fn filter_metadata(&self, metadata: &Metadata) -> FilterResult { - (*self.0).filter_metadata(metadata) +impl CustomFilter { + pub fn new(filter: impl Fn(&log::Metadata) -> FilterResult + Send + Sync + 'static) -> Self { + CustomFilter { + f: Box::new(filter), + } } -} -impl From for FilterImpl { - fn from(filter: BoxDyn) -> Self { - FilterImpl::BoxDyn(filter) + pub(crate) fn filter(&self, metadata: &Metadata) -> FilterResult { + (self.f)(metadata) } } -impl FilterResult> Filter for T { - fn filter_metadata(&self, metadata: &Metadata) -> FilterResult { - self(metadata) +impl From for Filter { + fn from(filter: CustomFilter) -> Self { + Filter::Custom(filter) } } diff --git a/src/filter/log_level.rs b/src/filter/min_level.rs similarity index 65% rename from src/filter/log_level.rs rename to src/filter/min_level.rs index f6b6d89..f3c8ee4 100644 --- a/src/filter/log_level.rs +++ b/src/filter/min_level.rs @@ -12,37 +12,33 @@ // See the License for the specific language governing permissions and // limitations under the License. -use log::LevelFilter; +use log::Level; use log::Metadata; use crate::filter::Filter; -use crate::filter::FilterImpl; use crate::filter::FilterResult; #[derive(Debug, Clone)] -pub struct LogLevel { - max_level: LevelFilter, -} - -impl LogLevel { - pub fn new(level: LevelFilter) -> Self { - Self { max_level: level } - } -} +pub struct MinLevel(pub Level); -impl Filter for LogLevel { - fn filter_metadata(&self, metadata: &Metadata) -> FilterResult { +impl MinLevel { + pub(crate) fn filter(&self, metadata: &Metadata) -> FilterResult { let level = metadata.level(); - if level <= self.max_level { + if level <= self.0 { FilterResult::Neutral } else { FilterResult::Reject } } } +impl From for Filter { + fn from(filter: MinLevel) -> Self { + Filter::MinLevel(filter) + } +} -impl From for FilterImpl { - fn from(filter: LogLevel) -> Self { - FilterImpl::LogLevel(filter) +impl From for Filter { + fn from(filter: Level) -> Self { + Filter::MinLevel(MinLevel(filter)) } } diff --git a/src/filter/mod.rs b/src/filter/mod.rs index 52582d6..0f44e80 100644 --- a/src/filter/mod.rs +++ b/src/filter/mod.rs @@ -12,12 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::dynlog::DynLog; -pub use boxdyn::BoxDyn; -pub use log_level::LogLevel; +pub use self::{custom::CustomFilter, min_level::MinLevel}; -mod boxdyn; -mod log_level; +mod custom; +mod min_level; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum FilterResult { @@ -29,23 +27,17 @@ pub enum FilterResult { Neutral, } -pub trait Filter { - fn filter_metadata(&self, metadata: &log::Metadata) -> FilterResult; -} - #[derive(Debug)] -pub enum FilterImpl { - BoxDyn(BoxDyn), - DynLog(DynLog), - LogLevel(LogLevel), +pub enum Filter { + MinLevel(MinLevel), + Custom(CustomFilter), } -impl Filter for FilterImpl { - fn filter_metadata(&self, metadata: &log::Metadata) -> FilterResult { +impl Filter { + pub(crate) fn filter(&self, metadata: &log::Metadata) -> FilterResult { match self { - FilterImpl::BoxDyn(filter) => filter.filter_metadata(metadata), - FilterImpl::DynLog(filter) => filter.filter_metadata(metadata), - FilterImpl::LogLevel(filter) => filter.filter_metadata(metadata), + Filter::MinLevel(filter) => filter.filter(metadata), + Filter::Custom(filter) => filter.filter(metadata), } } } diff --git a/src/layout/custom.rs b/src/layout/custom.rs index 36eb57f..a14614c 100644 --- a/src/layout/custom.rs +++ b/src/layout/custom.rs @@ -44,7 +44,7 @@ impl CustomLayout { } } - pub fn format(&self, record: &log::Record, f: &F) -> anyhow::Result<()> + pub(crate) fn format(&self, record: &log::Record, f: &F) -> anyhow::Result<()> where F: Fn(Arguments) -> anyhow::Result<()>, { diff --git a/src/layout/identical.rs b/src/layout/identical.rs index 5ced2d7..7124a30 100644 --- a/src/layout/identical.rs +++ b/src/layout/identical.rs @@ -16,10 +16,10 @@ use crate::layout::Layout; use std::fmt::Arguments; #[derive(Debug, Default, Clone, Copy)] -pub struct Identical; +pub struct IdenticalLayout; -impl Identical { - pub fn format(&self, record: &log::Record, f: &F) -> anyhow::Result<()> +impl IdenticalLayout { + pub(crate) fn format(&self, record: &log::Record, f: &F) -> anyhow::Result<()> where F: Fn(Arguments) -> anyhow::Result<()>, { @@ -27,8 +27,8 @@ impl Identical { } } -impl From for Layout { - fn from(layout: Identical) -> Self { +impl From for Layout { + fn from(layout: IdenticalLayout) -> Self { Layout::Identical(layout) } } diff --git a/src/layout/simple_json.rs b/src/layout/json.rs similarity index 91% rename from src/layout/simple_json.rs rename to src/layout/json.rs index 5ee502c..671018e 100644 --- a/src/layout/simple_json.rs +++ b/src/layout/json.rs @@ -25,7 +25,7 @@ use serde_json::Value; use crate::layout::Layout; #[derive(Default, Debug, Clone)] -pub struct SimpleJson; +pub struct JsonLayout; struct KvCollector<'a> { kvs: &'a mut Map, @@ -55,8 +55,8 @@ struct RecordLine<'a> { kvs: Map, } -impl SimpleJson { - pub fn format(&self, record: &Record, f: &F) -> anyhow::Result<()> +impl JsonLayout { + pub(crate) fn format(&self, record: &Record, f: &F) -> anyhow::Result<()> where F: Fn(Arguments) -> anyhow::Result<()>, { @@ -84,8 +84,8 @@ impl SimpleJson { } } -impl From for Layout { - fn from(layout: SimpleJson) -> Self { - Layout::SimpleJson(layout) +impl From for Layout { + fn from(layout: JsonLayout) -> Self { + Layout::JsonLayout(layout) } } diff --git a/src/layout/kv_display.rs b/src/layout/kv.rs similarity index 100% rename from src/layout/kv_display.rs rename to src/layout/kv.rs diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 87aa181..56ce6cb 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -13,31 +13,31 @@ // limitations under the License. pub use custom::CustomLayout; -pub use identical::Identical; -pub use kv_display::KvDisplay; +pub use identical::IdenticalLayout; #[cfg(feature = "json")] -pub use simple_json::SimpleJson; -pub use simple_text::ColoredLevel; -pub use simple_text::SimpleText; +pub use json::JsonLayout; +pub use kv::KvDisplay; +pub use text::LevelColor; +pub use text::TextLayout; mod custom; mod identical; -mod kv_display; #[cfg(feature = "json")] -mod simple_json; -mod simple_text; +mod json; +mod kv; +mod text; #[derive(Debug)] pub enum Layout { - Identical(Identical), - SimpleText(SimpleText), + Identical(IdenticalLayout), + Text(TextLayout), #[cfg(feature = "json")] - SimpleJson(SimpleJson), + Json(JsonLayout), Custom(CustomLayout), } impl Layout { - pub fn format(&self, record: &log::Record, f: &F) -> anyhow::Result<()> + pub(crate) fn format(&self, record: &log::Record, f: &F) -> anyhow::Result<()> where F: Fn(&log::Record) -> anyhow::Result<()>, { @@ -45,11 +45,11 @@ impl Layout { Layout::Identical(layout) => { layout.format(record, &|args| f(&record.to_builder().args(args).build())) } - Layout::SimpleText(layout) => { + Layout::Text(layout) => { layout.format(record, &|args| f(&record.to_builder().args(args).build())) } #[cfg(feature = "json")] - Layout::SimpleJson(layout) => { + Layout::Json(layout) => { layout.format(record, &|args| f(&record.to_builder().args(args).build())) } Layout::Custom(layout) => { diff --git a/src/layout/simple_text.rs b/src/layout/text.rs similarity index 85% rename from src/layout/simple_text.rs rename to src/layout/text.rs index 5aa42d7..a0691e8 100644 --- a/src/layout/simple_text.rs +++ b/src/layout/text.rs @@ -21,16 +21,16 @@ use colored::ColoredString; use colored::Colorize; use log::Level; -use crate::layout::kv_display::KvDisplay; +use crate::layout::KvDisplay; use crate::layout::Layout; #[derive(Default, Debug, Clone)] -pub struct SimpleText { - pub colors: ColoredLevel, +pub struct TextLayout { + pub colors: LevelColor, } #[derive(Debug, Clone)] -pub struct ColoredLevel { +pub struct LevelColor { pub error: Color, pub warn: Color, pub info: Color, @@ -38,7 +38,7 @@ pub struct ColoredLevel { pub trace: Color, } -impl Default for ColoredLevel { +impl Default for LevelColor { fn default() -> Self { Self { error: Color::Red, @@ -50,8 +50,8 @@ impl Default for ColoredLevel { } } -impl SimpleText { - pub fn format(&self, record: &log::Record, f: &F) -> anyhow::Result<()> +impl TextLayout { + pub(crate) fn format(&self, record: &log::Record, f: &F) -> anyhow::Result<()> where F: Fn(Arguments) -> anyhow::Result<()>, { @@ -81,8 +81,8 @@ impl SimpleText { } } -impl From for Layout { - fn from(layout: SimpleText) -> Self { - Layout::SimpleText(layout) +impl From for Layout { + fn from(layout: TextLayout) -> Self { + Layout::Text(layout) } } diff --git a/src/lib.rs b/src/lib.rs index ffd6d16..cbc538a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,12 @@ // limitations under the License. pub mod append; -pub mod dynlog; pub mod filter; pub mod layout; -pub mod logger; +mod logger; + +pub use append::Append; +pub use filter::Filter; +pub use layout::Layout; +pub use logger::Dispatch; +pub use logger::Logger; diff --git a/src/logger.rs b/src/logger.rs index acea6a2..4a78176 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -19,97 +19,77 @@ use log::Metadata; use log::Record; use crate::append::Append; -use crate::append::AppendImpl; use crate::filter::Filter; -use crate::filter::FilterImpl; use crate::filter::FilterResult; use crate::layout::Layout; - #[derive(Debug)] -pub struct DispatchBuilder { - appends: Vec, +pub struct Dispatch { + filters: Vec, + appends: Vec>, + layout: Option, +} + +impl Default for Dispatch { + fn default() -> Dispatch { + Self::new() + } } -impl DispatchBuilder { - pub fn new(append: impl Into) -> Self { +impl Dispatch { + pub fn new() -> Dispatch { Self { - appends: vec![append.into()], + filters: vec![], + appends: vec![], + layout: None, } } - pub fn append(mut self, append: impl Into) -> Self { - self.appends.push(append.into()); + pub fn filter(mut self, filter: impl Into) -> Dispatch { + self.filters.push(filter.into()); self } - pub fn filter(self, filter: impl Into) -> DispatchFilterBuilder { - DispatchFilterBuilder { - appends: self.appends, - filters: vec![filter.into()], - } - } - - pub fn layout(self, layout: impl Into) -> Dispatch { + pub fn layout(self, layout: impl Into) -> Dispatch { Dispatch { - filters: vec![], + filters: self.filters, appends: self.appends, - preferred_layout: Some(layout.into()), + layout: Some(layout.into()), } } - pub fn finish(self) -> Dispatch { + pub fn append(self, append: impl Append) -> Dispatch { Dispatch { - filters: vec![], - appends: self.appends, - preferred_layout: None, + filters: self.filters, + appends: vec![Box::new(append)], + layout: self.layout, } } } -#[derive(Debug)] -pub struct DispatchFilterBuilder { - appends: Vec, - filters: Vec, -} - -impl DispatchFilterBuilder { - pub fn filter(mut self, filter: impl Into) -> Self { - self.filters.push(filter.into()); - self - } - - pub fn layout(self, layout: impl Into) -> Dispatch { +impl Dispatch { + pub fn append(self, append: impl Append) -> Dispatch { Dispatch { filters: self.filters, - appends: self.appends, - preferred_layout: Some(layout.into()), + appends: vec![Box::new(append)], + layout: self.layout, } } +} - pub fn finish(self) -> Dispatch { +impl Dispatch { + pub fn append(self, append: impl Append) -> Dispatch { Dispatch { filters: self.filters, - appends: self.appends, - preferred_layout: None, + appends: vec![Box::new(append)], + layout: self.layout, } } } -#[derive(Debug)] -pub struct Dispatch { - filters: Vec, - appends: Vec, - preferred_layout: Option, -} - impl Dispatch { - pub fn builder(append: impl Into) -> DispatchBuilder { - DispatchBuilder::new(append) - } - fn enabled(&self, metadata: &Metadata) -> bool { for filter in &self.filters { - match filter.filter_metadata(metadata) { + match filter.filter(metadata) { FilterResult::Reject => return false, FilterResult::Accept => return true, FilterResult::Neutral => {} @@ -119,44 +99,26 @@ impl Dispatch { true } - fn try_append(&self, record: &Record) -> anyhow::Result<()> { - for filter in &self.filters { - match filter.filter_metadata(record.metadata()) { - FilterResult::Reject => return Ok(()), - FilterResult::Accept => break, - FilterResult::Neutral => {} - } - } + fn do_append(&self, record: &Record) -> anyhow::Result<()> { + let layout = self.layout.as_ref(); - fn do_append( - record: &Record, - append: &AppendImpl, - preferred_layout: Option<&Layout>, - ) -> anyhow::Result<()> { - if let Some(filters) = append.default_filters() { - for filter in filters { - match filter.filter_metadata(record.metadata()) { - FilterResult::Reject => return Ok(()), - FilterResult::Accept => break, - FilterResult::Neutral => {} - } + for append in &self.appends { + for filter in append.default_filters() { + match filter.filter(record.metadata()) { + FilterResult::Reject => return Ok(()), + FilterResult::Accept => break, + FilterResult::Neutral => {} } } - match preferred_layout { - Some(layout) => layout.format(record, &|record| append.try_append(record)), + match layout { + Some(layout) => layout.format(record, &|record| append.append(record))?, None => append .default_layout() - .format(record, &|record| append.try_append(record)), + .format(record, &|record| append.append(record))?, } } - let preferred_layout = self.preferred_layout.as_ref(); - - for append in &self.appends { - do_append(record, append, preferred_layout)? - } - Ok(()) } @@ -196,16 +158,16 @@ impl Logger { } impl log::Log for Logger { - fn enabled(&self, metadata: &Metadata) -> bool { - self.dispatches - .iter() - .any(|dispatch| dispatch.enabled(metadata)) + fn enabled(&self, _: &Metadata) -> bool { + true } fn log(&self, record: &Record) { for dispatch in &self.dispatches { - if let Err(err) = dispatch.try_append(record) { - handle_error(record, err); + if dispatch.enabled(record.metadata()) { + if let Err(err) = dispatch.do_append(record) { + handle_error(record, err); + } } } } From 2b0b28463ae689543dd5962a7d913beca8f98545 Mon Sep 17 00:00:00 2001 From: andylokandy Date: Fri, 2 Aug 2024 01:06:11 +0800 Subject: [PATCH 2/5] fix --- examples/fn_layout_filter.rs | 12 ++++++------ examples/json_stdio.rs | 5 ++--- examples/rolling_file.rs | 19 +++++++++---------- examples/simple_stdio.rs | 9 ++++++--- rustfmt.toml | 10 +++++----- src/append/opentelemetry.rs | 6 ++++-- src/filter/min_level.rs | 8 ++++---- src/filter/mod.rs | 3 ++- src/layout/custom.rs | 4 +++- src/layout/identical.rs | 3 ++- src/layout/json.rs | 2 +- 11 files changed, 44 insertions(+), 37 deletions(-) diff --git a/examples/fn_layout_filter.rs b/examples/fn_layout_filter.rs index 1e600cf..cf079be 100644 --- a/examples/fn_layout_filter.rs +++ b/examples/fn_layout_filter.rs @@ -13,12 +13,12 @@ // limitations under the License. use log::LevelFilter; -use logforth::{ - append, - filter::{CustomFilter, FilterResult}, - layout::CustomLayout, - Dispatch, Logger, -}; +use logforth::append; +use logforth::filter::CustomFilter; +use logforth::filter::FilterResult; +use logforth::layout::CustomLayout; +use logforth::Dispatch; +use logforth::Logger; fn main() { Logger::new() diff --git a/examples/json_stdio.rs b/examples/json_stdio.rs index 60b3811..b9f8159 100644 --- a/examples/json_stdio.rs +++ b/examples/json_stdio.rs @@ -14,10 +14,9 @@ use log::LevelFilter; use logforth::append; -use logforth::filter; use logforth::layout; -use logforth::logger::Dispatch; -use logforth::logger::Logger; +use logforth::Dispatch; +use logforth::Logger; fn main() { Logger::new() diff --git a/examples/rolling_file.rs b/examples/rolling_file.rs index 8370c8a..7244956 100644 --- a/examples/rolling_file.rs +++ b/examples/rolling_file.rs @@ -13,14 +13,13 @@ // limitations under the License. use log::LevelFilter; -use logforth::append; -use logforth::append::NonBlockingBuilder; -use logforth::append::RollingFileWriter; -use logforth::append::Rotation; -use logforth::filter; -use logforth::layout; -use logforth::logger::Dispatch; -use logforth::logger::Logger; +use logforth::append::rolling_file::NonBlockingBuilder; +use logforth::append::rolling_file::RollingFile; +use logforth::append::rolling_file::RollingFileWriter; +use logforth::append::rolling_file::Rotation; +use logforth::layout::JsonLayout; +use logforth::Dispatch; +use logforth::Logger; fn main() { let rolling = RollingFileWriter::builder() @@ -36,8 +35,8 @@ fn main() { .dispatch( Dispatch::new() .filter(LevelFilter::Trace) - .layout(layout::JsonLayout) - .append(append::RollingFile::new(writer)), + .layout(JsonLayout) + .append(RollingFile::new(writer)), ) .apply() .unwrap(); diff --git a/examples/simple_stdio.rs b/examples/simple_stdio.rs index cd612f9..55cb772 100644 --- a/examples/simple_stdio.rs +++ b/examples/simple_stdio.rs @@ -12,14 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -use log::Level; -use logforth::{append, filter::MinLevel, layout::TextLayout, Dispatch, Logger}; +use log::LevelFilter; +use logforth::append; +use logforth::layout::TextLayout; +use logforth::Dispatch; +use logforth::Logger; fn main() { Logger::new() .dispatch( Dispatch::new() - .filter(MinLevel(Level::Trace)) + .filter(LevelFilter::Trace) .layout(TextLayout::default()) .append(append::Stdout), ) diff --git a/rustfmt.toml b/rustfmt.toml index 641c1d0..bf58561 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# comment_width = 120 -# format_code_in_doc_comments = true -# group_imports = "StdExternalCrate" -# imports_granularity = "Item" -# wrap_comments = true +comment_width = 120 +format_code_in_doc_comments = true +group_imports = "StdExternalCrate" +imports_granularity = "Item" +wrap_comments = true diff --git a/src/append/opentelemetry.rs b/src/append/opentelemetry.rs index b8e54b4..9a162a8 100644 --- a/src/append/opentelemetry.rs +++ b/src/append/opentelemetry.rs @@ -17,8 +17,10 @@ use std::time::Duration; use std::time::SystemTime; use log::Record; -use opentelemetry::logs::{AnyValue, LoggerProvider as ILoggerProvider}; -use opentelemetry::logs::{Logger, Severity}; +use opentelemetry::logs::AnyValue; +use opentelemetry::logs::Logger; +use opentelemetry::logs::LoggerProvider as ILoggerProvider; +use opentelemetry::logs::Severity; use opentelemetry::InstrumentationLibrary; use opentelemetry_otlp::WithExportConfig; use opentelemetry_sdk::logs::LoggerProvider; diff --git a/src/filter/min_level.rs b/src/filter/min_level.rs index f3c8ee4..464a3ef 100644 --- a/src/filter/min_level.rs +++ b/src/filter/min_level.rs @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -use log::Level; +use log::LevelFilter; use log::Metadata; use crate::filter::Filter; use crate::filter::FilterResult; #[derive(Debug, Clone)] -pub struct MinLevel(pub Level); +pub struct MinLevel(pub LevelFilter); impl MinLevel { pub(crate) fn filter(&self, metadata: &Metadata) -> FilterResult { @@ -37,8 +37,8 @@ impl From for Filter { } } -impl From for Filter { - fn from(filter: Level) -> Self { +impl From for Filter { + fn from(filter: LevelFilter) -> Self { Filter::MinLevel(MinLevel(filter)) } } diff --git a/src/filter/mod.rs b/src/filter/mod.rs index 0f44e80..a6e2c0e 100644 --- a/src/filter/mod.rs +++ b/src/filter/mod.rs @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub use self::{custom::CustomFilter, min_level::MinLevel}; +pub use self::custom::CustomFilter; +pub use self::min_level::MinLevel; mod custom; mod min_level; diff --git a/src/layout/custom.rs b/src/layout/custom.rs index a14614c..ad177c0 100644 --- a/src/layout/custom.rs +++ b/src/layout/custom.rs @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::fmt::{Arguments, Debug, Formatter}; +use std::fmt::Arguments; +use std::fmt::Debug; +use std::fmt::Formatter; use crate::layout::Layout; diff --git a/src/layout/identical.rs b/src/layout/identical.rs index 7124a30..a34999c 100644 --- a/src/layout/identical.rs +++ b/src/layout/identical.rs @@ -12,9 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::layout::Layout; use std::fmt::Arguments; +use crate::layout::Layout; + #[derive(Debug, Default, Clone, Copy)] pub struct IdenticalLayout; diff --git a/src/layout/json.rs b/src/layout/json.rs index 671018e..df52625 100644 --- a/src/layout/json.rs +++ b/src/layout/json.rs @@ -86,6 +86,6 @@ impl JsonLayout { impl From for Layout { fn from(layout: JsonLayout) -> Self { - Layout::JsonLayout(layout) + Layout::Json(layout) } } From 4ea17ece2fbab56f774b144277fb64f90807eefc Mon Sep 17 00:00:00 2001 From: andylokandy Date: Fri, 2 Aug 2024 01:14:18 +0800 Subject: [PATCH 3/5] fix --- Cargo.toml | 2 +- examples/no_color_stdio.rs | 9 ++++----- src/append/mod.rs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aafb7be..8432a16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ rustdoc-args = ["--cfg", "docs"] [features] fastrace = ["dep:fastrace"] -file = ["dep:crossbeam-channel", "dep:parking_lot", "dep:time"] +rolling_file = ["dep:crossbeam-channel", "dep:parking_lot", "dep:time"] json = ["dep:serde_json", "dep:serde"] no-color = ["colored/no-color"] opentelemetry = [ diff --git a/examples/no_color_stdio.rs b/examples/no_color_stdio.rs index 0adb3bb..55cb772 100644 --- a/examples/no_color_stdio.rs +++ b/examples/no_color_stdio.rs @@ -14,17 +14,16 @@ use log::LevelFilter; use logforth::append; -use logforth::filter; -use logforth::layout; -use logforth::logger::Dispatch; -use logforth::logger::Logger; +use logforth::layout::TextLayout; +use logforth::Dispatch; +use logforth::Logger; fn main() { Logger::new() .dispatch( Dispatch::new() .filter(LevelFilter::Trace) - .layout(layout::Text::default()) + .layout(TextLayout::default()) .append(append::Stdout), ) .apply() diff --git a/src/append/mod.rs b/src/append/mod.rs index 19cc35c..97c3818 100644 --- a/src/append/mod.rs +++ b/src/append/mod.rs @@ -28,7 +28,7 @@ use crate::layout::Layout; mod fastrace; #[cfg(feature = "opentelemetry")] mod opentelemetry; -#[cfg(feature = "file")] +#[cfg(feature = "rolling_file")] pub mod rolling_file; mod stdio; From d2d8fe71fae748b484c7501c9e5acddefd91396f Mon Sep 17 00:00:00 2001 From: andylokandy Date: Fri, 2 Aug 2024 01:17:09 +0800 Subject: [PATCH 4/5] fix --- examples/json_stdio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/json_stdio.rs b/examples/json_stdio.rs index b9f8159..59a1658 100644 --- a/examples/json_stdio.rs +++ b/examples/json_stdio.rs @@ -14,7 +14,7 @@ use log::LevelFilter; use logforth::append; -use logforth::layout; +use logforth::layout::JsonLayout; use logforth::Dispatch; use logforth::Logger; @@ -23,7 +23,7 @@ fn main() { .dispatch( Dispatch::new() .filter(LevelFilter::Trace) - .layout(layout::JsonLayout) + .layout(JsonLayout) .append(append::Stdout), ) .apply() From ac90573f5f48024161f892b5e25d55aa590988ed Mon Sep 17 00:00:00 2001 From: andylokandy Date: Fri, 2 Aug 2024 01:25:59 +0800 Subject: [PATCH 5/5] fix --- .github/workflows/ci.yml | 2 +- Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6f45bb..7a1b9a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: cargo run --example fn_layout_filter cargo run --features="no-color" --example no_color_stdio cargo run --features="json" --example json_stdio - cargo run --features="json,file" --example rolling_file + cargo run --features="json,rolling_file" --example rolling_file required: name: Required diff --git a/Cargo.toml b/Cargo.toml index 8432a16..3d182d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,6 @@ rustdoc-args = ["--cfg", "docs"] [features] fastrace = ["dep:fastrace"] -rolling_file = ["dep:crossbeam-channel", "dep:parking_lot", "dep:time"] json = ["dep:serde_json", "dep:serde"] no-color = ["colored/no-color"] opentelemetry = [ @@ -39,6 +38,7 @@ opentelemetry = [ "dep:opentelemetry-otlp", "dep:opentelemetry_sdk", ] +rolling_file = ["dep:crossbeam-channel", "dep:parking_lot", "dep:time"] [dependencies] anyhow = { version = "1.0" } @@ -86,4 +86,4 @@ required-features = ["json"] [[example]] name = "rolling_file" path = "examples/rolling_file.rs" -required-features = ["file", "json"] +required-features = ["rolling_file", "json"]