elog

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2021 License: MIT Imports: 16 Imported by: 169

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
)
View Source
const (
	// DefaultLoggerName 业务日志名
	DefaultLoggerName = "default.log"
	// EgoLoggerName 系统文件名
	EgoLoggerName = "ego.sys"
)
View Source
const PackageName = "core.elog"

PackageName 包名

Variables

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

Functions

func DPanic

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

DPanic ...

func DPanicf deprecated

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

Deprecated: Will be removed in future versions, use DPanic instead. DPanicf ...

func DPanicw deprecated

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

Deprecated: Will be removed in future versions, use DPanic instead. DPanicw ...

func Debug

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

Debug ...

func Debugf deprecated

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

Deprecated: Will be removed in future versions, use Debug instead. Debugf ...

func Debugw deprecated

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

Deprecated: Will be removed in future versions, use Debug instead. Debugw ...

func Error

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

Error ...

func Errorf deprecated

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

Deprecated: Will be removed in future versions, use Error instead. Errorf ...

func Errorw deprecated

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

Deprecated: Will be removed in future versions, use Error instead. Errorw ...

func Fatal

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

Fatal ...

func Fatalf deprecated

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

Deprecated: Will be removed in future versions, use Fatal instead. Fatalf ...

func Fatalw deprecated

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

Deprecated: Will be removed in future versions, use Fatal instead. Fatalw ...

func Info

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

Info ...

func Infof deprecated

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

Deprecated: Will be removed in future versions, use Info instead. Infof ...

func Infow deprecated

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

Deprecated: Will be removed in future versions, use Info instead. Infow ...

func Panic

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

Panic ...

func Panicf deprecated

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

Deprecated: Will be removed in future versions, use Panic instead. Panicf ...

func Panicw deprecated

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

Deprecated: Will be removed in future versions, use Panic instead. Panicw ...

func Register added in v0.6.0

func Register(builder WriterBuilder)

Register registers a dataSource creator function to the registry

func Warn

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

Warn ...

func Warnf deprecated

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

Deprecated: Will be removed in future versions, use Warn instead. Warnf ...

func Warnw deprecated

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

Deprecated: Will be removed in future versions, use Warn instead. Warnw ...

Types

type CloseFunc

type CloseFunc func() error

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

func (CloseFunc) Close added in v0.6.0

func (c CloseFunc) Close() error

Close 关闭

type Component

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

Component 组件

var DefaultLogger *Component

DefaultLogger defines default logger, it's usually used in application business logic

var EgoLogger *Component

EgoLogger defines ego framework logger, it's for ego framework only

func With

func With(fields ...Field) *Component

With ...

func (*Component) AutoLevel

func (logger *Component) AutoLevel(confKey string)

AutoLevel ...

func (*Component) ConfigDir added in v0.6.0

func (logger *Component) ConfigDir() string

ConfigDir 获取日志路径

func (*Component) ConfigName added in v0.6.0

func (logger *Component) ConfigName() string

ConfigName 获取日志名称

func (*Component) DPanic

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

DPanic ...

func (*Component) DPanicf deprecated

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

Deprecated: Will be removed in future versions, use *Component.DPanic instead. DPanicf ...

func (*Component) DPanicw deprecated

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

Deprecated: Will be removed in future versions, use *Component.DPanic instead. DPanicw ...

func (*Component) Debug

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

Debug ...

func (*Component) Debugf deprecated

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

Deprecated: Will be removed in future versions, use *Component.Debug instead. Debugf ...

func (*Component) Debugw deprecated

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

Deprecated: Will be removed in future versions, use *Component.Debug instead. Debugw ...

func (*Component) Error

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

Error ...

func (*Component) Errorf deprecated

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

Deprecated: Will be removed in future versions, use *Component.Error instead. Errorf ...

func (*Component) Errorw deprecated

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

Deprecated: Will be removed in future versions, use *Component.Error instead. Errorw ...

func (*Component) Fatal

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

Fatal ...

func (*Component) Fatalf deprecated

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

Deprecated: Will be removed in future versions, use *Component.Fatal instead. Fatalf ...

func (*Component) Fatalw deprecated

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

Deprecated: Will be removed in future versions, use *Component.Fatal instead. Fatalw ...

func (*Component) Flush

func (logger *Component) Flush() error

Flush ... When use os.Stdout or os.Stderr as zapcore.WriteSyncer logger.desugar.Sync() maybe return an error like this: 'sync /dev/stdout: The handle is invalid.' Because os.Stdout and os.Stderr is a non-normal file, maybe not support 'fsync' in different os platform So ignored Sync() return value About issues: https://github.com/uber-go/zap/issues/328 About 'fsync': https://man7.org/linux/man-pages/man2/fsync.2.html

func (*Component) Info

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

Info ...

func (*Component) Infof deprecated

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

Deprecated: Will be removed in future versions, use *Component.Info instead. Infof ...

func (*Component) Infow deprecated

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

Deprecated: Will be removed in future versions, use *Component.Info instead. Infow ...

func (*Component) IsDebugMode

func (logger *Component) IsDebugMode() bool

IsDebugMode ...

func (*Component) Panic

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

Panic ...

func (*Component) Panicf deprecated

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

Deprecated: Will be removed in future versions, use *Component.Panic instead. Panicf ...

func (*Component) Panicw deprecated

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

Deprecated: Will be removed in future versions, use *Component.Panic instead. Panicw ...

func (*Component) SetLevel

func (logger *Component) SetLevel(lv Level)

SetLevel ...

func (*Component) Warn

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

Warn ...

func (*Component) Warnf deprecated

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

Deprecated: Will be removed in future versions, use *Component.Warn instead. Warnf ...

func (*Component) Warnw deprecated

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

