Expand description
Structured logging (cli-logging), matching opcda-bridge-gateway’s own tracing
stack and log.* configuration conventions (level/directory/format/rotation, resolved
with the same CLI flag > env var > config file > default precedence as every other
bhtune setting) – see crate::config::LogConfig/resolve_log_settings.
Deliberately never writes to stdout. bhtune tune/simulate --output json prints a
single machine-readable JSON object to stdout as its whole documented contract (see
AGENTS.md’s “Automation” section); mirroring diagnostic log lines onto that same stream
(as opcda-bridge-gateway’s equivalent does, safely, since it owns stdout outright) would
risk interleaving free-form log text into a stream a scheduler parses as JSON. Log lines
go to the rotating file always, and to stderr (never stdout) when a console is
attached – stderr can never corrupt stdout’s contract, so mirroring there is free.
This is diagnostic/operational logging only: the CLI’s actual product output (the tune
summary, history/export listings) stays exactly what it already was, plain println!
calls in commands::* – unaffected by, and independent of, whatever this module does.
Structs§
- LogSettings
- Resolved logging settings, after applying
CLI flag > env var > config file > defaultprecedence to each individual field.
Enums§
- LogFormat
- Log file format.
Functions§
- build_
env_ filter - Build an
EnvFilterfrom an explicit level/directive spec (e.g."debug"or"bhtune_cli=debug,sqlx=warn"), falling back toinfoiflevelis absent or fails to parse. Logging misconfiguration should degrade gracefully rather than stop a tune from running. - init_
tracing - Initialize the process-global tracing subscriber: a non-blocking rolling file writer
under
settings.dir, plus a stderr writer when a console is actually attached (a scheduled/cron invocation typically has none). Never touches stdout – see the module doc comment. - parse_
log_ format - Parse the configured log format. Defaults to
PrettyforNoneor any unrecognized value – a config typo inlog.formatshould degrade gracefully rather than stop a tune from running. - parse_
rotation - Parse the configured rotation policy. Defaults to
DAILYforNoneor any unrecognized value, for the same reason asparse_log_format. - resolve_
log_ settings - Resolve every logging setting.
cli_levelalready hasRUST_LOGfolded in by clap’senvattribute onCli::log_level;dir/format/rotationhave no env var, matching the rest of the config surface (seecrate::config).