xlog

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: Apache-2.0 Imports: 17 Imported by: 109

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

This section is empty.

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 logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.

func Debug

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

Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func DebugEncodeLevel

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

DebugEncodeLevel ...

func DefaultZapConfig

func DefaultZapConfig() *zapcore.EncoderConfig

DefaultZapConfig ...

func Error

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

Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func Fatal

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

Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func GetTraceID added in v0.4.3

func GetTraceID(ctx context.Context) string

func Info

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

Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func NewContext

func NewContext(ctx context.Context, l *Logger) context.Context

func Panic

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

Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then panics, even if logging at PanicLevel is disabled.

func SetDefault added in v0.6.1

func SetDefault(logger *Logger)

func SetJupiter added in v0.6.1

func SetJupiter(logger *Logger)

func SetTraceID added in v0.4.3

func SetTraceID(ctx context.Context, traceID string) context.Context

func Warn

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

Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

Types

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 for application.

func RawConfig

func RawConfig(key string) *Config

RawConfig ...

func StdConfig

func StdConfig(prefix, 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 added in v0.2.0

func FieldCode(value int32) Field

FieldCode ...

func FieldColor added in v0.6.1

func FieldColor(value string) Field

FieldColor ...

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 FieldHost added in v0.6.1

func FieldHost(value string) Field

FieldHost ...

func FieldIP added in v0.6.1

func FieldIP(value string) Field

FieldIP ...

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 FieldReqAID added in v0.6.1

func FieldReqAID(value string) Field

FieldReqAID ...

func FieldReqHost added in v0.6.1

func FieldReqHost(value string) Field

FieldReqHost ...

func FieldStack

func FieldStack(value []byte) Field

FieldStack ...

func FieldStdMethod added in v0.6.1

func FieldStdMethod(value string) Field

FieldStdMethod ...

func FieldStringErr added in v0.2.0

func FieldStringErr(err string) Field

FieldErr ...

func FieldTID added in v0.6.1

func FieldTID(value string) Field

FieldTID ...

func FieldType added in v0.2.0

func FieldType(value string) Field

FieldType ...

func FieldValue

func FieldValue(value string) Field

FieldValue ...

func FieldValueAny

func FieldValueAny(value interface{}) Field

FieldValueAny ...

type Level

type Level = zapcore.Level

Func ...

type Logger

type Logger = zap.Logger

Func ...

func Default added in v0.5.0

func Default() *Logger

Default returns default logger

func FromContext added in v0.4.3

func FromContext(ctx context.Context) *Logger

func Jupiter added in v0.5.0

func Jupiter() *Logger

Jupiter returns framework logger

func L added in v0.6.2

func L(ctx context.Context) *Logger

L returns the standard logger.

func Named added in v0.6.1

func Named(s string) *Logger

Named adds a new path segment to the logger's name. Segments are joined by periods. By default, Loggers are unnamed.

func With

func With(fields ...Field) *Logger

With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.

func WithOptions added in v0.6.1

func WithOptions(opts ...Option) *Logger

WithOptions clones the current Logger, applies the supplied Options, and returns the resulting Logger. It's safe to use concurrently.

type Option added in v0.6.1

type Option = zap.Option

Func ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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