logfmt

package
v0.0.0-...-349f3ea Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 26 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Pid = os.Getpid()

Functions

func ColorByLevel

func ColorByLevel(level string) int

func GetTraceID

func GetTraceID(entry *logrus.Entry) string

func Limit

func Limit(ll *logrus.Logger, level logrus.Level, msg []byte, formatter *LogrusFormatter) (filteredMsg []byte, limited bool)

func ParseLevelFromMsg

func ParseLevelFromMsg(msg []byte) (level logrus.Level, s []byte, foundLevelTag bool)

func RegisterLevelKey

func RegisterLevelKey(levelKey string, level logrus.Level)

RegisterLevelKey customizes the log level key in the message, like [DEBUG] for debugging level.

func RegisterLimitConf

func RegisterLimitConf(limitConf LimitConf)

Types

type AsyncConfig

type AsyncConfig struct {
	QueueSize int
}

type CallerPart

type CallerPart struct {
	Digits string
	Sep    string

	Level logrus.Level
	// contains filtered or unexported fields
}

func (CallerPart) Append

func (p CallerPart) Append(b *bytes.Buffer, e Entry)

type ContextPart

type ContextPart struct {
	Name   string
	Digits string
}

func (ContextPart) Append

func (p ContextPart) Append(b *bytes.Buffer, e Entry)

type DiscardFormatter

type DiscardFormatter struct{}

func (DiscardFormatter) Format

func (f DiscardFormatter) Format(_ *logrus.Entry) ([]byte, error)

type Entry

type Entry interface {
	Time() time.Time
	Level() string
	TraceID() string
	Fields() Fields
	Message() string

	// Caller returns Calling method, with package name
	Caller() *runtime.Frame
}

Entry is an interface for log entry.

type EntryItem

type EntryItem struct {
	EntryTime    time.Time
	EntryLevel   string
	EntryTraceID string
	EntryFields  Fields
	EntryMessage string
}

EntryItem is an entry to log.

func (EntryItem) Caller

func (e EntryItem) Caller() *runtime.Frame

func (EntryItem) Fields

func (e EntryItem) Fields() Fields

func (EntryItem) Level

func (e EntryItem) Level() string

func (EntryItem) Message

func (e EntryItem) Message() string

func (EntryItem) Time

func (e EntryItem) Time() time.Time

func (EntryItem) TraceID

func (e EntryItem) TraceID() string

type Fields

type Fields map[string]interface{}

Fields type, used to pass to `WithFields`.

type FieldsPart

type FieldsPart struct{}

func (FieldsPart) Append

func (p FieldsPart) Append(b *bytes.Buffer, e Entry)

type Formatter

type Formatter struct {
	Layout      *Layout
	PrintColor  bool
	PrintCaller bool
	Simple      bool
}

func (Formatter) Format

func (f Formatter) Format(e Entry) []byte

Format formats the log output.

func (Formatter) PrintCallerInfo

func (f Formatter) PrintCallerInfo(fs Fields, b *bytes.Buffer, callSkip int)

func (Formatter) PrintLevel

func (f Formatter) PrintLevel(b *bytes.Buffer, level string)

type GidPart

type GidPart struct {
	Digits string
}

func (GidPart) Append

func (p GidPart) Append(b *bytes.Buffer, e Entry)

type Hook

type Hook struct {
	Writers []*rotate.WriterFormatter
}

Hook is a hook to handle writing to local log files.

func NewHook

func NewHook(writers []*rotate.WriterFormatter) *Hook

NewHook returns new LFS hook. Output can be a string, io.Writer, WriterMap or PathMap. If using io.Writer or WriterMap, user is responsible for closing the used io.Writer.

func (*Hook) Fire

func (hook *Hook) Fire(entry *logrus.Entry) error

Fire writes the log file to defined path or using the defined writer. User who run this function needs write permissions to the file or directory if the file does not yet exist.

func (*Hook) Levels

func (hook *Hook) Levels() []logrus.Level

