xlog

package
v0.0.0-...-a89d410 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

README

xlog

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

动态设置日志级别

修改默认日志级别:

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

修改自定义日志界别:

[sanchin.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 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, traceID string) 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

func SetDefault(logger *Logger)

func SetSanchin

func SetSanchin(logger *Logger)

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 Sanchin 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:yiqi@tcp(127.0.0.1:3306)/yiqi?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 FieldColor

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

func FieldHost(value string) Field

FieldHost ...

func FieldIP

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

func FieldReqAID(value string) Field

FieldReqAID ...

func FieldReqHost

func FieldReqHost(value string) Field

FieldReqHost ...

func FieldStack

func FieldStack(value []byte) Field

FieldStack ...

func FieldStdMethod

func FieldStdMethod(value string) Field

FieldStdMethod ...

func FieldStringErr

func FieldStringErr(err string) Field

FieldErr ...

func FieldTID

func FieldTID(value string) Field

FieldTID ...

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 Level

type Level = zapcore.Level

Func ...

type Logger

type Logger = zap.Logger

Func ...

func Default

func Default() *Logger

Default returns default logger

func FromContext deprecated

func FromContext(ctx context.Context) *Logger

Deprecated: use xlog.L instead

func J

func J(ctx context.Context) *Logger

J returns the sanchin logger.

func L

func L(ctx context.Context) *Logger

L returns the standard logger.

func Named

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 Sanchin

func Sanchin() *Logger

Sanchin returns framework logger

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

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

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