logger

package
v0.21.17 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: GPL-3.0 Imports: 15 Imported by: 6

Documentation

Index

Constants

View Source
const (
	TraceLevel = Level(iota)
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	PanicLevel
	FatalLevel

	LevelNameUnknown = "NULL"
	LevelNameTrace   = "TRAC"
	LevelNameDebug   = "DEBU"
	LevelNameInfo    = "INFO"
	LevelNameWarn    = "WARN"
	LevelNameError   = "ERRO"
	LevelNamePanic   = "PANC"
	LevelNameFatal   = "CRIT"
)

define levels

Variables

View Source
var LevelColors = map[Level]string{
	TraceLevel: levelColorDebug,
	DebugLevel: levelColorDebug,
	InfoLevel:  levelColorInfo,
	WarnLevel:  levelColorWarn,
	ErrorLevel: levelColorError,
	PanicLevel: levelColorPanic,
	FatalLevel: levelColorFatal,
}

LevelColors printer's color

Functions

func NewFileLogger added in v0.21.2

func NewFileLogger(opts ...FileOption) (*fileLogger, error)

NewFileLogger 标准窗体的输出对象

func NewFileLoggerWithOptions added in v0.21.9

func NewFileLoggerWithOptions(opts FileOptions) (*fileLogger, error)

NewFileLogger 标准窗体的输出对象

func ToLevelName

func ToLevelName(lvl Level) string

ToLevelName corvert level into string name

Types

type FileOption added in v0.21.2

type FileOption func(*FileOptions)

FileOption 操作配置函数

func OptionFilename added in v0.21.9

func OptionFilename(name string) FileOption

OptionFilename 设置文件名

func OptionMaxBackups added in v0.21.9

func OptionMaxBackups(num int) FileOption

OptionMaxBackups 文件最大数量

func OptionMaxLength added in v0.21.9

func OptionMaxLength(length int64) FileOption

OptionMaxLength 设置最大文件大小

func OptionMoveFileType added in v0.21.9

func OptionMoveFileType(typ MoveFileType) FileOption

OptionMoveFileType 设置移动文件的类型

func OptionSeparator added in v0.21.9

func OptionSeparator(separator string) FileOption

OptionSeparator 设置打印分隔符

func OptionStdPrinters added in v0.21.9

func OptionStdPrinters(ps []string) FileOption

OptionStdPrinters 设置移动文件的类型

type FileOptions added in v0.21.2

type FileOptions struct {
	Filename    string   `yaml:"filename"`
	StdPrinters []string `yaml:"std_printers"`

	Separator string `yaml:"separator"`
	MaxLength int64  `yaml:"max_length"`

	MoveFileType MoveFileType `yaml:"move_file_type"`
	// 最大保留日志个数,如果为0则全部保留
	MaxBackups int `yaml:"max_backups"`
}

FileOptions file options

func (*FileOptions) Check added in v0.21.9

func (p *FileOptions) Check() error

type FileSort

type FileSort []os.FileInfo

FileSort 文件排序

func (FileSort) Len

func (fs FileSort) Len() int

func (FileSort) Less

func (fs FileSort) Less(i, j int) bool

func (FileSort) Swap

func (fs FileSort) Swap(i, j int)

type Level

type Level int32

Level log level

func (*Level) ToZapLevel added in v0.21.9

func (p *Level) ToZapLevel() zapcore.Level

ToZapLevel convert level into zap level

type LogConfig added in v0.21.9

type LogConfig struct {
	Level      Level  `yaml:"level"`
	Encoding   string `yaml:"encoding,omitempty"` // json | console, default console
	CallerSkip int    `yaml:"caller_skip"`
	StackTrace bool   `yaml:"stack_trace"`
	Caller     bool   `yaml:"caller"`

	EncoderConfig *zapcore.EncoderConfig `yaml:",inline,omitempty"`

	FileOptions FileOptions `yaml:",inline"`
}

type Logger

type Logger interface {
	SimpleLogger

	With(kvs ...interface{}) Logger

	Debug(msg string, kvs ...interface{}) // Debug(msg string, fields ...Field)
	Debugf(msg string, kvs ...interface{})
	Info(msg string, kvs ...interface{}) // Info(msg string, fields ...Field)
	Infof(msg string, kvs ...interface{})
	Warn(msg string, kvs ...interface{}) // Warn(msg string, fields ...Field)
	Warnf(msg string, kvs ...interface{})
	Error(msg string, kvs ...interface{}) // Error(msg string, fields ...Field)
	Errorf(msg string, kvs ...interface{})
	Panic(msg string, kvs ...interface{})
	Panicf(msg string, kvs ...interface{}) // Panic(msg string, fields ...Field)
	Fatal(msg string, kvs ...interface{})
	Fatalf(msg string, kvs ...interface{}) // Fatal(msg string, fields ...Field)
}

