logger

package
v1.2.18 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 11 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LevelValueMap = map[Level]int{LevelDebug: 0, LevelInfo: 1, LevelWarn: 2, LevelError: 3, LevelFatal: 4, LevelPanic: 5}
)

Functions

func Debug

func Debug(fields Fields)

Debug logs a message at the Debug level with the given fields.

Parameters:

fields (Fields): The fields to include in the log message.

func Debugf

func Debugf(fields Fields, format string, args ...any)

Debugf logs a formatted message at the Debug level with the given fields.

Parameters:

fields (Fields): The fields to include in the log message.
format (string): The format string for the log message.
args (...any): The arguments for the format string.

func Error

func Error(fields Fields)

Error logs a message at the Error level with the given fields.

Parameters:

fields (Fields): The fields to include in the log message.

func Errorf

func Errorf(fields Fields, format string, args ...any)

Errorf logs a formatted message at the Error level with the given fields.

Parameters:

fields (Fields): The fields to include in the log message.
format (string): The format string for the log message.
args (...any): The arguments for the format string.

func Fatal

func Fatal(fields Fields)

Fatal logs a message at the Fatal level with the given fields and then exits the application.

Parameters:

fields (Fields): The fields to include in the log message.

func Fatalf

func Fatalf(fields Fields, format string, args ...any)

Fatalf logs a formatted message at the Fatal level with the given fields and then exits the application.

Parameters:

fields (Fields): The fields to include in the log message.
format (string): The format string for the log message.
args (...any): The arguments for the format string.

func Info

func Info(fields Fields)

Info logs a message at the Info level with the given fields.

Parameters:

fields (Fields): The fields to include in the log message.

func Infof

func Infof(fields Fields, format string, args ...any)

Infof logs a formatted message at the Info level with the given fields.

Parameters:

fields (Fields): The fields to include in the log message.
format (string): The format string for the log message.
args (...any): The arguments for the format string.

func Log

func Log(level Level, fields Fields)

Log logs a message at the specified level with the given fields.

Parameters:

level (Level): The log level (e.g., Debug, Info, Warn, Error, Fatal, Panic).
fields (Fields): The fields to include in the log message.

func Logf

func Logf(level Level, fields Fields, format string, args ...any)

Logf logs a formatted message at the specified level with the given fields.

Parameters:

level (Level): The log level (e.g., Debug, Info, Warn, Error, Fatal, Panic).
fields (Fields): The fields to include in the log message.
format (string): The format string for the log message.
args (...any): The arguments for the format string.

func Panic

func Panic(fields Fields)

Panic logs a message at the Panic level with the given fields and then panics.

Parameters:

fields (Fields): The fields to include in the log message.

func Panicf

func Panicf(fields Fields, format string, args ...any)

Panicf logs a formatted message at the Panic level with the given fields and then panics.

Parameters:

fields (Fields): The fields to include in the log message.
format (string): The format string for the log message.
args (...any): The arguments for the format string.

func Warn

func Warn(fields Fields)

Warn logs a message at the Warn level with the given fields.

Parameters:

fields (Fields): The fields to include in the log message.

func Warnf

func Warnf(fields Fields, format string, args ...any)

Warnf logs a formatted message at the Warn level with the given fields.

Parameters:

fields (Fields): The fields to include in the log message.
format (string): The format string for the log message.
args (...any): The arguments for the format string.

Types

type Entry

type Entry struct {
	File     string         `json:"file" yaml:"file" xml:"file"`
	Level    string         `json:"level" yaml:"level" xml:"level"`
	Service  string         `json:"service" yaml:"service" xml:"service"`
	TraceID  string         `json:"trace_id" yaml:"trace_id" xml:"trace_id"`
	CallTime string         `json:"call_time" yaml:"call_time" xml:"call_time"`
	Data     any            `json:"data,omitempty" yaml:"data,omitempty" xml:"data,omitempty"`
	Extra    map[string]any `json:"extra,omitempty" yaml:"extra,omitempty" xml:"extra,omitempty"`
	Message  string         `json:"message,omitempty" yaml:"message,omitempty" xml:"message,omitempty"`
	// contains filtered or unexported fields
}

type Fields

type Fields interface {
	Export() *Entry
	WithTraceID(traceID string) Fields
	WithMessage(message string) Fields
	WithData(data any) Fields
	WithField(key string, value any) Fields
	WithLevel(level Level) Fields
	WithService(service string) Fields
	WithCallTime(callTime time.Time) Fields
	WithBaseFields(base Fields) Fields
	WithAttachFields(attach Fields) Fields
	// contains filtered or unexported methods
}

func NewFields

func NewFields(ctx ...context.Context) Fields

type Level

type Level string
const (
	LevelDebug Level = "debug"
	LevelInfo  Level = "info"
	LevelWarn  Level = "warn"
	LevelError Level = "error"
	LevelFatal Level = "fatal"
	LevelPanic Level = "panic"
)

type Logger

type Logger interface {
	Debug(fields Fields)
	Info(fields Fields)
	Warn(fields Fields)
	Error(fields Fields)
	Fatal(fields Fields)
	Panic(fields Fields)
	Log(level Level, fields Fields)
	Logf(level Level, fields Fields, format string, args ...any)
	Debugf(fields Fields, format string, args ...any)
	Infof(fields Fields, format string, args ...any)
	Warnf(fields Fields, format string, args ...any)
	Errorf(fields Fields, format string, args ...any)
	Fatalf(fields Fields, format string, args ...any)
	Panicf(fields Fields, format string, args ...any)
}

func Default

func Default() Logger

func File added in v1.2.17

func File(file string, level Level) Logger

func Mute added in v1.2.16

func Mute() Logger

func NewCustomLoggerWithOpts added in v1.2.17

func NewCustomLoggerWithOpts(opts ...Option) Logger

NewCustomLoggerWithOpts creates and returns a new custom logger instance with the specified options. This function initializes a custom logger with default values and then applies the provided options to it.

The logger is configured with default options for standard writer, JSON formatting, and log level set to Info. Additional options can be passed and will be applied in the order they are provided.

Parameters:

opts (...Option): A variadic parameter that allows passing multiple
                  Option functions to customize the logger.

Returns:

Logger: A configured logger instance with applied options.

type Option added in v1.2.17

type Option func(*customLogger)

func WithAttachFields added in v1.2.17

func WithAttachFields(fields Fields) Option

func WithCustomWriterOpts added in v1.2.17

func WithCustomWriterOpts(writer Writer) Option

func WithFileWriterOpts added in v1.2.17

func WithFileWriterOpts(file string) Option

func WithHookOpts added in v1.2.17

func WithHookOpts(hook func(Fields), levels ...Level) Option

func WithJsonFormatOpts added in v1.2.17

func WithJsonFormatOpts() Option

func WithLevelOpts added in v1.2.17

func WithLevelOpts(level Level) Option

func WithStdWriterOpts added in v1.2.17

func WithStdWriterOpts() Option

type Writer

type Writer interface {
	Write(data []byte)
	Close()
}

func NewFileWriter added in v1.2.17

func NewFileWriter(path string) Writer

func NewMultiWriter added in v1.2.17

func NewMultiWriter(writers ...Writer) Writer

func NewStderrConsoleWriter added in v1.2.17

func NewStderrConsoleWriter() Writer

func NewStdoutConsoleWriter added in v1.2.17

func NewStdoutConsoleWriter() Writer

func NewTimeBasedRotationFileWriter added in v1.2.17

func NewTimeBasedRotationFileWriter(directory string, rotation func(time time.Time) (filename string)) Writer

Jump to

Keyboard shortcuts

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