Levels returns configured log levels.

type Layout

type Layout struct {
	Parts []Part
}

Layout describes the parsed layout of expression.

func NewLayout

func NewLayout(lo Option) (*Layout, error)

NewLayout creates a new layout from string expression.

func (Layout) Append

func (l Layout) Append(b *bytes.Buffer, e Entry)

func (*Layout) ResetForLogFile

func (l *Layout) ResetForLogFile() *Layout

type LevelPart

type LevelPart struct {
	Digits     string
	PrintColor bool
	LowerCase  bool
	Length     int
}

func (LevelPart) Append

func (l LevelPart) Append(b *bytes.Buffer, e Entry)

func (LevelPart) ResetForLogFile

func (l LevelPart) ResetForLogFile() Part

type LimitConf

type LimitConf struct {
	Key       string
	EveryNum  int
	EveryTime time.Duration
	Level     logrus.Level
}

func ParseLimitConf

func ParseLimitConf(msg []byte) (*LimitConf, []byte)

type LiteralPart

type LiteralPart string

func (LiteralPart) Append

func (l LiteralPart) Append(b *bytes.Buffer, _ Entry)

type LogFileReset

type LogFileReset interface {
	ResetForLogFile() Part
}

type LogrusEntry

type LogrusEntry struct {
	*logrus.Entry
	EntryTraceID string
}

func (LogrusEntry) Caller

func (e LogrusEntry) Caller() *runtime.Frame

func (LogrusEntry) Fields

func (e LogrusEntry) Fields() Fields

func (LogrusEntry) Level

func (e LogrusEntry) Level() string

func (LogrusEntry) Message

func (e LogrusEntry) Message() string

func (LogrusEntry) Time

func (e LogrusEntry) Time() time.Time

func (LogrusEntry) TraceID

func (e LogrusEntry) TraceID() string

type LogrusFormatter

type LogrusFormatter struct {
	Formatter
}

func (LogrusFormatter) Format

func (f LogrusFormatter) Format(entry *logrus.Entry) ([]byte, error)

type MessagePart

type MessagePart struct {
	SingleLine bool
}

func (MessagePart) Append

func (p MessagePart) Append(b *bytes.Buffer, e Entry)

type NewLinePart

type NewLinePart struct{}

func (NewLinePart) Append

func (n NewLinePart) Append(b *bytes.Buffer, e Entry)

type Option

type Option struct {
	Layout string

	Level  string
	Rotate string

	LogPath      string
	TotalSizeCap int64 // 可选,用来指定所有日志文件的总大小上限,例如设置为3GB的话,那么到了这个值,就会删除旧的日志
	MaxSize      int64
	MaxAge       time.Duration
	GzipAge      time.Duration
	Simple       bool
	Stdout       bool
	PrintCaller  bool
	PrintColor   bool
	FixStd       bool // 是否增强log.Print...的输出
}

Option defines the options to setup logrus logging system.

func (Option) Setup

func (lo Option) Setup(ll *logrus.Logger) *Result

Setup setup log parameters.

type Part

type Part interface {
	Append(*bytes.Buffer, Entry)
}

type PidPart

type PidPart struct {
	Digits string
}

func (PidPart) Append

func (p PidPart) Append(b *bytes.Buffer, e Entry)

type Result

type Result struct {
	io.Writer
	Rotate *rotate.Rotate
	Option Option
}

func (*Result) OnExit

func (r *Result) OnExit() error

func (*Result) RegisterSignalRotate

func (r *Result) RegisterSignalRotate(sig ...os.Signal) error

RegisterSignalRotate register a signal like syscall.SIGHUP to rotate the log file.

type Time

type Time struct {
	Format string
}

func (Time) Append

func (t Time) Append(b *bytes.Buffer, e Entry)

type TracePart

type TracePart struct {
	Digits string
}

func (TracePart) Append

func (t TracePart) Append(b *bytes.Buffer, e Entry)

Jump to

Keyboard shortcuts

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