logger

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 13 Imported by: 3

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)

func Debugf

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

func Error

func Error(fields Fields)

func Errorf

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

func Fatal

func Fatal(fields Fields)

func Fatalf

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

func Info

func Info(fields Fields)

func Infof

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

func Log

func Log(level Level, fields Fields)

func Logf

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

func Panic

func Panic(fields Fields)

func Panicf

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

func SetLevel

func SetLevel(level Level)

func SetMarshaller

func SetMarshaller(marshaller Marshaller)

func Warn

func Warn(fields Fields)

func Warnf

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

Types

type Config

type Config struct {
	Level          string `yaml:"level,omitempty" json:"level,omitempty" xml:"level,omitempty"`
	Formatter      string `yaml:"formatter,omitempty" json:"formatter,omitempty" xml:"formatter,omitempty"`
	StdoutFilePath string `yaml:"stdout_file_path,omitempty" json:"stdout_file_path,omitempty" xml:"stdout_file_path,omitempty"`
	StderrFilePath string `yaml:"stderr_file_path,omitempty" json:"stderr_file_path,omitempty" xml:"stderr_file_path,omitempty"`
}

type Entry

type Entry struct {
	File     string         `json:"file" yaml:"file" xml:"file"`
	Level    string         `json:"level" yaml:"level" xml:"level"`
	CallTime string         `json:"call_time" yaml:"call_time" xml:"call_time"`
	Service  string         `json:"service" yaml:"service" xml:"service"`
	TraceID  string         `json:"trace_id" yaml:"trace_id" xml:"trace_id"`
	Message  string         `json:"message,omitempty" yaml:"message,omitempty" xml:"message,omitempty"`
	Data     any            `json:"data,omitempty" yaml:"data,omitempty" xml:"data,omitempty"`
	Extra    map[string]any `json:"extra,omitempty" yaml:"extra,omitempty" xml:"extra,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
	// contains filtered or unexported methods
}

func NewFields

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

func NewFieldsFromEntry added in v1.2.11

func NewFieldsFromEntry(entry *Entry) 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 New

func New() Logger

func NewLoggerWithConfig

func NewLoggerWithConfig(cfg Config) Logger

func NewLoggerWithCustomWriter added in v1.2.10

func NewLoggerWithCustomWriter(stdout, stderr Writer, closable bool, formatter Marshaller, level Level) Logger

type Marshaller

type Marshaller func(entry *Entry) ([]byte, error)
var (
	JsonMarshaller Marshaller = jsonMarshaller
	TextMarshaller Marshaller = textMarshaller
	CsvMarshaller  Marshaller = csvMarshaller
	TsvMarshaller  Marshaller = tsvMarshaller
)

type Options

type Options struct {
	LogLevel     Level
	Marshaller   Marshaller
	StdoutWriter Writer
	StderrWriter Writer
	// contains filtered or unexported fields
}

type Writer

type Writer interface {
	Write(data []byte)
	Close()
	// contains filtered or unexported methods
}

func ConsoleErrorWriter

func ConsoleErrorWriter() Writer

func ConsoleWriter

func ConsoleWriter() Writer

func FileWriter

func FileWriter(path string) (w Writer, err error)

Jump to

Keyboard shortcuts

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