loggers

package
v0.2.50 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 11 Imported by: 6

Documentation

Overview

package loggers contains some basic logging setup.

Index

Constants

This section is empty.

Variables

View Source
var (

	// FieldNameCmd is the name of the field that holds the command name.
	FieldNameCmd = reservedFieldNamePrefix + "_cmd"
	// Used to suppress statements.
	FieldNameStatementID = reservedFieldNamePrefix + "__h_field_statement_id"
)
View Source
var PanicOnWarningHook = func(e *logg.Entry) error {
	if e.Level != logg.LevelWarn {
		return nil
	}
	panic(e.Message)
}

PanicOnWarningHook panics on warnings.

Functions

func InitGlobalLogger

func InitGlobalLogger(level logg.Level, panicOnWarnings bool)

func LevelLoggerToWriter

func LevelLoggerToWriter(l logg.LevelLogger) io.Writer

func SetGlobal added in v0.1.24

func SetGlobal(logger Logger)

func SetGlobalFields added in v0.1.24

func SetGlobalFields(fs *LogFields)

func TimeTrackf

func TimeTrackf(l logg.LevelLogger, start time.Time, fields logg.Fields, format string, a ...any)

func TimeTrackfn

func TimeTrackfn(fn func() (logg.LevelLogger, error)) error

Types

type LogFields added in v0.1.22

type LogFields struct {
	// contains filtered or unexported fields
}

LogFields provides a common implementation for structured logging fields

func GetGlobalFields added in v0.1.24

func GetGlobalFields() *LogFields

func NewLogFields added in v0.1.22

func NewLogFields() *LogFields

NewLogFields creates a new LogFields instance with common fields

func NewLogFieldsWithCommon added in v0.1.22

func NewLogFieldsWithCommon(operation string, sessionID string) *LogFields

func (*LogFields) AddField added in v0.1.22

func (f *LogFields) AddField(name string, value interface{}) *LogFields

AddField adds a new field to the LogFields

func (*LogFields) AddFields added in v0.1.22

func (f *LogFields) AddFields(fields ...logg.Field) *LogFields

AddFields adds multiple fields to the LogFields

func (*LogFields) Fields added in v0.1.22

func (f *LogFields) Fields() logg.Fields

Fields implements the logg.Fielder interface

func (*LogFields) WithLevel added in v0.1.22

func (f *LogFields) WithLevel(level string) *LogFields

WithLevel sets the log level field

type Logger

type Logger interface {
	Debug() logg.LevelLogger
	Debugf(format string, v ...any)
	Debugln(v ...any)
	Error() logg.LevelLogger
	Errorf(format string, v ...any)
	Erroridf(id, format string, v ...any)
	Errorln(v ...any)
	Errors() string
	Info() logg.LevelLogger
	InfoCommand(command string) logg.LevelLogger
	Infof(format string, v ...any)
	Infoln(v ...any)
	Level() logg.Level
	LoggCount(logg.Level) int
	Logger() logg.Logger
	Out() io.Writer
	Printf(format string, v ...any)
	Println(v ...any)
	PrintTimerIfDelayed(start time.Time, name string)
	Reset()
	Warn() logg.LevelLogger
	WarnCommand(command string) logg.LevelLogger
	Warnf(format string, v ...any)
	Warnidf(id, format string, v ...any)
	Warnln(v ...any)
	Deprecatef(fail bool, format string, v ...any)
	Trace(s logg.StringFunc)
}

func Log

func Log() Logger

func New

func New(opts Options) Logger

New creates a new logger with the given options.

func NewDefault

func NewDefault() Logger

NewDefault creates a new logger with the default options.

func NewTrace

func NewTrace() Logger

type Options

type Options struct {
	Level              logg.Level
	Stdout             io.Writer
	Stderr             io.Writer
	DistinctLevel      logg.Level
	StoreErrors        bool
	HandlerPost        func(e *logg.Entry) error
	SuppressStatements map[string]bool
	WithColor          bool
}

Options defines options for the logger.

Jump to

Keyboard shortcuts

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