log

package
v0.3.37 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 15 Imported by: 14

Documentation

Index

Constants

View Source
const (
	ConsoleEncoder string = "console"
	JsonEncoder    string = "json"
	ObjEncoder     string = "obj"
)

Variables

View Source
var DefaultJsonConfig = zapcore.EncoderConfig{
	LevelKey:       "level",
	NameKey:        "logger",
	CallerKey:      "caller",
	MessageKey:     "msg",
	StacktraceKey:  "stacktrace",
	LineEnding:     zapcore.DefaultLineEnding,
	EncodeLevel:    zapcore.CapitalLevelEncoder,
	EncodeTime:     nil,
	EncodeDuration: zapcore.SecondsDurationEncoder,
	EncodeCaller:   zapcore.ShortCallerEncoder,
}
View Source
var DefaultJsonConfigWithTime = zapcore.EncoderConfig{
	TimeKey:        "time",
	LevelKey:       "level",
	NameKey:        "logger",
	CallerKey:      "caller",
	MessageKey:     "msg",
	StacktraceKey:  "stacktrace",
	LineEnding:     zapcore.DefaultLineEnding,
	EncodeLevel:    zapcore.CapitalLevelEncoder,
	EncodeTime:     TimeEncoder,
	EncodeDuration: zapcore.SecondsDurationEncoder,
	EncodeCaller:   zapcore.ShortCallerEncoder,
}

Functions

func AddHook

func AddHook(hook Hook)

func Close

func Close()

func Debug

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

func Debugf

func Debugf(args ...interface{})

func DefaultConsoleConfig added in v0.2.33

func DefaultConsoleConfig(title string) *zapcore.EncoderConfig

func Error

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

func Errorf

func Errorf(args ...interface{})

func Fatal

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

func Fatalf

func Fatalf(args ...interface{})

func Info

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

func Infof

func Infof(args ...interface{})

func Init

func Init(dev bool, conf *LogConfig, hooks ...Hook)

func InitDefault

func InitDefault(dev bool, console bool, title string, hooks ...Hook)

func IsConsole added in v0.1.7

func IsConsole() bool

func NewEncoderConfig added in v0.2.33

func NewEncoderConfig(title string, console bool) *zapcore.EncoderConfig

func Panic

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

func Panicf

func Panicf(args ...interface{})

func PrettyStruct

func PrettyStruct(s interface{}) string

func RemoveHook

func RemoveHook(hook Hook)

func SetDefaultLogger

func SetDefaultLogger(logger *ComposeLogger)

func Sync

func Sync() error

func TimeEncoder

func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

func Warn

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

func Warnf

func Warnf(args ...interface{})

Types

type ComposeEncoder

type ComposeEncoder struct {
	zapcore.ObjectEncoder
	Fields map[string]interface{}
	// contains filtered or unexported fields
}

func NewComposeEncoder

func NewComposeEncoder(cfg *zapcore.EncoderConfig, enableJson, enableObj bool) *ComposeEncoder

func (ComposeEncoder) AddArray

func (this ComposeEncoder) AddArray(k string, v zapcore.ArrayMarshaler) error

func (ComposeEncoder) AddBinary

func (this ComposeEncoder) AddBinary(k string, v []byte)

AddBinary implements composeEnc.

func (ComposeEncoder) AddBool

func (this ComposeEncoder) AddBool(k string, v bool)

AddBool implements composeEnc.

func (ComposeEncoder) AddByteString

func (this ComposeEncoder) AddByteString(k string, v []byte)

AddByteString implements composeEnc.

func (ComposeEncoder) AddComplex128

func (this ComposeEncoder) AddComplex128(k string, v complex128)

AddComplex128 implements composeEnc.

func (ComposeEncoder) AddComplex64

func (this ComposeEncoder) AddComplex64(k string, v complex64)

AddComplex64 implements composeEnc.

func (ComposeEncoder) AddDuration

func (this ComposeEncoder) AddDuration(k string, v time.Duration)

AddDuration implements composeEnc.

func (ComposeEncoder) AddFloat32

func (this ComposeEncoder) AddFloat32(k string, v float32)

AddFloat32 implements composeEnc.

func (ComposeEncoder) AddFloat64

func (this ComposeEncoder) AddFloat64(k string, v float64)

AddFloat64 implements composeEnc.

func (ComposeEncoder) AddInt

func (this ComposeEncoder) AddInt(k string, v int)

AddInt implements composeEnc.

func (ComposeEncoder) AddInt16

func (this ComposeEncoder) AddInt16(k string, v int16)

AddInt16 implements composeEnc.

func (ComposeEncoder) AddInt32

func (this ComposeEncoder) AddInt32(k string, v int32)

AddInt32 implements composeEnc.

func (ComposeEncoder) AddInt64

func (this ComposeEncoder) AddInt64(k string, v int64)

AddInt64 implements composeEnc.

func (ComposeEncoder) AddInt8

func (this ComposeEncoder) AddInt8(k string, v int8)

AddInt8 implements composeEnc.

