A minimalist, customizable, easy to use logger for rust, based on the log crate, also adapted to tracing,
for production and testing scenario.
-
Allow customize log format and time format. Refer to LogFormat
-
Dynamic reconfigurable.
-
Support subscribing span and event log from tracing (feature
tracing) with consistent format:-
global default subscriber mode
-
layer mode
-
scoped mode
-
-
Multiple types of sink stacking, each with its own log level.
-
LogConsole: Console output to stdout/stderr. -
LogRawFile: Support atomic appending from multi-process on linux (with ext4, xfs) -
LogBufFile: Write to log file with merged I/O and delay flush, and optional self-rotation.
-
Syslog: (feature
syslog)Write to local or remote syslog server, with timeout and auto reconnect.
-
LogRingFile: (feature
ringfile)For deadlock / race condition debugging, collect log to ring buffer in memory, flush on panic or by signal.
-
-
Log panic message by default.
-
Provide additional macros. For example: log_assert!(), logger_assert!() ...
-
Supports signal listening for log-rotate. Refer to
Builder::signal() -
Provides many preset recipes in recipe module for convenience.
-
Supports configured by environment
-
Fine-grain module-level control and API-level log handling.
Provides
LogFilterandKeyFilterto filter specified logs on-the-fly. Refer to doc -
For test suits usage:
-
Allow dynamic reconfigure logger setting in different test function.
Refer to Unit test example.
-
Provides an attribute macro #[logfn] to wrap test function.
Refer to Best practice with rstest
-
-
Provides a
parserto work on your log files.
Cargo.toml
[dependencies]
log = { version = "0.4", features = ["std", "kv_unstable"] }
captains_log = "0"lib.rs or main.rs:
// By default, reexport the macros from log crate
#[macro_use]
extern crate captains_log;
-
syslog: Enable [Syslog] sink
-
ringfile: Enable [LogRingFile] sink
-
tracing: Receive log from tracing
...
See detail usage on docs.rs