Skip to content

Instantly share code, notes, and snippets.

@DrBluefall
Last active August 18, 2020 16:24
Show Gist options
  • Save DrBluefall/a9829bffe905b3468fcc7a1f4b3ba872 to your computer and use it in GitHub Desktop.
Save DrBluefall/a9829bffe905b3468fcc7a1f4b3ba872 to your computer and use it in GitHub Desktop.
[package]
name = "foo"
version = "0.1.0"
authors = ["drbluefall"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
slog = "2.5"
slog-async = "*"
slog-term = "*"
slog-scope = "*"
slog-envlogger = "*"
slog-unwrap = { version = "0.9", features = [ "scope" ] }
extern crate slog;
extern crate slog_async;
extern crate slog_term;
#[macro_use]
extern crate slog_scope;
extern crate slog_envlogger;
extern crate slog_unwrap;
mod log {
use slog::Drain;
pub fn setup() -> slog_scope::GlobalLoggerGuard {
let file_log = {
let log_file = std::fs::OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open("bot.log")
.unwrap();
let decorator = slog_term::PlainDecorator::new(log_file);
let drain = slog_term::FullFormat::new(decorator)
.build()
.fuse();
slog_async::Async::new(drain).build().fuse()
};
let term_log = {
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_async::Async::new(
slog_envlogger::new(
slog_term::FullFormat::new(decorator).build().fuse())
).build().fuse();
drain
};
let logger = slog::Logger::root(
slog::Duplicate::new(file_log, term_log).fuse(),
slog::o!());
slog_scope::set_global_logger(logger)
}
}
fn main() {
println!("Hello, world!");
let _l = log::setup();
trace!("foo");
debug!("bar");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment