-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add level filters * WIP * WIP * WIP
- Loading branch information
Showing
13 changed files
with
447 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ pub mod console; | |
pub mod daily_file; | ||
pub mod formatted_console; | ||
pub mod single_file; | ||
#[cfg(test)] | ||
pub mod test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::{ | ||
formatters::{default::DefaultFormatter, Formatter}, | ||
Config, | ||
}; | ||
use log::{LevelFilter, Log}; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
pub struct TestLogger { | ||
pub buffer: Arc<Mutex<Vec<String>>>, | ||
pub config: Config, | ||
} | ||
|
||
impl TestLogger { | ||
#[cfg(test)] | ||
pub fn new(config: Config) -> Self { | ||
TestLogger { | ||
buffer: Arc::new(Mutex::new(Vec::new())), | ||
config, | ||
} | ||
} | ||
} | ||
|
||
impl Log for TestLogger { | ||
fn enabled(&self, metadata: &log::Metadata) -> bool { | ||
if self.config.level_filter == LevelFilter::Off { | ||
return true; | ||
} | ||
|
||
metadata.level() <= self.config.level_filter | ||
} | ||
|
||
fn log(&self, record: &log::Record) { | ||
if !self.enabled(record.metadata()) { | ||
return; | ||
} | ||
|
||
let formatter = DefaultFormatter::new(record, &self.config); | ||
|
||
let mut buffer = self.buffer.lock().unwrap(); | ||
buffer.push(formatter.format()); | ||
} | ||
|
||
fn flush(&self) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.