clap-logflag
The clap-logflag library can be used to add a --log flag to
clap based command line applications that allows users to configure
logging from the command line. It can log to stderr, files and syslog, powered by the
fern logging backend.
Examples
# Log to a single destination
# Log to both stderr and a file
# Filter log levels. Debug (and higher) gets logged to stderr.
# Info (and higher) additionally gets logged to a file.
# Disable logging
# Use default logging setup (defined by the application developer)
Setup
To use clap-logflag, first add clap-logflag, clap and log to your Cargo.toml.
Then, add the LogArgs struct to your clap definition and initialize logging with it:
use Parser;
use LoggingConfig;
use LevelFilter;
Command Line Syntax
See LogArgs for a detailed explanation of the syntax for the --log argument.
Log Format
The format of the log messages uses an opinionated, reasonably pretty format by default. At the moment, this library does not offer a way to modify the format.

Log lines contain a UTC timestamp, the log level and an executable name.
When the logging destination is stderr and stderr is a terminal, then the log level is colorized. When logging to a file, syslog or to a stderr that is redirected to a file, the log level is not colorized.
Help message
clap-logflag will automatically add a detailed help message to the --help output of your application,
explaining the usage of the --log flag to your users.
At the moment, this library does not offer a way to modify the help message.
|
| | | |
| | |
)
License: MIT OR Apache-2.0