January 2019
Intermediate to advanced
520 pages
14h 32m
English
We will crate a tiny application that writes logs to a file and to a console. Create a new crate and add the following dependencies:
slog = "2.4"slog-async = "2.3"slog-json = "2.3"slog-term = "2.4"
We need slog as the main logging crate for the application. The slog-async crate helps to move log processing to a separate thread. slog-json provides a logger that writes records in JSON format. slog-term provides formats to write messages to a Terminal.
We will import the following types:
use slog::{crit, debug, error, Drain, Duplicate, Level, LevelFilter};use slog_async::Async;use slog_term::{CompactFormat, PlainDecorator};use slog_json::Json;use std::fs::OpenOptions;use std::sync::Mutex;
From the main slog crate, we will use the crit ...
Read now
Unlock full access