xlog

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 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
)
View Source
var ConfigPrefix = constant.ConfigPrefix + ".logger"

Functions

func ConfigEntry added in v0.3.1

func ConfigEntry(name string) string

func DebugEncodeLevel

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

DebugEncodeLevel ...

func Default added in v0.5.0

func Default() *zap.Logger

Default returns default logger

func DefaultZapConfig

func DefaultZapConfig() *zapcore.EncoderConfig

DefaultZapConfig ...

func GetTraceID added in v0.4.3

func GetTraceID(ctx context.Context) string

func Jupiter added in v0.5.0

func Jupiter() *zap.Logger

Jupiter returns framework logger

func NewContext

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

func SetTraceID added in v0.4.3

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

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

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

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

func FieldStringErr(err string) Field

FieldErr ...

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 FromContext added in v0.4.3

func FromContext(ctx context.Context) *Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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