-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: use the standard rustlang log for all logging purposes
BREAKING this replaces the custom logging implementation with the standard rust-lang/log library that is implemented for many backends https://github.com/rust-lang/log Signed-off-by: Amin Yahyaabadi <[email protected]>
- Loading branch information
Showing
17 changed files
with
69 additions
and
434 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,18 @@ | ||
//! Use the simplelog and log libraries to implement the Logger trait to customize the log manager. | ||
//! Use the simplelog for logging. | ||
extern crate dagrs; | ||
extern crate log; | ||
extern crate simplelog; | ||
|
||
use std::collections::HashMap; | ||
|
||
use dagrs::{Dag, LogLevel, Logger}; | ||
use dagrs::Dag; | ||
use simplelog::*; | ||
|
||
struct MyLogger { | ||
level: LogLevel, | ||
} | ||
|
||
impl MyLogger { | ||
/// Create MyLogger and set the log level of simplelog. | ||
fn new(level: LogLevel) -> Self { | ||
let filter = match level { | ||
LogLevel::Debug => LevelFilter::Debug, | ||
LogLevel::Info => LevelFilter::Info, | ||
LogLevel::Warn => LevelFilter::Warn, | ||
LogLevel::Error => LevelFilter::Error, | ||
LogLevel::Off => LevelFilter::Off, | ||
}; | ||
CombinedLogger::init(vec![TermLogger::new( | ||
filter, | ||
Config::default(), | ||
TerminalMode::Mixed, | ||
ColorChoice::Auto, | ||
)]) | ||
.unwrap(); | ||
MyLogger { level } | ||
} | ||
} | ||
|
||
/// In turn, use the corresponding logging macro of log to override the Logger method. | ||
impl Logger for MyLogger { | ||
fn level(&self) -> LogLevel { | ||
self.level | ||
} | ||
|
||
fn debug(&self, msg: String) { | ||
log::debug!("{}", msg); | ||
} | ||
|
||
fn info(&self, msg: String) { | ||
log::info!("{}", msg); | ||
} | ||
|
||
fn warn(&self, msg: String) { | ||
log::warn!("{}", msg); | ||
} | ||
|
||
fn error(&self, msg: String) { | ||
log::error!("{}", msg); | ||
} | ||
} | ||
|
||
fn main() { | ||
// Initialize the global logger with a custom logger. | ||
let _initialized = dagrs::log::init_custom_logger(MyLogger::new(LogLevel::Info)); | ||
// Initialize the global logger with a simplelogger as the logging backend. | ||
let _ = SimpleLogger::init(LevelFilter::Info, Config::default()); | ||
|
||
let mut dag = Dag::with_yaml("tests/config/correct.yaml", HashMap::new()).unwrap(); | ||
assert!(dag.start().unwrap()); | ||
} |
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
Oops, something went wrong.