ulog

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 9 Imported by: 2

README

ulog

采用uber的log,并做了一些封装。 支持打印到终端与打印到文件,如果在k8s中有比较成熟的捕捉终端打印到日志的方案, 使用打印日志到终端就足够了。

Documentation

Index

Constants

View Source
const (
	//level string
	DebugLevelStr = "debug"
	InfoLevelStr  = "info"
	WarnLevelStr  = "warn"
	ErrorLevelStr = "error"

	//level define
	DebugLevel = zap.DebugLevel
	InfoLevel  = zap.InfoLevel
	WarnLevel  = zap.WarnLevel
	ErrorLevel = zap.ErrorLevel
)

Variables

View Source
var (
	//ErrZapEmpty empty zap logger
	ErrZapEmpty = errors.New("zap.pointer.empty")
)

Functions

func Debug

func Debug(msg string, fields ...zap.Field)

Debug : log debug

func Error

func Error(msg string, fields ...zap.Field)

Error : log error

func GetLevel

func GetLevel() zapcore.Level

GetLevel : get log level

func GetLevelStr

func GetLevelStr() string

GetLevelStr : get log level str

func Info

func Info(msg string, fields ...zap.Field)

Info : log info

func Level2String

func Level2String(level zapcore.Level) string

Level2String extract zap level

func ParseLevel

func ParseLevel(level string) zapcore.Level

ParseLevel parse zap level

func SetDefaultLogger

func SetDefaultLogger(logger *Logger)

SetDefaultLogger : set default logger

func SetLogLevel

func SetLogLevel(level zapcore.Level)

SetLogLevel : set log level

func SetLogLevelStr

func SetLogLevelStr(levelStr string)

SetLogLevelStr : set log level by string

func Warn

func Warn(msg string, fields ...zap.Field)

Warn : log warn

Types

type Logger

type Logger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

Logger 封装可以动态设置log level的logger

func GetDefaultLogger

func GetDefaultLogger() *Logger

GetDefaultLogger : get default logger

func NewFileLogger

func NewFileLogger(cnf ZapConf) *Logger

NewFileLogger new zap logger

func NewSimpleLogger

func NewSimpleLogger(level string, options ...zap.Option) *Logger

NewSimpleLogger new zap logger without file log

func (*Logger) Debug

func (z *Logger) Debug(msg string, fields ...zap.Field)

func (*Logger) Error

func (z *Logger) Error(msg string, fields ...zap.Field)

func (*Logger) Info

func (z *Logger) Info(msg string, fields ...zap.Field)

func (*Logger) Level

func (z *Logger) Level() zapcore.Level

Level get level

func (*Logger) LevelStr

func (z *Logger) LevelStr() string

LevelStr get level str

func (*Logger) SetLevel

func (z *Logger) SetLevel(level zapcore.Level)

SetLevel set level

func (*Logger) SetLevelStr

func (z *Logger) SetLevelStr(sLevel string)

SetLevelStr set level string

func (*Logger) Sync

func (z *Logger) Sync() error

func (*Logger) Warn

func (z *Logger) Warn(msg string, fields ...zap.Field)

type ZapConf

type ZapConf struct {
	//文件名
	FileName string `json:"fileName" toml:"fileName"`
	//文件最大长度 (M bytes)
	MaxSize int `json:"maxSize" toml:"maxSize"`
	//文件最久天数
	MaxAge int `json:"maxAge" toml:"maxAge"`
	//最大备份文件数量
	MaxBackups int `json:"maxBackups" toml:"maxBackups"`

	//是否在备份文件格式中使用utc time,否则为local time
	UTCTime bool `json:"utcTime" toml:"utcTime"`
	//是否压缩旧的文件
	Compress bool `json:"compress" toml:"compress"`
	//Disable log caller
	DisableCaller bool `json:"disableCaller" toml:"disableCaller"`

	//log level
	LogLevel string `json:"logLevel" toml:"logLevel"`
}

ZapConf zap configuration

func (ZapConf) String

func (c ZapConf) String() string

zap conf string

Jump to

Keyboard shortcuts

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