func (ComposeEncoder) AddObject

func (this ComposeEncoder) AddObject(k string, v zapcore.ObjectMarshaler) error

AddObject implements composeEnc.

func (ComposeEncoder) AddReflected

func (this ComposeEncoder) AddReflected(k string, v interface{}) error

AddReflected implements composeEnc.

func (ComposeEncoder) AddString

func (this ComposeEncoder) AddString(k string, v string)

AddString implements composeEnc.

func (ComposeEncoder) AddTime

func (this ComposeEncoder) AddTime(k string, v time.Time)

AddTime implements composeEnc.

func (ComposeEncoder) AddUint

func (this ComposeEncoder) AddUint(k string, v uint)

AddUint implements composeEnc.

func (ComposeEncoder) AddUint16

func (this ComposeEncoder) AddUint16(k string, v uint16)

AddUint16 implements composeEnc.

func (ComposeEncoder) AddUint32

func (this ComposeEncoder) AddUint32(k string, v uint32)

AddUint32 implements composeEnc.

func (ComposeEncoder) AddUint64

func (this ComposeEncoder) AddUint64(k string, v uint64)

AddUint64 implements composeEnc.

func (ComposeEncoder) AddUint8

func (this ComposeEncoder) AddUint8(k string, v uint8)

AddUint8 implements composeEnc.

func (ComposeEncoder) AddUintptr

func (this ComposeEncoder) AddUintptr(k string, v uintptr)

AddUintptr implements composeEnc.

func (ComposeEncoder) Clone

func (this ComposeEncoder) Clone() *ComposeEncoder

func (ComposeEncoder) EncodeEntry

