Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tjardoo committed Sep 12, 2024
1 parent aa4ba76 commit dfd40c3
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 23 deletions.
4 changes: 1 addition & 3 deletions src/drivers/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ impl Log for ConsoleLogger {
}

fn log(&self, record: &log::Record) {
let config = self.config.clone();

let formatter = DefaultFormatter::new(record, config);
let formatter = DefaultFormatter::new(record, &self.config);

println!("{}", formatter.format());
}
Expand Down
4 changes: 1 addition & 3 deletions src/drivers/daily_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ impl Log for DailyFileLogger {
fn log(&self, record: &log::Record) {
self.rotate_file_if_needed();

let config = self.config.clone();

let formatter = DefaultFormatter::new(record, config);
let formatter = DefaultFormatter::new(record, &self.config);

let mut file = self.file.lock().unwrap();
writeln!(file, "{}", formatter.format()).unwrap();
Expand Down
4 changes: 1 addition & 3 deletions src/drivers/formatted_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ impl Log for FormattedConsoleLogger {
}

fn log(&self, record: &log::Record) {
let config = self.config.clone();

let formatter = ReadableFormatter::new(record, config);
let formatter = ReadableFormatter::new(record, &self.config);

println!("{}", formatter.format());
}
Expand Down
3 changes: 1 addition & 2 deletions src/drivers/single_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ impl Log for SingleFileLogger {
}

fn log(&self, record: &log::Record) {
let config = self.config.clone();
let formatter = DefaultFormatter::new(record, config);
let formatter = DefaultFormatter::new(record, &self.config);

let mut file = self.file.lock().unwrap();
writeln!(file, "{}", formatter.format()).unwrap();
Expand Down
8 changes: 3 additions & 5 deletions src/formatters/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ use super::Formatter;

pub struct DefaultFormatter<'a> {
record: &'a log::Record<'a>,
config: Config,
config: &'a Config,
}

impl DefaultFormatter<'_> {
pub fn new<'a>(record: &'a log::Record<'a>, config: Config) -> DefaultFormatter<'a> {
pub fn new<'a>(record: &'a log::Record<'a>, config: &'a Config) -> DefaultFormatter<'a> {
DefaultFormatter { record, config }
}
}

impl<'a> Formatter for DefaultFormatter<'a> {
fn format(&self) -> String {
let config = self.config.clone();

let writer = LogWriter::new(self.record, config);
let writer = LogWriter::new(self.record, self.config);

format!(
"{} {} {} {}",
Expand Down
8 changes: 3 additions & 5 deletions src/formatters/readable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ use super::{Config, Formatter};

pub struct ReadableFormatter<'a> {
record: &'a log::Record<'a>,
config: Config,
config: &'a Config,
}

impl ReadableFormatter<'_> {
pub fn new<'a>(record: &'a log::Record<'a>, config: Config) -> ReadableFormatter<'a> {
pub fn new<'a>(record: &'a log::Record<'a>, config: &'a Config) -> ReadableFormatter<'a> {
ReadableFormatter { record, config }
}
}

impl<'a> Formatter for ReadableFormatter<'a> {
fn format(&self) -> String {
let config = self.config.clone();

let writer = LogWriter::new(self.record, config);
let writer = LogWriter::new(self.record, self.config);

let mut result = String::new();

Expand Down
4 changes: 2 additions & 2 deletions src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use crate::formatters::Config;

pub(crate) struct LogWriter<'a> {
record: &'a Record<'a>,
config: Config,
config: &'a Config,
}

impl<'a> LogWriter<'a> {
pub fn new(record: &'a Record<'a>, config: Config) -> LogWriter<'a> {
pub fn new(record: &'a Record<'a>, config: &'a Config) -> LogWriter<'a> {
LogWriter { record, config }
}

Expand Down

0 comments on commit dfd40c3

Please sign in to comment.