log

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: MIT Imports: 14 Imported by: 7

Documentation

Overview

nolint:err113

Index

Constants

View Source
const FormatterTypeJson = "json"

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

IsLevelEnabled checks if the log level of the logger is greater than the level param

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. Warning: using Log at Panic or Fatal level will not respectively Panic nor Exit. For this behaviour logger.Panic or logger.Fatal should be used instead.

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      string
}

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 ByteString

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

for UTF-8 encoded string

func String added in v1.4.0

func String(name string, value string) Field

type Fields

type Fields map[string]any

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 *JsonFormatterConfig
}

type JsonFormatterConfig added in v1.4.0

type JsonFormatterConfig struct {
	TimestampFormat   string
	DisableTimestamp  bool
	DisableHtmlEscape bool
	PrettyPrint       bool
	DataKey           string
}

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 MutexWrap

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

func (*MutexWrap) Disable

func (mw *MutexWrap) Disable()

func (*MutexWrap) Lock

func (mw *MutexWrap) Lock()

func (*MutexWrap) Unlock

func (mw *MutexWrap) Unlock()

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