Documentation
¶
Overview ¶
Package logging provides the single logging setup used by all provider-services commands: option parsing, a zap-backed implementation of cosmossdk.io/log.Logger, cobra wiring and the canonical log keys.
The attestation sidecar, a separate module, keeps a copy in sidecar/attestation/internal/logging. Changes to options, values, defaults or parsing go into both; testdata/conformance.json is run by both test suites.
Index ¶
Constants ¶
const ( FlagLogLevel = cflags.FlagLogLevel FlagLogFormat = cflags.FlagLogFormat FlagLogColor = cflags.FlagLogColor FlagLogTimestamp = cflags.FlagLogTimestamp FlagTrace = cflags.FlagTrace )
Option (flag / config key) names. Environment variables are derived by viper, e.g. AP_LOG_LEVEL, AP_LOG_FORMAT, AP_LOG_COLOR, AP_LOG_TIMESTAMP, AP_TRACE.
const ( FormatPlain = "plain" FormatJSON = "json" )
const ( TimestampOff = "off" TimestampRFC3339 = "rfc3339" TimestampRFC3339Nano = "rfc3339nano" TimestampKitchen = "kitchen" )
const ( DefaultLevel = "info" DefaultFormat = FormatPlain DefaultColor = true DefaultTimestamp = TimestampRFC3339Nano DefaultTrace = false )
const ( // KeyModule names the component emitting the entry. Set it only via With. KeyModule = "module" // KeyErr carries an error value. KeyErr = "err" KeyLeaseID = "lid" KeyOrderID = "oid" KeyDeploymentID = "did" KeyBidID = "bid" KeyGroupID = "gid" KeyNamespace = "ns" KeyOwner = "owner" KeyProvider = "provider" KeyService = "service" KeyHostname = "hostname" KeyCount = "count" KeyGroupName = "group_name" KeyListenAddr = "listen_addr" )
Canonical log keys. All keys are snake_case; see _docs/logging.md for the full dictionary.
Variables ¶
This section is empty.
Functions ¶
func AddFlags ¶
AddFlags registers log_level, log_format, log_color and log_timestamp with the provider defaults. The trace flag is registered by cometbft's PrepareBaseCmd.
func New ¶
New returns a logger writing to w (os.Stdout when w is nil) configured by cfg.
The returned logger keeps exactly one "module" field: With("module", x) on a logger that already has a module replaces it. Level and per-module filters are evaluated before an entry is encoded.
func NormalizeTimestampForUpstream ¶
NormalizeTimestampForUpstream rewrites an effective log_timestamp of "off" to "" on the command's flag, so pkg.akt.dev/go/cli's root pre-run (which accepts only ""|rfc3339|rfc3339nano|kitchen) does not reject it. The effective value is taken, in order, from the changed flag, <prefix>_LOG_TIMESTAMP for each env prefix, and the global viper (config file).
func Setup ¶
Setup builds the logger from the logging options and stores it, together with its Config, in the command context. When the context already holds a logger, Setup returns it unchanged.
Each option is also read from <PREFIX>_<OPTION> for every prefix in envPrefixes, earlier prefixes taking precedence, so the environment applies even to commands whose pre-run does not bind those prefixes (operator subcommands).
Types ¶
type Config ¶
type Config struct {
// LevelSpec is the normalized log_level value: a level name or a module
// filter list "module:level,...,*:level".
LevelSpec string
// Level applies to entries without a module, or with a module not listed in Modules.
// When the filter list has no "*" entry it is the lowest level (unfiltered).
Level zapcore.Level
// Modules holds per-module levels from the filter list (nil when none).
Modules map[string]zapcore.Level
// Format is either FormatPlain or FormatJSON.
Format string
// Color enables ANSI colors. Always false when Format is FormatJSON.
Color bool
// Timestamp is one of the Timestamp* constants ("" is normalized to TimestampOff).
Timestamp string
// Trace enables stack traces on error entries.
Trace bool
}
Config is the resolved logging configuration.
func ConfigFromCtx ¶
ConfigFromCtx returns the configuration stored by Setup.
func ConfigFromViper ¶
ConfigFromViper reads the logging options from v. Options not set in v take their defaults.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the configuration used when no option is set.
func ParseConfig ¶
ParseConfig validates and normalizes raw option values.