Documentation
¶
Overview ¶
Package types contains the types for the log package.
Index ¶
Constants ¶
const ( TraceStr = "trace" DebugStr = "debug" InfoStr = "info" WarnStr = "warn" ErrorStr = "error" CriticalStr = "critical" OffStr = "off" )
Log level string representations
Variables ¶
This section is empty.
Functions ¶
func ToSlogLevel ¶
ToSlogLevel converts a LogLevel to a slog.Level
func ValidateLevelRules ¶ added in v0.86.0
ValidateLevelRules reports whether spec is a valid log level specification, as accepted by ParseLevelRules.
Types ¶
type LevelRules ¶ added in v0.86.0
type LevelRules struct {
// contains filtered or unexported fields
}
LevelRules is an immutable log level configuration: a default level, applied to any package not selected by a more specific rule, plus any number of per-package overrides.
func NewLevelRules ¶ added in v0.86.0
func NewLevelRules(level LogLevel) *LevelRules
NewLevelRules returns a LevelRules applying level by default and no per-package overrides.
func ParseLevelRules ¶ added in v0.86.0
func ParseLevelRules(spec, modulePrefix string) (*LevelRules, error)
ParseLevelRules parses a log level specification into a LevelRules.
A specification is a comma-separated list of instructions. Each instruction is either a bare level (e.g. "debug"), which sets the default level applied to any package not selected by a more specific instruction, or "<pattern>=<level>", which overrides the level for the packages selected by pattern:
- "some/pkg/path" selects exactly that package.
- "some/pkg/path/..." selects that package and any of its subpackages.
- "./relative/path" and "./relative/path/..." are the same as above, but relative to modulePrefix.
- "." alone refers to modulePrefix itself.
When several instructions select the same package, the most specific one wins. At most one bare level may be given; if none is given, the default level is InfoLvl.
func (*LevelRules) DefaultLevel ¶ added in v0.86.0
func (c *LevelRules) DefaultLevel() LogLevel
DefaultLevel returns the level applied to packages that don't match any rule in the configuration.
func (*LevelRules) LevelForPC ¶ added in v0.86.0
func (c *LevelRules) LevelForPC(pc uintptr) LogLevel
LevelForPC returns the effective log level for the call site identified by pc, as captured by runtime.Callers.
func (*LevelRules) MinLevel ¶ added in v0.86.0
func (c *LevelRules) MinLevel() LogLevel
MinLevel returns the most permissive level enabled anywhere by this configuration.
func (*LevelRules) Spec ¶ added in v0.86.0
func (c *LevelRules) Spec() string
Spec returns the specification string this configuration corresponds to.
type LogLevel ¶
LogLevel is the type of log levels
const ( TraceLvl LogLevel = LogLevel(slog.LevelDebug - 4) DebugLvl LogLevel = LogLevel(slog.LevelDebug) InfoLvl LogLevel = LogLevel(slog.LevelInfo) WarnLvl LogLevel = LogLevel(slog.LevelWarn) ErrorLvl LogLevel = LogLevel(slog.LevelError) CriticalLvl LogLevel = LogLevel(slog.LevelError + 4) Off LogLevel = LogLevel(slog.LevelError + 8) )
Log levels
func FromSlogLevel ¶
FromSlogLevel converts a slog.Level to a LogLevel
func ValidateLogLevel ¶ added in v0.86.0
ValidateLogLevel validates the given log level and returns the corresponding LogLevel.
type LoggerInterface ¶
type LoggerInterface interface {
// Trace formats message using the default formats for its operands
// and writes to log with level = Trace
Trace(v ...interface{})
// Debug formats message using the default formats for its operands
// and writes to log with level = Debug
Debug(v ...interface{})
// Info formats message using the default formats for its operands
// and writes to log with level = Info
Info(v ...interface{})
// Warn formats message using the default formats for its operands
// and writes to log with level = Warn
Warn(v ...interface{}) error
// Error formats message using the default formats for its operands
// and writes to log with level = Error
Error(v ...interface{}) error
// Critical formats message using the default formats for its operands
// and writes to log with level = Critical
Critical(v ...interface{}) error
// Close flushes all the messages in the logger and closes it. It cannot be used after this operation.
Close()
// Flush flushes all the messages in the logger.
Flush()
// SetAdditionalStackDepth sets the additional number of frames to skip by runtime.Caller
SetAdditionalStackDepth(depth int) error
// Sets logger context that can be used in formatter funcs and custom receivers
SetContext(context interface{})
// Tracef formats message according to format specifier
// and writes to log with level = Trace.
Tracef(format string, params ...interface{})
// Debugf formats message according to format specifier
// and writes to log with level = Debug.
Debugf(format string, params ...interface{})
// Infof formats message according to format specifier
// and writes to log with level = Info.
Infof(format string, params ...interface{})
// Warnf formats message according to format specifier
// and writes to log with level = Warn.
Warnf(format string, params ...interface{}) error
// Errorf formats message according to format specifier
// and writes to log with level = Error.
Errorf(format string, params ...interface{}) error
// Criticalf formats message according to format specifier
// and writes to log with level = Critical.
Criticalf(format string, params ...interface{}) error
}
LoggerInterface provides basic logging methods that can be used from outside the log package.
type RulesSync ¶ added in v0.86.0
type RulesSync struct {
// contains filtered or unexported fields
}
RulesSync is a dynamically updatable LevelRules holder, safe for concurrent use. It implements slog.Leveler.
func NewRulesSync ¶ added in v0.86.0
func NewRulesSync(levelRules *LevelRules) *RulesSync
NewRulesSync returns a RulesSync initialized with levelRules.
func NewRulesSyncFromLevel ¶ added in v0.86.0
NewRulesSyncFromLevel returns a RulesSync initialized with a single level applying to all packages.
func (*RulesSync) EnabledForPC ¶ added in v0.86.0
EnabledForPC reports whether level is enabled for the call site identified by pc, as captured by runtime.Callers.
func (*RulesSync) Load ¶ added in v0.86.0
func (s *RulesSync) Load() *LevelRules
Load returns the current LevelRules.
func (*RulesSync) Store ¶ added in v0.86.0
func (s *RulesSync) Store(levelRules *LevelRules)
Store atomically replaces the current LevelRules.