logging

package
v0.16.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const (
	FormatPlain = "plain"
	FormatJSON  = "json"
)
View Source
const (
	TimestampOff         = "off"
	TimestampRFC3339     = "rfc3339"
	TimestampRFC3339Nano = "rfc3339nano"
	TimestampKitchen     = "kitchen"
)
View Source
const (
	DefaultLevel     = "info"
	DefaultFormat    = FormatPlain
	DefaultColor     = true
	DefaultTimestamp = TimestampRFC3339Nano
	DefaultTrace     = false
)
View Source
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

func AddFlags(fs *pflag.FlagSet)

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

func New(w io.Writer, cfg Config) log.Logger

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

func NormalizeTimestampForUpstream(cmd *cobra.Command, envPrefixes ...string) error

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

func Setup(cmd *cobra.Command, envPrefixes ...string) (log.Logger, error)

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

func ConfigFromCtx(ctx context.Context) (Config, bool)

ConfigFromCtx returns the configuration stored by Setup.

func ConfigFromViper

func ConfigFromViper(v *viper.Viper) (Config, error)

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

func ParseConfig(level, format string, color bool, timestamp string, trace bool) (Config, error)

ParseConfig validates and normalizes raw option values.

func (Config) Env

func (c Config) Env(prefix string) []EnvVar

Env returns the configuration as environment variables with the given prefix, e.g. prefix "ATTESTATION_" yields ATTESTATION_LOG_LEVEL ... ATTESTATION_TRACE.

type EnvVar

type EnvVar struct {
	Name  string
	Value string
}

EnvVar is a name/value pair used to propagate the configuration to other processes.

Directories

Path Synopsis
Package logtest provides a cosmossdk.io/log.Logger that records entries for assertions in tests.
Package logtest provides a cosmossdk.io/log.Logger that records entries for assertions in tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL