logcli

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 14 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 logcli wires the logging package into urfave/cli applications: the log flags, the CLIConfig they parse into, the logger constructors that consume it, and the process-level logger setup a service performs at startup.

It is separate from op-service/log so that op-service/log stays free of in-repo dependencies and can be imported by any package in the monorepo.

Index

Constants

View Source
const (
	LevelFlagName  = "log.level"
	FormatFlagName = "log.format"
	ColorFlagName  = "log.color"
	PidFlagName    = "log.pid"
)

Variables

This section is empty.

Functions

func AppOut

func AppOut(ctx *cli.Context) io.Writer

AppOut returns an io.Writer to write app output to, like logs. This falls back to os.Stdout if the ctx, ctx.App or ctx.App.Writer are nil.

func CLIFlags

func CLIFlags(envPrefix string) []cli.Flag

func CLIFlagsWithCategory

func CLIFlagsWithCategory(envPrefix string, category string) []cli.Flag

CLIFlagsWithCategory creates flag definitions for the logging utils. Warning: flags are not safe to reuse due to an upstream urfave default-value mutation bug in GenericFlag. Use cliapp.ProtectFlags(flags) to create a copy before passing it into an App if the app runs more than once.

func NewLogHandler

func NewLogHandler(wr io.Writer, cfg CLIConfig) slog.Handler

NewLogHandler creates a new configured handler, compatible as LvlSetter for log-level changes during runtime.

func NewLogger

func NewLogger(wr io.Writer, cfg CLIConfig) log.Logger

NewLogger creates a new configured logger. The log handler of the logger is a LvlSetter, i.e. the log level can be changed as needed.

func SetGlobalLogHandler

func SetGlobalLogHandler(h slog.Handler)

SetGlobalLogHandler sets the log handles as the handler of the global default logger. The usage of this logger is strongly discouraged, as it does makes it difficult to distinguish different services in the same process, e.g. during tests. Geth and other components may use the global logger however, and it is thus recommended to set the global log handler to catch these logs.

This cannot move into op-service/log: it tags the global logger through logfilter, an in-repo package, and op-service/log must stay free of in-repo imports.

func SetupDefaults

func SetupDefaults()

Types

type CLIConfig

type CLIConfig struct {
	Level  slog.Level
	Color  bool
	Format log.FormatType
	Pid    bool
}

func DefaultCLIConfig

func DefaultCLIConfig() CLIConfig

DefaultCLIConfig creates a default log configuration. Color defaults to true if terminal is detected.

func ReadCLIConfig

func ReadCLIConfig(ctx cliiface.Context) CLIConfig

func ReadTestCLIConfig

func ReadTestCLIConfig() CLIConfig

ReadTestCLIConfig reads the CLI config from flags and environment variables into a CLIConfig. flag.Parse() must be called before calling this function.

type FormatFlagValue

type FormatFlagValue log.FormatType

FormatFlagValue is a value type for cli.GenericFlag to parse and validate log-formatting-type values

func NewFormatFlagValue

func NewFormatFlagValue(fmtType log.FormatType) *FormatFlagValue

func (*FormatFlagValue) Clone

func (fv *FormatFlagValue) Clone() any

func (FormatFlagValue) FormatType

func (fv FormatFlagValue) FormatType() log.FormatType

func (*FormatFlagValue) Set

func (fv *FormatFlagValue) Set(value string) error

func (FormatFlagValue) String

func (fv FormatFlagValue) String() string

type LevelFlagValue

type LevelFlagValue slog.Level

LevelFlagValue is a value type for cli.GenericFlag to parse and validate log-level values. Log level: trace, debug, info, warn, error, crit. Capitals are accepted too.

func NewLevelFlagValue

func NewLevelFlagValue(lvl slog.Level) *LevelFlagValue

func (*LevelFlagValue) Clone

func (fv *LevelFlagValue) Clone() any

func (LevelFlagValue) Level

func (fv LevelFlagValue) Level() slog.Level

func (*LevelFlagValue) Set

func (fv *LevelFlagValue) Set(value string) error

func (LevelFlagValue) String

func (fv LevelFlagValue) String() string

Jump to

Keyboard shortcuts

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