xlog

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

README

xlog

xlog wrapped go.uber.org/zap, simplify the difficulty of use.

动态设置日志级别

修改默认日志级别:

[jupiter.logger.default]
    level = "error"

修改自定义日志界别:

[jupiter.logger.mylog]
    level = "error"

创建自定义日志

logger := xlog.StdConfig("mylog").Build()
logger.Info("info", xlog.String("a", "b"))
logger.Infof("info %s", "a")
logger.Infow("info", "a", "b")

也可以更精确的控制:

config := xlog.Config{
    Name: "default.log",
    Dir: "/tmp",
    Level: "info",
}
logger := config.Build()
logger.SetLevel(xlog.DebugLevel)
logger.Debug("debug", xlog.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
)
View Source
var DefaultLogger = Config{
	Debug: true,
	Async: true,
}.Build()

DefaultLogger default logger Biz Log debug=true as default, will be

View Source
var JupiterLogger = Config{
	Debug: true,
}.Build()

frame logger

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 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 InjectTraceMD

func InjectTraceMD(ctx interface{ Set(string, interface{}) }, md *Tracer)

InjectTraceMD ...

func NewContext

func NewContext(ctx context.Context, tracer Tracer) context.Context

NewContext ...

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 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
	// Name 日志文件名称
	Name string
	// Level 日志初始等级
	Level string
	// 日志初始化字段
	Fields []zap.Field
	// 是否添加调用者信息
	AddCaller bool
	// 日志前缀
	Prefix string
	// 日志输出文件最大长度,超过改值则截断
	MaxSize   int
	MaxAge    int
	MaxBackup int
	// 日志磁盘刷盘间隔
	Interval      time.Duration
	CallerSkip    int
	Async         bool
	Queue         bool
	QueueSleep    time.Duration
	Core          zapcore.Core
	Debug         bool
	EncoderConfig *zapcore.EncoderConfig
	// contains filtered or unexported fields
}

Config ...

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig ...

func RawConfig

func RawConfig(key string) *Config

RawConfig ...

func StdConfig

func StdConfig(name string) *Config

StdConfig Jupiter Standard logger config

func (Config) Build

func (config Config) Build() *Logger

Build ...

func (*Config) Filename

func (config *Config) Filename() string

Filename ...

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 With

func With(fields ...Field) *Logger

With ...

func (*Logger) AutoLevel

func (logger *Logger) AutoLevel(confKey string)

AutoLevel ...

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) 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 ...

type Tracer

type Tracer struct {
	BeginTime time.Time
	// contains filtered or unexported fields
}

Tracer ...

func ExtractTraceMD

func ExtractTraceMD(ctx interface{ Get(string) interface{} }) (md *Tracer, ok bool)

ExtractTraceMD ...

func NewTracer

func NewTracer() *Tracer

NewTracer ...

func (*Tracer) Error

func (t *Tracer) Error(fields ...Field)

Error ...

func (*Tracer) Flush

func (t *Tracer) Flush(msg string, logger *Logger)

Flush ...

func (*Tracer) Info

func (t *Tracer) Info(fields ...Field)

Info ...

func (*Tracer) Warn

func (t *Tracer) Warn(fields ...Field)

Warn ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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