Crates.io | slog_mongodb |
lib.rs | slog_mongodb |
version | 1.0.0 |
source | src |
created_at | 2020-03-29 15:14:16.873289 |
updated_at | 2020-03-29 15:14:16.873289 |
description | MongoDB drain for slog-rs |
homepage | |
repository | https://github.com/jwillbold/slog_mongodb |
max_upload_size | |
id | 224092 |
size | 17,784 |
MongoDB extension for Rust's logging library slog-rs. Serializes slog messages to BSON documents and stores them in a MongoDB collection. To reduce the stress on the database, the logged messages are buffered and only sent in configurable time intervals.
use slog::*;
fn main() {
let client = mongodb::Client::with_uri_str("mongodb://localhost:27017/").unwrap();
let db = client.database("some_db");
let logs = db.collection("logs");
let drain = slog_mongodb::MongoDBDrain::new(logs, std::time::Duration::from_secs(5)).fuse();
let drain = slog_async::Async::new(drain).build().fuse();
let log = Logger::root(drain, o!());
info!(log, "Hello MongoDB!");
}
By default, the logged messages contain the following values:
This behavior can be changed by constructing the drain as follows:
use slog::*;
fn main() {
let client = mongodb::Client::with_uri_str("mongodb://localhost:27017/").unwrap();
let db = client.database("some_db");
let logs = db.collection("logs");
let drain = MongoDBDrainBuilder::new(logs, std::time::Duration::from_secs(5))
.add_key_value(o!("key" => "value")).build();
let drain = slog_async::Async::new(drain).build().fuse();
let log = Logger::root(drain, o!());
info!(log, "Hello MongoDB!");
}
The serde serialization as well as the overall design is copied from slog-json.