Skip to main content

Module logging

Module logging 

Source
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 > default precedence to each individual field.

Enums§

LogFormat
Log file format.

Functions§

build_env_filter
Build an EnvFilter from an explicit level/directive spec (e.g. "debug" or "bhtune_cli=debug,sqlx=warn"), falling back to info if level is 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 Pretty for None or any unrecognized value – a config typo in log.format should degrade gracefully rather than stop a tune from running.
parse_rotation
Parse the configured rotation policy. Defaults to DAILY for None or any unrecognized value, for the same reason as parse_log_format.
resolve_log_settings
Resolve every logging setting. cli_level already has RUST_LOG folded in by clap’s env attribute on Cli::log_level; dir/format/rotation have no env var, matching the rest of the config surface (see crate::config).