log

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: MIT Imports: 9 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 FluentOutput

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

func (*FluentOutput) Init

func (o *FluentOutput) Init()

func (*FluentOutput) Level

func (o *FluentOutput) Level() Level

func (*FluentOutput) Log

func (o *FluentOutput) Log(l Level, msg string, argPairs []interface{})

func (*FluentOutput) LogFormatted

func (o *FluentOutput) LogFormatted(l Level, format string, args []interface{})

func (*FluentOutput) LogMap

func (o *FluentOutput) LogMap(l Level, msg string, values map[string]interface{})

func (*FluentOutput) LogPlainMessage

func (o *FluentOutput) LogPlainMessage(l Level, args []interface{})

type Level

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

func MakeLevelWithName

func MakeLevelWithName(name string) Level

type LocalFormat

type LocalFormat struct {
	Format MessageFormat

	MessageKey string // 默认为M
	TimeKey    string // 默认为T
	LevelKey   string // 默认为L
	NameKey    string // 默认为N
	CallerKey  string // 默认为C
	// 时间格式
	TimeFormat TimeFormat // 默认为TimeFormatISO8601
}

func MakeLocalFormat

func MakeLocalFormat(msg MessageFormat) LocalFormat

type Logger

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

func NewLogger

func NewLogger(outpers ...Output) *Logger

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...interface{})

func (*Logger) Debugf

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

func (*Logger) Debugm

func (l *Logger) Debugm(msg string, values map[string]interface{})

func (*Logger) Error

func (l *Logger) Error(msg string, args ...interface{})

func (*Logger) Errorf

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

func (*Logger) Errorm

func (l *Logger) Errorm(msg string, values map[string]interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, args ...interface{})

func (*Logger) Fatalf

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

func (*Logger) Fatalm

func (l *Logger) Fatalm(msg string, values map[string]interface{})

func (*Logger) Info

func (l *Logger) Info(msg string, args ...interface{})

func (*Logger) Infof

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

func (*Logger) Infom

func (l *Logger) Infom(msg string, values map[string]interface{})

func (*Logger) Log

func (l *Logger) Log(level Level, msg string, argPairs ...interface{})

发送可转换为key-value结构的消息. - Parameters:

  • argPairs: 键值对列表,键或值为nil的将不被记录

console: 直接发给zap.w处理 fluent: 拼成map {"message": msg, "data": {arg0: arg1, arg2: arg3, ...}}

func (*Logger) LogFormatted

func (l *Logger) LogFormatted(level Level, format string, args ...interface{})

发送格式化后的简单消息,逻辑与LogPlainMessage基本相同

func (*Logger) LogMap

func (l *Logger) LogMap(level Level, msg string, values map[string]interface{})

发送消息 console: 解构后发给zap.w处理 fluent: 直接发送

func (*Logger) LogPlainMessage

func (l *Logger) LogPlainMessage(level Level, args ...interface{})

发送简单消息 console: 直接发给zap处理 fluent: 将所有args串接起来调用fluent output的LogMap(level, joinedString, nil)

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

func (*Logger) Warnm

func (l *Logger) Warnm(msg string, values map[string]interface{})

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
	Log(l Level, msg string, argPairs []interface{})
	LogMap(l Level, msg string, values map[string]interface{})
	LogPlainMessage(l Level, args []interface{})
	LogFormatted(l Level, format string, args []interface{})
}

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

func MakeFluentOutput

func MakeFluentOutput(level Level, tag string, config fluent.Config) Output

type TimeFormat

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

func MakeTimeFormat

func MakeTimeFormat(raw string) TimeFormat

Jump to

Keyboard shortcuts

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