logger

package
v0.0.0-...-b124b1e Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommFieldLogId   = "logid"
	CommFieldSubMod  = "submod"
	CommFieldPid     = "pid"
	CommFieldCall    = "call"
	DefaultCallDepth = 4
)

Reserve base key

Variables

This section is empty.

Functions

func InitMLog

func InitMLog(cfgFile, logDir string)

Types

type LogConf

type LogConf struct {
	Module   string `yaml:"module,omitempty"`
	Filename string `yaml:"filename,omitempty"`
	// 日志格式:logfmt、json
	Fmt string `yaml:"fmt,omitempty"`
	// 日志输出级别:debug、trace、info、warn、error
	Level string `yaml:"level,omitempty"`
	// 日志分割周期(单位:分钟)
	RotateInterval int `yaml:"rotateInterval,omitempty"`
	// 日志保留天数(单位:小时)
	RotateBackups int `yaml:"rotateBackups,omitempty"`
	// 是否输出到标准输出
	Console bool `yaml:"console,omitempty"`
	// 设置日志模式是否是异步
	Async bool `yaml:"async,omitempty"`
	// 设置异步模式下缓冲区大小
	BufSize int `yaml:"bufSize,omitempty"`
}

LogConfig is the log envconfig of node

func GetDefLogConf

func GetDefLogConf() *LogConf

func LoadLogConf

func LoadLogConf(cfgFile string) (*LogConf, error)

type LogDriver

type LogDriver interface {
	Fatal(msg string, ctx ...interface{})
	Error(msg string, ctx ...interface{})
	Warn(msg string, ctx ...interface{})
	Info(msg string, ctx ...interface{})
	Debug(msg string, ctx ...interface{})
}

LogDriver 底层日志库约束接口

func OpenMLog

func OpenMLog(lc *LogConf, logDir string) (LogDriver, error)

OpenMLog create and open log stream using LogConfig

type Logger

type Logger interface {
	GetLogId() string
	SetCommField(key string, value interface{})
	SetInfoField(key string, value interface{})
	Fatal(msg string, ctx ...interface{})
	Error(msg string, ctx ...interface{})
	Warn(msg string, ctx ...interface{})
	Info(msg string, ctx ...interface{})
	Debug(msg string, ctx ...interface{})
}

type LoggerImpl

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

func NewLogger

func NewLogger(logId, subMod string) (*LoggerImpl, error)

NewLogger 使用NewLogger请先调用InitMLog全局初始化

func (*LoggerImpl) Debug

func (t *LoggerImpl) Debug(msg string, ctx ...interface{})

func (*LoggerImpl) Error

func (t *LoggerImpl) Error(msg string, ctx ...interface{})

func (*LoggerImpl) Fatal

func (t *LoggerImpl) Fatal(msg string, ctx ...interface{})

func (*LoggerImpl) GetLogId

func (t *LoggerImpl) GetLogId() string

func (*LoggerImpl) Info

func (t *LoggerImpl) Info(msg string, ctx ...interface{})

func (*LoggerImpl) SetCommField

func (t *LoggerImpl) SetCommField(key string, value interface{})

func (*LoggerImpl) SetInfoField

func (t *LoggerImpl) SetInfoField(key string, value interface{})

func (*LoggerImpl) Warn

func (t *LoggerImpl) Warn(msg string, ctx ...interface{})

type Lvl

type Lvl int

Lvl is a type for predefined log levels.

const (
	LvlFatal Lvl = iota
	LvlError
	LvlWarn
	LvlInfo
	LvlDebug
)

List of predefined log Levels

func LvlFromString

func LvlFromString(lvlString string) Lvl

LvlFromString returns the appropriate Lvl from a string name. Useful for parsing command line args and configuration files.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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