log

package
v0.0.0-...-9345fe3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// G shortcut to get logger from the context
	G = GetLogger
	// L the default logger
	L = DefaultLogger()
)

Functions

func Debug

func Debug(v ...interface{})

Debug ...

func Debugf

func Debugf(format string, v ...interface{})

Debugf ...

func Error

func Error(v ...interface{})

Error ...

func Errorf

func Errorf(format string, v ...interface{})

Errorf ...

func Fatal

func Fatal(v ...interface{})

Fatal ...

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf ...

func Info

func Info(v ...interface{})

Info ...

func Infof

func Infof(format string, v ...interface{})

Infof ...

func Warning

func Warning(v ...interface{})

Warning ...

func Warningf

func Warningf(format string, v ...interface{})

Warningf ...

func WithLogger

func WithLogger(ctx context.Context, logger *Logger) context.Context

WithLogger returns a new context with the provided logger.

Types

type Fields

type Fields = map[string]interface{}

Fields type alias to map[string]interface{}

type Formatter

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

Formatter formats records in different ways: text, json, etc.

type Level

type Level int

Level ...

const (
	// DebugLevel debug
	DebugLevel Level = iota
	// InfoLevel info
	InfoLevel
	// WarningLevel warning
	WarningLevel
	// ErrorLevel error
	ErrorLevel
	// FatalLevel fatal
	FatalLevel
)

func GetLevel

func GetLevel() Level

GetLevel return the verbosity level of default logger

type Logger

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

Logger provides a struct with fields that describe the details of logger.

func DefaultLogger

func DefaultLogger() *Logger

DefaultLogger returns the default logger within the pkg, i.e. the one used in log.Infof....

func GetLogger

func GetLogger(ctx context.Context) *Logger

GetLogger retrieves the current logger from the context. If no logger is available, the default logger is returned.

func New

func New(out io.Writer, fmtter Formatter, lvl Level, options ...interface{}) *Logger

New returns a customized Logger

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug ...

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

Debugf ...

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

Error ...

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

Errorf ...

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

Fatal ...

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf ...

func (*Logger) GetLevel

func (l *Logger) GetLevel() Level

GetLevel returns the verbosity level of this logger

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

Info ...

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

Infof ...

func (*Logger) SetFallback

func (l *Logger) SetFallback(logger *Logger)

SetFallback enable fallback when error happen

func (*Logger) SetOutput

func (l *Logger) SetOutput(out io.Writer)

SetOutput sets the output of Logger l

func (*Logger) Warning

func (l *Logger) Warning(v ...interface{})

Warning ...

func (*Logger) Warningf

func (l *Logger) Warningf(format string, v ...interface{})

Warningf ...

func (*Logger) WithDepth

func (l *Logger) WithDepth(depth int) *Logger

WithDepth returns cloned logger with new depth

func (*Logger) WithField

func (l *Logger) WithField(key string, value interface{}) *Logger

WithField returns cloned logger which fields merged with field key=value

func (*Logger) WithFields

func (l *Logger) WithFields(fields Fields) *Logger

WithFields returns cloned logger which fields merged with the new fields

type Record

type Record struct {
	Time time.Time // time when the log produced
	Msg  string    // content of the log
	Line string    // in which file and line that the log produced
	Lvl  Level     // level of the log
}

Record holds information about log

func NewRecord

func NewRecord(time time.Time, msg, line string, lvl Level) *Record

NewRecord creates a record according to the arguments provided and returns it

type TextFormatter

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

TextFormatter represents a kind of formatter that formats the logs as plain text

func NewTextFormatter

func NewTextFormatter() *TextFormatter

NewTextFormatter returns a TextFormatter, the format of time is time.RFC3339

func (*TextFormatter) Format

func (t *TextFormatter) Format(r *Record) (b []byte, err error)

Format formats the logs as "time [level] line message"

func (*TextFormatter) SetTimeFormat

func (t *TextFormatter) SetTimeFormat(fmt string)

SetTimeFormat sets time format of TextFormatter if the parameter fmt is not null

Jump to

Keyboard shortcuts

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