Logger 日志对象

func NewWithZapLogger added in v0.21.15

func NewWithZapLogger(l *zap.Logger) Logger

func Noop added in v0.21.15

func Noop() Logger

Noop logger.

type MoveFileType

type MoveFileType int

MoveFileType move file type

const (
	MoveFileTypeNothing   MoveFileType = iota // 不移动
	MoveFileTypePerMinite                     // 按分钟移动
	MoveFileTypeHourly                        // 按小时移动
	MoveFileTypeDaily                         // 按天移动
)

MoveFileTypes

type Option added in v0.21.1

type Option func(*LogConfig)

func Caller

func Caller() Option

Caller 设置等级

func CallerSkip added in v0.21.9

func CallerSkip(cs int) Option

CallerSkip 设置等级

func EncoderConfig added in v0.21.11

func EncoderConfig(encoder *zapcore.EncoderConfig) Option

EncoderConfig 设置等级

func Encoding added in v0.21.9

func Encoding(encoding string) Option

Encoding 设置移动文件的类型

func LogFileOption added in v0.21.9

func LogFileOption(opts ...FileOption) Option

LogFileOption 设置等级

func LogFileOptions added in v0.21.9

func LogFileOptions(fos *FileOptions) Option

LogFileOptions 设置等级

func LogLevel added in v0.21.9

func LogLevel(lvl Level) Option

LogLevel 设置等级

func StackTrace added in v0.21.9

func StackTrace() Option

StackTrace 设置等级

type SimpleLogger added in v0.21.10

type SimpleLogger interface {
	Log(keyvals ...interface{}) error
}

func NewZapSugarLogger added in v0.21.10

func NewZapSugarLogger(logger *zap.Logger, level zapcore.Level, opts ...zap.Option) SimpleLogger

NewZapSugarLogger returns a Go kit log.Logger that sends log events to a zap.Logger.

type ZapLogger added in v0.21.9

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

func NewLogger

func NewLogger(opts ...Option) (*ZapLogger, error)

func (*ZapLogger) Debug added in v0.21.9

func (p *ZapLogger) Debug(msg string, kvs ...interface{})

Debug(msg string, fields ...Field)

func (*ZapLogger) Debugf added in v0.21.9

func (p *ZapLogger) Debugf(msg string, kvs ...interface{})

Debugf(msg string, fields ...Field)

func (*ZapLogger) Error added in v0.21.9

func (p *ZapLogger) Error(msg string, kvs ...interface{})

Error(msg string, fields ...Field)

func (*ZapLogger) Errorf added in v0.21.9

func (p *ZapLogger) Errorf(msg string, kvs ...interface{})

Errorf(msg string, fields ...Field)

func (*ZapLogger) Fatal added in v0.21.9

func (p *ZapLogger) Fatal(msg string, kvs ...interface{})

Fatal(msg string, fields ...Field)

func (*ZapLogger) Fatalf added in v0.21.9

func (p *ZapLogger) Fatalf(msg string, kvs ...interface{})

Fatalf(msg string, fields ...Field)

func (*ZapLogger) GetZapLogger added in v0.21.11

func (p *ZapLogger) GetZapLogger() *zap.Logger

func (*ZapLogger) Info added in v0.21.9

func (p *ZapLogger) Info(msg string, kvs ...interface{})

Info(msg string, fields ...Field)

func (*ZapLogger) Infof added in v0.21.9

func (p *ZapLogger) Infof(msg string, kvs ...interface{})

Infof(msg string, fields ...Field)

func (*ZapLogger) Log added in v0.21.9

func (p *ZapLogger) Log(kvs ...interface{}) error

Debug(msg string, fields ...Field)

func (*ZapLogger) Panic added in v0.21.9

func (p *ZapLogger) Panic(msg string, kvs ...interface{})

Panic(msg string, fields ...Field)

func (*ZapLogger) Panicf added in v0.21.9

func (p *ZapLogger) Panicf(msg string, kvs ...interface{})

Panicf(msg string, fields ...Field)

func (*ZapLogger) Warn added in v0.21.9

func (p *ZapLogger) Warn(msg string, kvs ...interface{})

Warn(msg string, fields ...Field)

func (*ZapLogger) Warnf added in v0.21.9

func (p *ZapLogger) Warnf(msg string, kvs ...interface{})

Warnf(msg string, fields ...Field)

func (*ZapLogger) With added in v0.21.9

func (p *ZapLogger) With(kvs ...interface{}) Logger

With (fields ...Field)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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