qlog

package
v0.0.0-...-35fa672 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 15 Imported by: 19

README

qlog

创建日志

config := qlog.Config{
    Name: "default.log",
    Dir: "/tmp",
    Level: "info",
}
logger := config.Build()
logger.SetLevel(qlog.DebugLevel)
logger.Debug("debug", qlog.String("a", "b"))
logger.Debugf("debug %s", "a")
logger.Debugw("debug", "a", "b")

Documentation

Index

Constants

View Source
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel = zap.DebugLevel
	// InfoLevel is the default logging priority.
	InfoLevel = zap.InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel = zap.WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-Level logs.
	ErrorLevel = zap.ErrorLevel
	// PanicLevel logs a message, then panics.
	PanicLevel = zap.PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel = zap.FatalLevel
)

Variables

View Source
var (
	// String ...
	String = zap.String
	// Any ...
	Any = zap.Any
	// Int64 ...
	Int64 = zap.Int64
	// Int ...
	Int = zap.Int
	// Int32 ...
	Int32 = zap.Int32
	// Uint ...
	Uint = zap.Uint
	// Duration ...
	Duration = zap.Duration
	// Durationp ...
	Durationp = zap.Durationp
	// Object ...
	Object = zap.Object
	// Namespace ...
	Namespace = zap.Namespace
	// Reflect ...
	Reflect = zap.Reflect
	// Skip ...
	Skip = zap.Skip()
	// ByteString ...
	ByteString = zap.ByteString
)

Functions

func DPanic

func DPanic(msg string, fields ...Field)

DPanic ...

func DPanicf

func DPanicf(msg string, args ...interface{})

DPanicf ...

func DPanicw

func DPanicw(msg string, keysAndValues ...interface{})

DPanicw ...

func Debug

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

Debug ...

func DebugEncodeLevel

