Log to journald, and log panics
This integrates a bit better than having `cosmic-session` copy logs from stderr to journald, and works when not started through `cosmic-session`. Having panics logged should be helpful if panics ever occur.
This commit is contained in:
parent
31768f2c97
commit
49e0a5f3f4
3 changed files with 111 additions and 15 deletions
|
|
@ -9,20 +9,18 @@ pub struct LogState {
|
|||
|
||||
pub fn init_logger() -> Result<LogState> {
|
||||
let decorator = slog_term::TermDecorator::new().stderr().build();
|
||||
let term_drain = slog_term::CompactFormat::new(decorator)
|
||||
.build()
|
||||
.ignore_res();
|
||||
let journald_drain = slog_journald::JournaldDrain.ignore_res();
|
||||
let drain = slog::Duplicate::new(term_drain, journald_drain);
|
||||
// usually we would not want to use a Mutex here, but this is usefull for a prototype,
|
||||
// to make sure we do not miss any in-flight messages, when we crash.
|
||||
let logger = slog::Logger::root(
|
||||
std::sync::Mutex::new(
|
||||
slog_term::CompactFormat::new(decorator)
|
||||
.build()
|
||||
.ignore_res(),
|
||||
)
|
||||
.fuse(),
|
||||
slog::o!(),
|
||||
);
|
||||
let logger = slog::Logger::root(std::sync::Mutex::new(drain).fuse(), slog::o!());
|
||||
|
||||
let _guard = slog_scope::set_global_logger(logger);
|
||||
slog_stdlog::init().unwrap();
|
||||
log_panics::init();
|
||||
|
||||
slog_scope::info!("Version: {}", std::env!("CARGO_PKG_VERSION"));
|
||||
if cfg!(feature = "debug") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue