-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add implementation of logger (#93)
- Loading branch information
1 parent
246aaca
commit b87fb09
Showing
4 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "logger" | ||
authors.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
version.workspace = true | ||
|
||
[dependencies] | ||
slog = "2.7.0" | ||
slog-async = "2.8.0" | ||
slog-term = "2.9.1" |
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,4 @@ | ||
pub mod logger; | ||
pub mod traits; | ||
pub use logger::*; | ||
pub use traits::*; |
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,55 @@ | ||
use super::*; | ||
extern crate slog; | ||
extern crate slog_async; | ||
extern crate slog_term; | ||
|
||
use slog::Drain; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct CoreLogger { | ||
logger: slog::Logger, | ||
} | ||
|
||
impl CoreLogger { | ||
pub fn new() -> CoreLogger { | ||
use std::fs::OpenOptions; | ||
|
||
let file = OpenOptions::new() | ||
.create(true) | ||
.write(true) | ||
.append(true) | ||
.open("./workflows.log") | ||
.unwrap(); | ||
|
||
let decorator = slog_term::PlainDecorator::new(file); | ||
let file_drain = slog_term::FullFormat::new(decorator).build().fuse(); | ||
|
||
let decorator = slog_term::TermDecorator::new().build(); | ||
let terminal_drain = slog_term::FullFormat::new(decorator).build().fuse(); | ||
|
||
let drain = slog::Duplicate::new(file_drain, terminal_drain).fuse(); | ||
|
||
let drain = slog_async::Async::new(drain).overflow_strategy(slog_async::OverflowStrategy::Block).build().fuse(); | ||
let logger = slog::Logger::root(drain, slog::o!()); | ||
|
||
CoreLogger { logger } | ||
} | ||
} | ||
|
||
impl Logger for CoreLogger { | ||
fn info(&self, msg: &str) { | ||
slog::info!(self.logger, "{msg:?}"); | ||
} | ||
|
||
fn warn(&self, msg: &str) { | ||
slog::warn!(self.logger, "{msg:?}"); | ||
} | ||
|
||
fn error(&self, msg: &str) { | ||
slog::error!(self.logger, "{msg:?}"); | ||
} | ||
|
||
fn debug(&self, msg: &str) { | ||
slog::debug!(self.logger, "{msg:?}"); | ||
} | ||
} |
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,6 @@ | ||
pub trait Logger { | ||
fn info(&self, msg: &str); | ||
fn warn(&self, msg: &str); | ||
fn error(&self, msg: &str); | ||
fn debug(&self, msg: &str); | ||
} |