-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for noop logger also (#77)
Currently , user could only input the tracinglogger, added option to add nooplogger also for testing purposes --------- Co-authored-by: supernovahs <supernovahs@proton.me>
- Loading branch information
1 parent
5d9a2cc
commit ddb0136
Showing
14 changed files
with
148 additions
and
144 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,28 +1,17 @@ | ||
use super::log_level::LogLevel; | ||
use std::fmt::Debug; | ||
use std::sync::Arc; | ||
|
||
pub trait Logger { | ||
type LoggerType: Logger; | ||
pub type SharedLogger = Arc<dyn Logger>; | ||
|
||
fn new_text_logger( | ||
no_color: bool, | ||
time_format: String, | ||
level: LogLevel, | ||
add_source: bool, | ||
) -> Self::LoggerType; | ||
|
||
fn new_json_logger( | ||
no_color: bool, | ||
time_format: String, | ||
level: LogLevel, | ||
add_source: bool, | ||
) -> Self::LoggerType; | ||
|
||
fn debug(&self, msg: &str, args: &[impl Debug]); | ||
fn info(&self, msg: &str, args: &[impl Debug]); | ||
fn warn(&self, msg: &str, args: &[impl Debug]); | ||
fn error(&self, msg: &str, args: &[impl Debug]); | ||
fn fatal(&self, msg: &str, args: &[impl Debug]); | ||
pub fn tags_as_debug<'a>(tags: &'a [&'a str]) -> Vec<&'a dyn Debug> { | ||
tags.iter().map(|tag| tag as &dyn Debug).collect() | ||
} | ||
|
||
fn log(&self, msg: &str, args: &[impl Debug]); | ||
pub trait Logger: Debug + Send + Sync { | ||
fn debug(&self, msg: &str, args: &str); | ||
fn info(&self, msg: &str, args: &str); | ||
fn warn(&self, msg: &str, args: &str); | ||
fn error(&self, msg: &str, args: &str); | ||
fn fatal(&self, msg: &str, args: &str); | ||
fn log(&self, msg: &str, args: &str); | ||
} |
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,36 +1,37 @@ | ||
use super::log_level::LogLevel; | ||
use super::logger::Logger; | ||
use std::fmt::Debug; | ||
use std::sync::Arc; | ||
|
||
#[derive(Debug, Default)] | ||
#[derive(Debug, Default, Clone)] | ||
pub struct NoopLogger {} | ||
|
||
impl Logger for NoopLogger { | ||
type LoggerType = NoopLogger; | ||
|
||
fn new_text_logger( | ||
impl NoopLogger { | ||
pub fn new_text_logger( | ||
_no_color: bool, | ||
_time_format: String, | ||
_level: LogLevel, | ||
_add_source: bool, | ||
) -> Self::LoggerType { | ||
NoopLogger {} | ||
) -> Arc<dyn Logger> { | ||
Arc::new(NoopLogger {}) | ||
} | ||
|
||
fn new_json_logger( | ||
pub fn new_json_logger( | ||
_no_color: bool, | ||
_time_format: String, | ||
_level: LogLevel, | ||
_add_source: bool, | ||
) -> Self::LoggerType { | ||
) -> Self { | ||
NoopLogger {} | ||
} | ||
} | ||
|
||
fn debug(&self, _msg: &str, _args: &[impl Debug]) {} | ||
fn info(&self, _msg: &str, _args: &[impl Debug]) {} | ||
fn warn(&self, _msg: &str, _args: &[impl Debug]) {} | ||
fn error(&self, _msg: &str, _args: &[impl Debug]) {} | ||
fn fatal(&self, _msg: &str, _args: &[impl Debug]) {} | ||
impl Logger for NoopLogger { | ||
fn debug(&self, _msg: &str, _args: &str) {} | ||
fn info(&self, _msg: &str, _args: &str) {} | ||
fn warn(&self, _msg: &str, _args: &str) {} | ||
fn error(&self, _msg: &str, _args: &str) {} | ||
fn fatal(&self, _msg: &str, _args: &str) {} | ||
|
||
fn log(&self, _msg: &str, _args: &[impl Debug]) {} | ||
fn log(&self, _msg: &str, _args: &str) {} | ||
} |
Oops, something went wrong.