slog_glog_fmt/
lib.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under both the MIT license found in the
5 * LICENSE-MIT file in the root directory of this source tree and the Apache
6 * License, Version 2.0 found in the LICENSE-APACHE file in the root directory
7 * of this source tree.
8 */
9
10//! # A slog `Drain` for glog-formatted  logs.
11//!
12//! ## Usage
13//!
14//! For simple programs where you need glog-formatted logs to standard error, use the `logger`
15//! convenience function to create your logger:
16//!
17//! ```
18//! use slog::info;
19//!
20//! fn main() {
21//!     let log = slog_glog_fmt::facebook_logger().unwrap();
22//!     info!(log, "glog-formatted logs available");
23//! }
24//! ```
25//!
26//! For more complicated scenarios, create a `GlogFormat` instance using a normal slog-term
27//! decorator, and use that to construct the root `Logger` instance.  You can combine the
28//! `GlogFormat` drain with other drains in the usual way. The `KVCategorizer` controls how the KV
29//! values should be printed.
30//!
31//! ```
32//! use std::sync::Mutex;
33//! use slog::{debug, o, Drain, Logger};
34//! use slog_glog_fmt::kv_categorizer::InlineCategorizer;
35//!
36//! pub fn main() {
37//!     let decorator = slog_term::TermDecorator::new().build();
38//!     let drain = slog_glog_fmt::GlogFormat::new(decorator, InlineCategorizer).fuse();
39//!     let drain = Mutex::new(drain).fuse();
40//!     let log = Logger::root(drain, o!());
41//!     debug!(log, "Custom logger built.");
42//! }
43//! ```
44
45#![deny(warnings, missing_docs, clippy::all, rustdoc::broken_intra_doc_links)]
46#![allow(clippy::needless_doctest_main)]
47pub mod collector_serializer;
48mod glog_format;
49pub mod kv_categorizer;
50pub mod kv_defaults;
51
52pub use crate::glog_format::default_drain;
53pub use crate::glog_format::facebook_logger;
54pub use crate::glog_format::logger_that_can_work_in_tests;
55pub use crate::glog_format::GlogFormat;