Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement logger for aurras lite runtime #93

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions runtime/lite/modules/logger/Cargo.toml
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"
4 changes: 4 additions & 0 deletions runtime/lite/modules/logger/src/lib.rs
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::*;
55 changes: 55 additions & 0 deletions runtime/lite/modules/logger/src/logger.rs
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:?}");
}
}
6 changes: 6 additions & 0 deletions runtime/lite/modules/logger/src/traits.rs
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);
}
Loading