log

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: MIT Imports: 13 Imported by: 7

Documentation

Overview

nolint:err113

Index

Constants

View Source
const (
	FormatterTypeJson      = "json"
	FormatterTypePlainText = "plain-text"
)
View Source
const (
	DefaultTimestampFormat = time.RFC3339
	FieldKeyMsg            = "msg"
	FieldKeyLevel          = "level"
	FieldKeyTime           = "time"
	FieldKeyLogError       = "error"
	FieldKeyFunc           = "func"
	FieldKeyFile           = "file"
)

Default field names for the default fields

Variables

This section is empty.

Functions

func LogLevelFuncForError

func LogLevelFuncForError(err error, logger Logger) func(ctx context.Context, message any, fields ...Field)

nolint:exhaustive

func StdLoggerWithLevel

func StdLoggerWithLevel(adapter Logger, level Level, withFields ...Field) *stdlog.Logger

func ToContext

func ToContext(ctx context.Context, fields ...Field) context.Context

Types

type Adapter

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

func Default added in v1.4.0

func Default() *Adapter

func New added in v1.4.0

func New(options ...Option) *Adapter

func (*Adapter) Close added in v1.4.0

func (l *Adapter) Close() error

func (*Adapter) Debug

func (l *Adapter) Debug(ctx context.Context, msg any, fields ...Field)

func (*Adapter) Error

func (l *Adapter) Error(ctx context.Context, msg any, fields ...Field)

func (*Adapter) Fatal

func (l *Adapter) Fatal(ctx context.Context, msg any, fields ...Field)

func (*Adapter) Info

func (l *Adapter) Info(ctx context.Context, msg any, fields ...Field)

func (*Adapter) IsLevelEnabled

func (l *Adapter) IsLevelEnabled(level Level) bool

func (*Adapter) Level

func (l *Adapter) Level() Level

func (*Adapter) Log

func (l *Adapter) Log(ctx context.Context, level Level, msg any, fields ...Field)

Log will log a message at the level given as parameter.

func (*Adapter) Panic

func (l *Adapter) Panic(ctx context.Context, msg any, fields ...Field)

func (*Adapter) Print

func (l *Adapter) Print(ctx context.Context, msg any, fields ...Field)

func (*Adapter) Trace

func (l *Adapter) Trace(ctx context.Context, msg any, fields ...Field)

func (*Adapter) Warn

func (l *Adapter) Warn(ctx context.Context, msg any, fields ...Field)

type Config

type Config struct {
	Fileoutput *file.Config
	Formatter  *FormatterConfig
}

type Entry

type Entry struct {
	ReportCaller bool
	Data         Fields
	Time         time.Time
	Level        Level
	Caller       *runtime.Frame
	Message      []byte
}

func (*Entry) HasCaller

func (entry *Entry) HasCaller() bool

type Field

type Field struct {
	Name  string
	Value any
}

func Any

func Any(name string, value any) Field

func Bool added in v1.5.0

func Bool(name string, value bool) Field

func ByteString

func ByteString(name string, value []byte) Field

for UTF-8 encoded string

func Duration added in v1.5.0

func Duration(name string, value time.Duration) Field

func Error added in v1.5.0

func Error(err error) Field

func Float64 added in v1.5.0

func Float64(name string, value float64) Field

func Int added in v1.5.0

func Int(name string, value int) Field

func Int64 added in v1.5.0

func Int64(name string, value int64) Field

func String added in v1.4.0

func String(name string, value string) Field

func Stringer added in v1.5.0

func Stringer(name string, value fmt.Stringer) Field

func Time added in v1.5.0

func Time(name string, value time.Time) Field

func Uint added in v1.5.0

func Uint(name string, value uint) Field

func Uint64 added in v1.5.0

func Uint64(name string, value uint64) Field

func (Field) FormatValue added in v1.5.0

func (f Field) FormatValue() string

type Fields

type Fields []Field

func ContextLogValues

func ContextLogValues(ctx context.Context) Fields

type Formatter

type Formatter interface {
	Format(entry *Entry) ([]byte, error)
}

type FormatterConfig

type FormatterConfig struct {
	Type      string
	Json      *FormatterSettings
	PlainText *FormatterSettings
}

type FormatterSettings added in v1.5.0

type FormatterSettings struct {
	TimestampFormat  string
	DisableTimestamp bool
	PrettyPrint      bool
}

type Level

type Level uint32
const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel Level = iota
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

These are the different logging levels. You can set the logging level to log on your instance of logger

func LogLevelForError

func LogLevelForError(err error) Level

func ParseLogLevel

func ParseLogLevel(lvl string) (Level, error)

func (Level) String

func (l Level) String() string

type LogLevelSpecifier

type LogLevelSpecifier interface {
	LogLevel() Level
}

type Logger

type Logger interface {
	Log(ctx context.Context, level Level, msg any, fields ...Field)
	Trace(ctx context.Context, msg any, fields ...Field)
	Debug(ctx context.Context, msg any, fields ...Field)
	Info(ctx context.Context, msg any, fields ...Field)
	Warn(ctx context.Context, msg any, fields ...Field)
	Error(ctx context.Context, msg any, fields ...Field)
	Fatal(ctx context.Context, msg any, fields ...Field)
	Panic(ctx context.Context, msg any, fields ...Field)
}

type LoggerWriter

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

func (*LoggerWriter) Write

func (l *LoggerWriter) Write(p []byte) (int, error)

type Option added in v1.4.0

type Option func(*Adapter)

func WithExitFunction added in v1.4.0

func WithExitFunction(f exitFunc) Option

func WithFormatter added in v1.4.0

func WithFormatter(formatter Formatter) Option

func WithLevel added in v1.4.0

func WithLevel(level Level) Option

func WithOutput added in v1.4.0

func WithOutput(w ...io.Writer) Option

func WithReportCaller added in v1.4.0

func WithReportCaller(reportCaller bool) Option

Directories

Path Synopsis
nolint
nolint

Jump to

Keyboard shortcuts

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