ulog

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 10 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 BoolArray added in v1.0.2

type BoolArray []bool

func (BoolArray) MarshalLogArray added in v1.0.2

func (bs BoolArray) MarshalLogArray(arr zapcore.ArrayEncoder) error

type ByteStringsArray added in v1.0.2

type ByteStringsArray [][]byte

func (ByteStringsArray) MarshalLogArray added in v1.0.2

func (bss ByteStringsArray) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Complex128Array added in v1.0.2

type Complex128Array []complex128

func (Complex128Array) MarshalLogArray added in v1.0.2

func (nums Complex128Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Complex64Array added in v1.0.2

type Complex64Array []complex64

func (Complex64Array) MarshalLogArray added in v1.0.2

func (nums Complex64Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type DurationArray added in v1.0.2

type DurationArray []time.Duration

func (DurationArray) MarshalLogArray added in v1.0.2

func (ds DurationArray) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Float32Array added in v1.0.2

type Float32Array []float32

func (Float32Array) MarshalLogArray added in v1.0.2

func (nums Float32Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Float64Array added in v1.0.2

type Float64Array []float64

func (Float64Array) MarshalLogArray added in v1.0.2

func (nums Float64Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Int16Array added in v1.0.2

type Int16Array []int16

func (Int16Array) MarshalLogArray added in v1.0.2

func (nums Int16Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Int32Array added in v1.0.2

type Int32Array []int32

func (Int32Array) MarshalLogArray added in v1.0.2

func (nums Int32Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Int64Array added in v1.0.2

type Int64Array []int64

func (Int64Array) MarshalLogArray added in v1.0.2

func (nums Int64Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Int8Array added in v1.0.2

type Int8Array []int8

func (Int8Array) MarshalLogArray added in v1.0.2

func (nums Int8Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type IntArray added in v1.0.2

type IntArray []int

func (IntArray) MarshalLogArray added in v1.0.2

func (nums IntArray) MarshalLogArray(arr zapcore.ArrayEncoder) error

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 StringArray added in v1.0.2

type StringArray []string

func (StringArray) MarshalLogArray added in v1.0.2

func (ss StringArray) MarshalLogArray(arr zapcore.ArrayEncoder) error

type TimeArray added in v1.0.2

type TimeArray []time.Time

func (TimeArray) MarshalLogArray added in v1.0.2

func (ts TimeArray) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Uint16Array added in v1.0.2

type Uint16Array []uint16

func (Uint16Array) MarshalLogArray added in v1.0.2

func (nums Uint16Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Uint32Array added in v1.0.2

type Uint32Array []uint32

func (Uint32Array) MarshalLogArray added in v1.0.2

func (nums Uint32Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Uint64Array added in v1.0.2

type Uint64Array []uint64

func (Uint64Array) MarshalLogArray added in v1.0.2

func (nums Uint64Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type Uint8Array added in v1.0.2

type Uint8Array []uint8

func (Uint8Array) MarshalLogArray added in v1.0.2

func (nums Uint8Array) MarshalLogArray(arr zapcore.ArrayEncoder) error

type UintArray added in v1.0.2

type UintArray []uint

func (UintArray) MarshalLogArray added in v1.0.2

func (nums UintArray) MarshalLogArray(arr zapcore.ArrayEncoder) error

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

type Zaps added in v1.0.1

type Zaps []zap.Field

Zaps a extendable zap fields

func NewBuffedZaps added in v1.0.1

func NewBuffedZaps(n int) Zaps

func NewDefaultZaps added in v1.0.1

func NewDefaultZaps() Zaps

NewDefaultZaps default constructor

func NewHugeZaps added in v1.0.1

func NewHugeZaps() Zaps

NewHugeZaps huge size constructor

func NewMidZaps added in v1.0.1

func NewMidZaps() Zaps

NewMidZaps middle size constructor

func (*Zaps) Append added in v1.0.1

func (z *Zaps) Append(e zap.Field) *Zaps

func (*Zaps) Appends added in v1.0.1

func (z *Zaps) Appends(es ...zap.Field) *Zaps

Jump to

Keyboard shortcuts

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