func (this ComposeEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

func (ComposeEncoder) OpenNamespace

func (this ComposeEncoder) OpenNamespace(k string)

OpenNamespace implements composeEnc.

type ComposeLogger

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

func DefaultLogger

func DefaultLogger() *ComposeLogger

func NewComposeLogger

func NewComposeLogger(dev bool, conf *LogConfig, skip int, hooks ...Hook) *ComposeLogger

func WithField

func WithField(key string, value interface{}) *ComposeLogger

func WithFields

func WithFields(fields Fields) *ComposeLogger

func (*ComposeLogger) AddHook

func (this *ComposeLogger) AddHook(hook Hook)

func (*ComposeLogger) Clear added in v0.1.24

func (this *ComposeLogger) Clear()

func (*ComposeLogger) Clone

func (this *ComposeLogger) Clone() *ComposeLogger

func (*ComposeLogger) Debug

func (this *ComposeLogger) Debug(msg string, fields ...zap.Field)

func (*ComposeLogger) Debugf

func (this *ComposeLogger) Debugf(args ...interface{})

func (*ComposeLogger) Error

func (this *ComposeLogger) Error(msg string, fields ...zap.Field) error

func (*ComposeLogger) Errorf

func (this *ComposeLogger) Errorf(args ...interface{})

func (*ComposeLogger) Fatal

func (this *ComposeLogger) Fatal(msg string, fields ...zap.Field)

func (*ComposeLogger) Fatalf

func (this *ComposeLogger) Fatalf(args ...interface{})

func (*ComposeLogger) Info

func (this *ComposeLogger) Info(msg string, fields ...zap.Field)

func (*ComposeLogger) Infof

func (this *ComposeLogger) Infof(args ...interface{})

func (*ComposeLogger) Panic

func (this *ComposeLogger) Panic(msg string, fields ...zap.Field)

func (*ComposeLogger) Panicf

func (this *ComposeLogger) Panicf(args ...interface{})

func (*ComposeLogger) RemoveConsoleWriter

func (this *ComposeLogger) RemoveConsoleWriter(writer io.Writer)

func (*ComposeLogger) RemoveHook

func (this *ComposeLogger) RemoveHook(hook Hook)

func (*ComposeLogger) SetConsoleWriter

func (this *ComposeLogger) SetConsoleWriter(writer io.Writer)

func (*ComposeLogger) SetJsonWriter

func (this *ComposeLogger) SetJsonWriter(writer io.Writer)

func (*ComposeLogger) SetObjectWriter

func (this *ComposeLogger) SetObjectWriter(writer ObjectWriter)

func (*ComposeLogger) Sync

func (this *ComposeLogger) Sync() error

func (*ComposeLogger) Warn

func (this *ComposeLogger) Warn(msg string, fields ...zap.Field)

func (*ComposeLogger) Warnf

func (this *ComposeLogger) Warnf(args ...interface{})

func (*ComposeLogger) WithField

func (this *ComposeLogger) WithField(key string, value interface{}) *ComposeLogger

func (*ComposeLogger) WithFields

func (this *ComposeLogger) WithFields(fields Fields) *ComposeLogger

func (*ComposeLogger) Write

func (this *ComposeLogger) Write(p []byte) (int, error)

func (*ComposeLogger) WriteConsole

func (this *ComposeLogger) WriteConsole(ent zapcore.Entry, p []byte) error

func (*ComposeLogger) WriteJson

func (this *ComposeLogger) WriteJson(ent zapcore.Entry, p []byte) error

func (*ComposeLogger) WriteObject

func (this *ComposeLogger) WriteObject(ent zapcore.Entry, data map[string]interface{}) error

func (*ComposeLogger) WriteString

func (this *ComposeLogger) WriteString(s string)

type Field

type Field struct {
	Key   string
	Value interface{}
}

type Fields

type Fields map[string]interface{}

type FileRotateConf

type FileRotateConf struct {
}

type FileRotateHook

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

func NewFileRotationHook

func NewFileRotationHook(opt *FileRotateOpt) *FileRotateHook

func (*FileRotateHook) WriteConsole

func (this *FileRotateHook) WriteConsole(ent zapcore.Entry, p []byte) error

func (*FileRotateHook) WriteJson

func (this *FileRotateHook) WriteJson(ent zapcore.Entry, p []byte) error

func (*FileRotateHook) WriteObject

func (this *FileRotateHook) WriteObject(ent zapcore.Entry, m map[string]interface{}) error

type FileRotateOpt

type FileRotateOpt struct {
	MaxDay       int           //最多保留天数
	RotationSize int64         //最大尺寸
	RotationTime time.Duration //切割时间
	FileName     string        //文件名
	Json         bool          //是否用Json格式输出
	Format       string        //时间格式
	Filter       []func(ent zapcore.Entry) bool
}

type Hook

type Hook interface {
	WriteConsole(zapcore.Entry, []byte) error
	WriteJson(zapcore.Entry, []byte) error
	WriteObject(zapcore.Entry, map[string]interface{}) error
}

func NewConsoleWriter

func NewConsoleWriter(writer io.Writer) Hook

func NewJsonWriter

func NewJsonWriter(writer io.Writer) Hook

func NewObjectWriter

func NewObjectWriter(writer ObjectWriter) Hook

type ILogger

type ILogger interface {
	Clear()
	Infof(args ...interface{})
	Debugf(args ...interface{})
	Warnf(args ...interface{})
	Errorf(args ...interface{})
	Panicf(args ...interface{})
	Fatalf(args ...interface{})
	Info(msg string, fields ...zap.Field)
	Debug(msg string, fields ...zap.Field)
	Warn(msg string, fields ...zap.Field)
	Error(msg string, fields ...zap.Field) error
	Panic(msg string, fields ...zap.Field)
	Fatal(msg string, fields ...zap.Field)
	WriteString(s string)
	Write(p []byte) (int, error)
}

type LogConfig

type LogConfig struct {
	Title          string
	EncodeCfg      *zapcore.EncoderConfig
	Console        bool
	JsonConsole    bool
	Json           bool
	Object         bool
	FileRotateConf FileRotateConf
}

func ConsoleConfig

func ConsoleConfig(title string) *LogConfig

func CustomConfig added in v0.2.33

func CustomConfig(json, console, jsonConsole, object bool, config *zapcore.EncoderConfig) *LogConfig

func DefaultConfig

func DefaultConfig(title string) *LogConfig

type LoggerWithFields

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

type MongoConf

type MongoConf struct {
	Enable     bool
	Addr       string
	Db         string
	Collection string
	Expires    string
	User       string
	Pwd        string
}

type ObjectWriter

type ObjectWriter interface {
	Write(map[string]interface{}) error
}

type StdLogger

type StdLogger interface {
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Print(v ...interface{})
	Printf(format string, v ...interface{})
}

type TestLogger

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

func NewAstilecTronLogger

func NewAstilecTronLogger(enabled bool) *TestLogger

func (*TestLogger) Fatal

func (this *TestLogger) Fatal(fields ...interface{})

func (*TestLogger) Fatalf

func (this *TestLogger) Fatalf(msg string, fields ...interface{})

func (*TestLogger) Print

func (this *TestLogger) Print(fields ...interface{})

func (*TestLogger) Printf

func (this *TestLogger) Printf(msg string, fields ...interface{})

type ZapCompose

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

func NewZapCompose

func NewZapCompose(cfg *LogConfig, hook ...Hook) *ZapCompose

func (*ZapCompose) Check

func (*ZapCompose) Enabled

func (this *ZapCompose) Enabled(level zapcore.Level) bool

func (*ZapCompose) Sync

func (this *ZapCompose) Sync() error

func (*ZapCompose) With

func (this *ZapCompose) With(fields []zapcore.Field) zapcore.Core

func (*ZapCompose) Write

func (this *ZapCompose) Write(ent zapcore.Entry, fields []zapcore.Field) error

type ZapFields added in v0.1.4

type ZapFields []zap.Field

func (ZapFields) Append added in v0.1.4

func (this ZapFields) Append(field ...zap.Field) ZapFields

func (ZapFields) Concat added in v0.1.4

func (this ZapFields) Concat(fields ZapFields) ZapFields

Directories

Path Synopsis
Package color adds coloring functionality for TTY output.
Package color adds coloring functionality for TTY output.

Jump to

Keyboard shortcuts

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