log

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleStream

type ConsoleStream string
const (
	ConsoleStreamStdout ConsoleStream = "stdout"
	ConsoleStreamStderr ConsoleStream = "stderr"
)

func MakeConsoleStream

func MakeConsoleStream(raw string) ConsoleStream

type FileRotation

type FileRotation struct {
	MaxSize    int
	Compress   bool
	MaxAge     int
	MaxBackups int
	LocalTime  bool
	// RotateOnTime enables log rotation based on time.
	RotateOnTime bool
	// RotatePeriod is the period for log rotation.
	// Supports daily(d), hourly(h), minute(m) and second(s).
	RotatePeriod string
	// RotateAfter sets a value for time based rotation.
	// Log file rotates every RotateAfter * RotatePeriod.
	RotateAfter int
}

Rotation stores configs for the log rotation. See more in https://github.com/natefinch/lumberjack/tree/v2.0

type Level

type Level int
const (
	LevelDebug Level = 1 << iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
)

func MakeLevelWithName

func MakeLevelWithName(name string) Level

func (Level) ShortName

func (l Level) ShortName() string

func (Level) String

func (l Level) String() string

type LocalFormat

type LocalFormat struct {
	Format MessageFormat

	MessageKey string
	TimeKey    string
	LevelKey   string
	NameKey    string
	CallerKey  string
	// 时间格式
	TimeFormat TimeFormat // 默认为TimeFormatRFC3339
}

func MakeLocalFormat

func MakeLocalFormat(msg MessageFormat) LocalFormat

type LogPair

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

func Any

func Any(k string, v interface{}) LogPair

func ConvertStrMapToLogPairs

func ConvertStrMapToLogPairs(values map[string]interface{}) []LogPair

func Error

func Error(err error) LogPair

func JsonString

func JsonString(k string, v any) LogPair

func Stack

func Stack(stack []byte) LogPair

func String

func String(k, v string) LogPair

func (LogPair) String

func (p LogPair) String() string

type Logger

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

func NewLogger

func NewLogger(outputs ...Output) Logger

func NewLoggerWithTrace

func NewLoggerWithTrace(logger *Logger, traceTime time.Time, tracePairs ...LogPair) Logger

func WithContext

func WithContext(ctx context.Context) Logger

func (Logger) CanOutput

func (l Logger) CanOutput(level Level) bool

func (Logger) Debug

func (l Logger) Debug(subject string, pairs ...LogPair)

func (Logger) Error

func (l Logger) Error(subject string, pairs ...LogPair)

func (Logger) Info

func (l Logger) Info(subject string, pairs ...LogPair)

func (Logger) IsEmpty

func (l Logger) IsEmpty() bool

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

DO NOT USE IN SERVER

func (Logger) Warn

func (l Logger) Warn(subject string, pairs ...LogPair)

func (Logger) WithTrace

func (l Logger) WithTrace(trace Trace) Logger

func (Logger) WithTraceLogs

func (l Logger) WithTraceLogs(pairs ...LogPair) Logger

func (Logger) WrapContext

func (l Logger) WrapContext(ctx context.Context) context.Context

type MessageFormat

type MessageFormat string
const (
	MessageFormatJSON MessageFormat = "json"
	MessageFormatText MessageFormat = "text"
)

func MakeMessageFormat

func MakeMessageFormat(raw string) MessageFormat

MakeMessageFormat would product MessageFormat with raw string. MessageFormatText would be default returning if no matched.

type Output

type Output interface {
	Level() Level
	LogModuleAndPairs(l Level, subject string, pairs []LogPair)
}

func MakeConsoleOutput

func MakeConsoleOutput(name string, fmt LocalFormat, level Level, stream ConsoleStream) Output

func MakeFileOutput

func MakeFileOutput(name string, fmt LocalFormat, level Level, location string, rotation FileRotation) Output

type TimeFormat

type TimeFormat string
const (
	TimeFormatRFC3339 TimeFormat = "rfc3339"
	TimeFormatISO8601 TimeFormat = "iso8601"
	TimeFormatSeconds TimeFormat = "seconds"
	TimeFormatMillis  TimeFormat = "millis"
	TimeFormatNanos   TimeFormat = "nanos"
)

func MakeTimeFormat

func MakeTimeFormat(raw string) TimeFormat

type Trace

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

func NewTrace

func NewTrace(traceID string, t time.Time, pairs ...LogPair) Trace

type TraceID

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

func NewTraceID

func NewTraceID() TraceID

func (TraceID) String

func (t TraceID) String() string

Jump to

Keyboard shortcuts

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