Skip to content
Open
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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ parking_lot = { version = "0.12.0", optional = true }
rand = { version = "0.9", optional = true }
thiserror = "2.0.12"
anyhow = "1.0.28"
derive_more = { version = "2.0.1", features = ["debug"] }
mock_instant = "0.6"
unicode-segmentation = "1.10.0"

Expand Down
13 changes: 10 additions & 3 deletions examples/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! - Print messages at the trace and debug levels to the console.
//! - Write messages at the warning and error levels to a file.

use derive_more::Debug;
use core::fmt;
use std::{
fs::{File, OpenOptions},
io::{BufWriter, Write},
Expand Down Expand Up @@ -78,14 +78,21 @@ impl Encode for MyEncoder {
}

/// A custom appender that writes to both console and file based on log level.
#[derive(Debug)]
struct MyAppender {
#[debug(skip)]
console_writer: ConsoleWriter,
file_writer: Mutex<SimpleWriter<BufWriter<File>>>,
encoder: Box<dyn Encode>,
}

impl fmt::Debug for MyAppender {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("MyAppender")
.field("file_writer", &self.file_writer)
.field("encoder", &self.encoder)
.finish_non_exhaustive()
}
}

impl MyAppender {
fn new(file_name: &str, encoder: Box<dyn Encode>) -> Self {
let console_writer = ConsoleWriter::stderr().unwrap();
Expand Down
13 changes: 10 additions & 3 deletions examples/custom_config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! In this example, we will define the Appender, Encoder and Filter using the same code as in custom.rs.
//! However, unlike before, our logger will be initialized from a configuration file.

use derive_more::Debug;
use std::{
fmt,
fs::{File, OpenOptions},
io::{BufWriter, Write},
sync::Mutex,
Expand Down Expand Up @@ -73,14 +73,21 @@ impl Encode for MyEncoder {
}

/// A custom appender that writes to both console and file based on log level.
#[derive(Debug)]
struct MyAppender {
#[debug(skip)]
console_writer: ConsoleWriter,
file_writer: Mutex<SimpleWriter<BufWriter<File>>>,
encoder: Box<dyn Encode>,
}

impl fmt::Debug for MyAppender {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("MyAppender")
.field("file_writer", &self.file_writer)
.field("encoder", &self.encoder)
.finish_non_exhaustive()
}
}

impl MyAppender {
fn new(file_name: &str, encoder: Box<dyn Encode>) -> Self {
let console_writer = ConsoleWriter::stderr().unwrap();
Expand Down
12 changes: 9 additions & 3 deletions src/append/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! Requires the `console_appender` feature.

use derive_more::Debug;
use log::Record;
use std::{
fmt,
Expand All @@ -29,7 +28,7 @@ use crate::{

/// The console appender's configuration.
#[cfg(feature = "config_parsing")]
#[derive(Debug, serde::Deserialize)]
#[derive(serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ConsoleAppenderConfig {
target: Option<ConfigTarget>,
Expand All @@ -50,6 +49,14 @@ enum Writer {
Tty(ConsoleWriter),
Raw(StdWriter),
}
impl fmt::Debug for Writer {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Writer::Tty(_) => write!(f, "Tty"),
Writer::Raw(_) => write!(f, "Raw"),
}
}
}

impl Writer {
fn lock(&self) -> WriterLock<'_> {
Expand Down Expand Up @@ -119,7 +126,6 @@ impl<'a> encode::Write for WriterLock<'a> {
/// or is a TTY on Unix.
#[derive(Debug)]
pub struct ConsoleAppender {
#[debug(skip)]
writer: Writer,
encoder: Box<dyn Encode>,
do_write: bool,
Expand Down
2 changes: 0 additions & 2 deletions src/append/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! Requires the `file_appender` feature.

use chrono::prelude::Local;
use derive_more::Debug;
use log::Record;
use parking_lot::Mutex;
use std::{
Expand Down Expand Up @@ -43,7 +42,6 @@ pub struct FileAppenderConfig {
pub struct FileAppender {
#[allow(dead_code)] // reason = "debug purposes only"
path: PathBuf,
#[debug(skip)]
file: Mutex<SimpleWriter<BufWriter<File>>>,
encoder: Box<dyn Encode>,
}
Expand Down
16 changes: 12 additions & 4 deletions src/append/rolling_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//!
//! Requires the `rolling_file_appender` feature.

use derive_more::Debug;
use core::fmt;
use log::Record;
use parking_lot::Mutex;
use std::{
Expand Down Expand Up @@ -150,16 +150,25 @@ impl<'a> LogFile<'a> {
}

/// An appender which archives log files in a configurable strategy.
#[derive(Debug)]
pub struct RollingFileAppender {
#[debug(skip)]
writer: Mutex<Option<LogWriter>>,
path: PathBuf,
append: bool,
encoder: Box<dyn Encode>,
policy: Box<dyn policy::Policy>,
}

impl fmt::Debug for RollingFileAppender {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RollingFileAppender")
.field("path", &self.path)
.field("append", &self.append)
.field("encoder", &self.encoder)
.field("policy", &self.policy)
.finish()
}
}

impl Append for RollingFileAppender {
fn append(&self, record: &Record<'_>) -> anyhow::Result<()> {
// TODO(eas): Perhaps this is better as a concurrent queue?
Expand Down Expand Up @@ -365,7 +374,6 @@ impl Deserialize for RollingFileAppenderDeserializer {

#[cfg(test)]
mod test {
use derive_more::Debug;
use std::{
fs::File,
io::{Read, Write},
Expand Down
1 change: 0 additions & 1 deletion src/config/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
use std::{collections::HashMap, fmt, marker::PhantomData, sync::Arc, time::Duration};

use anyhow::anyhow;
use derive_more::Debug;
use log::LevelFilter;
use serde::de::{self, Deserialize as SerdeDeserialize, DeserializeOwned};
use serde_value::Value;
Expand Down
2 changes: 0 additions & 2 deletions src/encode/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Encoders

use derive_more::Debug;
use log::Record;
use std::{fmt, io};

Expand Down Expand Up @@ -102,7 +101,6 @@ pub struct Style {
pub background: Option<Color>,
/// True if the text should have increased intensity.
pub intense: Option<bool>,
#[debug(skip)]
_p: (),
}

Expand Down
13 changes: 9 additions & 4 deletions src/encode/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@
//! [log_kv]: https://docs.rs/log/latest/log/kv/index.html

use chrono::{Local, Utc};
use derive_more::Debug;
use log::{Level, Record};
use std::{default::Default, io, mem, process, thread};
use std::{default::Default, fmt, io, mem, process, thread};
use unicode_segmentation::{GraphemeCursor, UnicodeSegmentation};

use crate::encode::{
Expand Down Expand Up @@ -703,12 +702,18 @@ impl FormattedChunk {
}

/// An `Encode`r configured via a format string.
#[derive(Clone, Eq, Debug, PartialEq, Hash)]
#[derive(Clone, Eq, PartialEq, Hash)]
pub struct PatternEncoder {
#[debug(skip)]
chunks: Vec<Chunk>,
pattern: String,
}
impl fmt::Debug for PatternEncoder {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PatternEncoder")
.field("pattern", &self.pattern)
.finish_non_exhaustive()
}
}

/// Returns a `PatternEncoder` using the default pattern of `{d} {l} {t} - {m}{n}`.
impl Default for PatternEncoder {
Expand Down