func DebugEncodeLevel(lv zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

DebugEncodeLevel ...

func Debugf

func Debugf(msg string, args ...interface{})

Debugf ...

func Debugw

func Debugw(msg string, keysAndValues ...interface{})

Debugw ...

func DefaultZapConfig

func DefaultZapConfig() *zapcore.EncoderConfig

DefaultZapConfig ...

func Error

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

Error ...

func Errorf

func Errorf(msg string, args ...interface{})

Errorf ...

func Errorw

func Errorw(msg string, keysAndValues ...interface{})

Errorw ...

func Fatal

func Fatal(msg string, fields ...Field)

Fatal ...

func Fatalf

func Fatalf(msg string, args ...interface{})

Fatalf ...

func Fatalw

func Fatalw(msg string, keysAndValues ...interface{})

Fatalw ...

func Flush

func Flush() error

Flush ...

func Info

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

Info ...

func Infof

func Infof(msg string, args ...interface{})

Infof ...

func Infow

func Infow(msg string, keysAndValues ...interface{})

Infow ...

func Panic

func Panic(msg string, fields ...Field)

Panic ...

func Panicf

func Panicf(msg string, args ...interface{})

Panicf ...

func Panicw

func Panicw(msg string, keysAndValues ...interface{})

Panicw ...

func SetCtxParse

func SetCtxParse(parser CtParserFunc)

SetCtxParse ...

func Warn

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

Warn ...

func Warnf

func Warnf(msg string, args ...interface{})

Warnf ...

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

Warnw ...

Types

type CloseFunc

type CloseFunc func() error

CloseFunc should be called when the caller exits to clean up buffers.

func Buffer

func Buffer(ws zapcore.WriteSyncer, bufferSize int, flushInterval time.Duration) (zapcore.WriteSyncer, CloseFunc)

Buffer wraps a WriteSyncer in a buffer to improve performance, if bufferSize = 0, we set it to defaultBufferSize if flushInterval = 0, we set it to defaultFlushInterval

type Config

type Config struct {
	// Dir 日志输出目录
	Dir string `json:"dir" toml:"dir"`
	// Name 日志文件名称
	Name string `json:"name" toml:"name"`
	// Level 日志初始等级
	Level string `json:"level" toml:"level"`
	// 日志初始化字段
	Fields []zap.Field `json:"fields" toml:"fields"`
	// 是否添加调用者信息
	AddCaller bool `json:"add_caller" toml:"addCaller"`
	// 日志前缀
	Prefix string `json:"prefix" toml:"prefix"`
	// 日志输出文件最大长度,超过改值则截断
	MaxSize   int `json:"max_size" toml:"maxSize"`
	MaxAge    int `json:"max_age" toml:"maxAge"`
	MaxBackup int `json:"max_backup" toml:"maxBackup"`
	// 日志磁盘刷盘间隔
	Interval      time.Duration          `json:"internal" toml:"internal"`
	CallerSkip    int                    `json:"caller_skip" toml:"callerSkip"`
	Async         bool                   `json:"async" toml:"async"`
	Queue         bool                   `json:"queue" toml:"queue"`
	QueueSleep    time.Duration          `json:"queue_sleep" toml:"queueSleep"`
	Core          zapcore.Core           `json:"core" toml:"core"`
	Debug         bool                   `json:"debug" toml:"debug"`
	EncoderConfig *zapcore.EncoderConfig `json:"encoder_config" toml:"encoderConfig"`
}

Config ...

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig ...

func (Config) Build

func (config Config) Build() *Logger

Build ...

func (*Config) Filename

func (config *Config) Filename() string

Filename ...

type CtParserFunc

type CtParserFunc func(context.Context) []zap.Field

Func ...

type Field

type Field = zap.Field

Func ...

func FieldAddr

func FieldAddr(value string) Field

依赖的实例名称。以mysql为例,"dsn = "root:juno@tcp(127.0.0.1:3306)/juno?charset=utf8",addr为 "127.0.0.1:3306"

func FieldAddrAny

func FieldAddrAny(value interface{}) Field

FieldAddrAny ...

func FieldAid

func FieldAid(value string) Field

应用唯一标识符

func FieldCode

func FieldCode(value int32) Field

FieldCode ...

func FieldCost

func FieldCost(value time.Duration) Field

耗时时间

func FieldErr

func FieldErr(err error) Field

FieldErr ...

func FieldErrKind

func FieldErrKind(value string) Field

FieldErrKind ...

func FieldEvent

func FieldEvent(value string) Field

FieldEvent ...

func FieldExtMessage

func FieldExtMessage(vals ...interface{}) Field

FieldExtMessage ...

func FieldKey

func FieldKey(value string) Field

FieldKey ...

func FieldKeyAny

func FieldKeyAny(value interface{}) Field

耗时时间

func FieldMethod

func FieldMethod(value string) Field

FieldMethod ...

func FieldMod

func FieldMod(value string) Field

模块

func FieldName

func FieldName(value string) Field

FieldName ...

func FieldStack

func FieldStack(value []byte) Field

FieldStack ...

func FieldStringErr

func FieldStringErr(err string) Field

FieldErr ...

func FieldType

func FieldType(value string) Field

FieldType ...

func FieldValue

func FieldValue(value string) Field

FieldValue ...

func FieldValueAny

func FieldValueAny(value interface{}) Field

FieldValueAny ...

type Func

type Func func(string, ...zap.Field)

Func ...

func Auto

func Auto(err error) Func

Auto ...

func (Func) Log

func (fn Func) Log(msg string, fields ...Field)

Log ...

type Level

type Level = zapcore.Level

Func ...

type Logger

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

Func ...

func Ctx

func Ctx(ctx context.Context) *Logger

Context ...

func SetCfg

func SetCfg(cfg *Config) *Logger

func With

func With(fields ...Field) *Logger

With ...

func (*Logger) Ctx

func (logger *Logger) Ctx(ctx context.Context) *Logger

Ctx ...

func (*Logger) DPanic

func (logger *Logger) DPanic(msg string, fields ...Field)

DPanic ...

func (*Logger) DPanicf

func (logger *Logger) DPanicf(template string, args ...interface{})

DPanicf ...

func (*Logger) DPanicw

func (logger *Logger) DPanicw(msg string, keysAndValues ...interface{})

DPanicw ...

func (*Logger) Debug

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

Debug ...

func (*Logger) Debugf

func (logger *Logger) Debugf(template string, args ...interface{})

Debugf ...

func (*Logger) Debugw

func (logger *Logger) Debugw(msg string, keysAndValues ...interface{})

Debugw ...

func (*Logger) Error

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

Error ...

func (*Logger) Errorf

func (logger *Logger) Errorf(template string, args ...interface{})

Errorf ...

func (*Logger) Errorw

func (logger *Logger) Errorw(msg string, keysAndValues ...interface{})

Errorw ...

func (*Logger) Fatal

func (logger *Logger) Fatal(msg string, fields ...Field)

Fatal ...

func (*Logger) Fatalf

func (logger *Logger) Fatalf(template string, args ...interface{})

Fatalf ...

func (*Logger) Fatalw

func (logger *Logger) Fatalw(msg string, keysAndValues ...interface{})

Fatalw ...

func (*Logger) Flush

func (logger *Logger) Flush() error

Flush ...

func (*Logger) Info

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

Info ...

func (*Logger) Infof

func (logger *Logger) Infof(template string, args ...interface{})

Infof ...

func (*Logger) Infow

func (logger *Logger) Infow(msg string, keysAndValues ...interface{})

Infow ...

func (*Logger) IsDebugMode

func (logger *Logger) IsDebugMode() bool

IsDebugMode ...

func (*Logger) Panic

func (logger *Logger) Panic(msg string, fields ...Field)

Panic ...

func (*Logger) Panicf

func (logger *Logger) Panicf(template string, args ...interface{})

Panicf ...

func (*Logger) Panicw

func (logger *Logger) Panicw(msg string, keysAndValues ...interface{})

Panicw ...

func (*Logger) SetCtxParse

func (logger *Logger) SetCtxParse(parser CtParserFunc)

SetCtxParse ...

func (*Logger) SetLevel

func (logger *Logger) SetLevel(lv Level)

SetLevel ...

func (*Logger) StdLog

func (logger *Logger) StdLog() *log.Logger

StdLog ...

func (*Logger) Warn

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

Warn ...

func (*Logger) Warnf

func (logger *Logger) Warnf(template string, args ...interface{})

Warnf ...

func (*Logger) Warnw

func (logger *Logger) Warnw(msg string, keysAndValues ...interface{})

Warnw ...

func (*Logger) With

func (logger *Logger) With(fields ...Field) *Logger

With ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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