Deprecated: Will be removed in future versions, use *Component.Warn instead. Warnw ...

func (*Component) With

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

With creates a child logger

func (*Component) WithCallerSkip added in v0.5.5

func (logger *Component) WithCallerSkip(callerSkip int, fields ...Field) *Component

WithCallerSkip ...

func (*Component) ZapLogger added in v0.7.0

func (logger *Component) ZapLogger() *zap.Logger

ZapLogger returns *zap.Logger

func (*Component) ZapSugaredLogger added in v0.7.0

func (logger *Component) ZapSugaredLogger() *zap.SugaredLogger

ZapSugaredLogger returns *zap.SugaredLogger

type Config

type Config struct {
	Debug           bool   // 是否双写至文件控制日志输出到终端
	Level           string // 日志初始等级,默认info级别
	Dir             string // [fileWriter]日志输出目录,默认logs
	Name            string // [fileWriter]日志文件名称,默认框架日志ego.sys,业务日志default.log
	EnableAddCaller bool   // 是否添加调用者信息,默认不加调用者信息
	EnableAsync     bool   // 是否异步,默认异步
	Writer          string // 使用哪种Writer,可选[file|ali|stderr],默认file

	CallerSkip int
	// contains filtered or unexported fields
}

Config ...

func (*Config) AtomicLevel added in v0.6.0

func (c *Config) AtomicLevel() zap.AtomicLevel

AtomicLevel 获取AtomicLevel配置

func (*Config) EncoderConfig

func (c *Config) EncoderConfig() *zapcore.EncoderConfig

EncoderConfig 获取zap encoder配置

func (*Config) Filename

func (c *Config) Filename() string

Filename ...

type Container

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

Container 容器

func DefaultContainer

func DefaultContainer() *Container

DefaultContainer 默认容器

func Load

func Load(key string) *Container

Load 加载配置key

func (*Container) Build

func (c *Container) Build(options ...Option) *Component

Build 构建组件

type Field

type Field = zap.Field

Field ...

func FieldAddr

func FieldAddr(value string) Field

FieldAddr 设置地址

func FieldApp added in v0.3.4

func FieldApp(value string) Field

FieldApp 设置应用名

func FieldCode

func FieldCode(value int32) Field

FieldCode ...

func FieldComponent

func FieldComponent(value string) Field

FieldComponent 设置组件

func FieldComponentName

func FieldComponentName(value string) Field

FieldComponentName 设置组件配置名

func FieldCost

func FieldCost(value time.Duration) Field

FieldCost 耗时时间

func FieldCtxTid added in v0.5.5

func FieldCtxTid(ctx context.Context) Field

FieldCtxTid 设置链路id

func FieldCustomKeyValue added in v0.5.7

func FieldCustomKeyValue(key string, value string) Field

FieldCustomKeyValue 设置自定义日志

func FieldDescription added in v0.3.4

func FieldDescription(value string) Field

FieldDescription ...

func FieldErr

func FieldErr(err error) Field

FieldErr ...

func FieldErrAny added in v0.3.11

func FieldErrAny(err interface{}) Field

FieldErrAny ...

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

func FieldIP(value string) Field

FieldIP ...

func FieldKey

func FieldKey(value string) Field

FieldKey ...

func FieldKind added in v0.3.4

func FieldKind(value string) Field

FieldKind ... level 2

func FieldMethod

func FieldMethod(value string) Field

FieldMethod ...

func FieldName

func FieldName(value string) Field

FieldName ...

func FieldPeerIP added in v0.3.4

func FieldPeerIP(value string) Field

FieldPeerIP ...

func FieldPeerName added in v0.3.4

func FieldPeerName(value string) Field

FieldPeerName ...

func FieldSize added in v0.3.4

func FieldSize(value int32) Field

FieldSize ...

func FieldStack

func FieldStack(value []byte) Field

FieldStack ...

func FieldTid added in v0.3.6

func FieldTid(value string) Field

FieldTid 设置链路id

func FieldType

func FieldType(value string) Field

FieldType ... level 1

func FieldUniformCode added in v0.6.12

func FieldUniformCode(value int32) Field

FieldUniformCode uniform code

func FieldValue

func FieldValue(value string) Field

FieldValue ...

func FieldValueAny

func FieldValueAny(value interface{}) Field

FieldValueAny ...

type Level

type Level = zapcore.Level

Level ...

type Option

type Option func(c *Container)

Option 可选项

func WithDebug added in v0.3.9

func WithDebug(debug bool) Option

WithDebug 设置在命令行显示

func WithEnableAddCaller added in v0.3.11

func WithEnableAddCaller(enableAddCaller bool) Option

WithEnableAddCaller 是否添加行号,默认不添加行号

func WithEnableAsync added in v0.3.9

func WithEnableAsync(enableAsync bool) Option

WithEnableAsync 是否异步执行,默认异步

func WithFileName

func WithFileName(name string) Option

WithFileName 设置文件名

func WithLevel added in v0.3.9

func WithLevel(level string) Option

WithLevel 设置级别

func WithZapCore added in v0.6.0

func WithZapCore(core zapcore.Core) Option

WithZapCore 添加ZapCore

type Writer added in v0.6.0

type Writer interface {
	zapcore.Core
	io.Closer
}

Writer 日志interface

type WriterBuilder added in v0.6.0

type WriterBuilder interface {
	// Build(key string, commonConfig *Config, lv zap.AtomicLevel) (zapcore.Core, CloseFunc)
	Build(key string, commonConfig *Config) Writer
	Scheme() string
}

WriterBuilder 根据key初始化writer

func Provider added in v0.6.0

func Provider(scheme string) WriterBuilder

Provider 根据配置地址,创建数据源

Jump to

Keyboard shortcuts

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