logger

package
v0.0.0-...-cda2eac Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: GPL-3.0 Imports: 21 Imported by: 11

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 (
	DefaultEncoderConfig = zapcore.EncoderConfig{
		TimeKey:        "ts",
		LevelKey:       "level",
		NameKey:        "log",
		CallerKey:      "caller",
		MessageKey:     "msg",
		StacktraceKey:  "stacktrace",
		LineEnding:     zapcore.DefaultLineEnding,
		EncodeLevel:    zapcore.LowercaseLevelEncoder,
		EncodeTime:     zapcore.RFC3339NanoTimeEncoder,
		EncodeDuration: zapcore.SecondsDurationEncoder,
		EncodeCaller:   zapcore.ShortCallerEncoder,
	}
)
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

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

NewFileLogger 标准窗体的输出对象

func NewFileLoggerWithOptions

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

NewFileLoggerWithOptions 标准窗体的输出对象

func ToLevelName

func ToLevelName(lvl Level) string

ToLevelName convert level into string name

Types

type FileOption

type FileOption func(*FileOptions)

FileOption 操作配置函数

func OptionFilename

func OptionFilename(name string) FileOption

OptionFilename 设置文件名

func OptionMaxBackups

func OptionMaxBackups(num int) FileOption

OptionMaxBackups 文件最大数量

func OptionMaxLength

func OptionMaxLength(length int64) FileOption

OptionMaxLength 设置最大文件大小

func OptionMoveFileType

func OptionMoveFileType(typ MoveFileType) FileOption

OptionMoveFileType 设置移动文件的类型

func OptionSeparator

func OptionSeparator(separator string) FileOption

OptionSeparator 设置打印分隔符

func OptionStdPrinters

func OptionStdPrinters(ps []string) FileOption

OptionStdPrinters 设置移动文件的类型

type FileOptions

type FileOptions struct {
	Filename string `yaml:"filename" json:"filename"`
	FileExt  string `yaml:"file_ext" json:"file_ext"`

	FileBasename string `yaml:"-" json:"-"`
	FileDir      string `yaml:"-" json:"-"`

	StdPrinters types.Strings `yaml:"std_printers" json:"std_printers"`

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

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

FileOptions file options

func (*FileOptions) Check

func (p *FileOptions) Check() error

func (*FileOptions) ParseFlags

func (p *FileOptions) ParseFlags(f *flag.FlagSet)

func (*FileOptions) ParseFlagsWithPrefix

func (p *FileOptions) ParseFlagsWithPrefix(prefix string, f *flag.FlagSet)

ParseFlagsWithPrefix adds the flags required to config this to the given FlagSet.

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 KitLogger

type KitLogger = kLog.Logger

func NewZapSugarLogger

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

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

type Level

type Level int32

Level log level

func (*Level) ToZapLevel

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

ToZapLevel convert level into zap level

type LogConfig

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

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

	ShowXormSQL bool `yaml:"show_xorm_sql" json:"show_xorm_sql"`
	// contains filtered or unexported fields
}

func (*LogConfig) ParseFlags

func (p *LogConfig) ParseFlags(f *flag.FlagSet)

func (*LogConfig) ParseFlagsWithPrefix

func (p *LogConfig) ParseFlagsWithPrefix(prefix string, f *flag.FlagSet)

ParseFlagsWithPrefix adds the flags required to config this to the given FlagSet.

func (*LogConfig) UnmarshalYAML

func (p *LogConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for LogConfig.

type Logger

type Logger interface {
	KitLogger
	XormLogger
	MessageLogger

	With(kvs ...interface{}) Logger
	Writer() io.Writer
}

Logger 日志对象

func NewWithZapLogger

func NewWithZapLogger(l *zap.Logger) Logger

func Noop

func Noop() Logger

Noop logger.

type MessageLogger

type MessageLogger interface {
	DebugM(msg string, kvs ...interface{})
	InfoM(msg string, kvs ...interface{})
	WarnM(msg string, kvs ...interface{})
	ErrorM(msg string, kvs ...interface{})
	PanicM(msg string, kvs ...interface{})
	FatalM(msg string, kvs ...interface{})
}

type MoveFileType

type MoveFileType int

MoveFileType move file type

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

MoveFileTypes

type Option

type Option func(*LogConfig)

func Caller

func Caller() Option

Caller 设置等级

func CallerSkip

func CallerSkip(cs int) Option

CallerSkip 设置等级

func EncoderConfig

func EncoderConfig(encoder zapcore.EncoderConfig) Option

EncoderConfig 设置等级

func Encoding

func Encoding(encoding string) Option

Encoding 设置移动文件的类型

func LogFileOption

func LogFileOption(opts ...FileOption) Option

LogFileOption 设置等级

func LogFileOptions

func LogFileOptions(fos *FileOptions) Option

LogFileOptions 设置等级

func LogLevel

func LogLevel(lvl Level) Option

LogLevel 设置等级

func ShowXormSQL

func ShowXormSQL(show ...bool) Option

ShowXormSQL 设置等级

func StackTrace

func StackTrace() Option

StackTrace 设置等级

type XormLogger

type XormLogger = log.Logger

type ZapLogger

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

func NewLogger

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

func NewLoggerWithConfig

func NewLoggerWithConfig(c *LogConfig) (*ZapLogger, error)

func (*ZapLogger) Debug

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

Debug 打印debug信息

func (*ZapLogger) DebugM

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

DebugM 打印debug信息

func (*ZapLogger) Debugf

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

Debugf format打印debug信息

func (*ZapLogger) Error

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

Error 打印error信息

func (*ZapLogger) ErrorM

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

ErrorM 打印error信息

func (*ZapLogger) Errorf

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

Errorf format打印error信息

func (*ZapLogger) Fatal

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

Fatal 打印panic信息

func (*ZapLogger) FatalM

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

FatalM 打印info信息

func (*ZapLogger) Fatalf

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

Fatalf format打印panic信息

func (*ZapLogger) GetZapLogger

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

func (*ZapLogger) Info

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

Info 打印Info信息

func (*ZapLogger) InfoM

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

InfoM 打印info信息

func (*ZapLogger) Infof

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

Infof format打印info信息

func (*ZapLogger) IsShowSQL

func (p *ZapLogger) IsShowSQL() bool

func (*ZapLogger) Level

func (p *ZapLogger) Level() log.LogLevel

func (*ZapLogger) Log

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

Log print log with kvs

func (*ZapLogger) Panic

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

Panic 打印panic信息

func (*ZapLogger) PanicM

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

PanicM 打印info信息

func (*ZapLogger) Panicf

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

Panicf format打印panic信息

func (*ZapLogger) SetLevel

func (p *ZapLogger) SetLevel(l log.LogLevel)

func (*ZapLogger) ShowSQL

func (p *ZapLogger) ShowSQL(show ...bool)

func (*ZapLogger) Warn

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

Warn 打印warn信息

func (*ZapLogger) WarnM

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

WarnM 打印warn信息

func (*ZapLogger) Warnf

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

Warnf format打印warn信息

func (*ZapLogger) With

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

With (fields ...Field)

func (*ZapLogger) Writer

func (p *ZapLogger) Writer() io.Writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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