log

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 19 Imported by: 33

README

core 核心包含编码和输出 sink 输出 encoder 编码 encoder+sink = zapcore.ioCore

钉钉 loki一类接口就需要特定字段结构化的,最好实现core,当然这往往需要自己实现encoder,sink即第三方接口

Documentation

Index

Constants

View Source
const (
	FieldStack    = "stack"
	FieldApi      = "api"
	FieldSource   = "source"
	FieldResult   = "result"
	FieldParam    = "param"
	FieldFunc     = "func"
	FieldMsg      = "msg"
	FieldPosition = "position"
	FieldTraceId  = "traceId"
	FieldSpanId   = "spanId"
	FieldKey      = "key"
	FieldValue    = "value"
	FieldInvalid  = "invalid"
	FieldIgnored  = "ignored"

	FieldType     = "type"
	FieldIP       = "ip"
	FieldHostname = "hostname"

	FieldTime   = "time"
	FieldApp    = "app"
	FieldLevel  = "level"
	FieldCaller = "caller"
)
View Source
const (
	EncodeLevelTypeColor        = "color"
	EncodeLevelTypCapital       = "capital"
	EncodeLevelTypeCapitalColor = "capitalColor"
)

Variables

This section is empty.

Functions

func Check added in v0.0.36

func Check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry

func DPanicEntry added in v0.1.6

func DPanicEntry(args ...any) *zapcore.CheckedEntry

func Debug

func Debug(args ...any)

func DebugEntry added in v0.1.6

func DebugEntry(args ...any) *zapcore.CheckedEntry

func Debugf

func Debugf(template string, args ...any)

func Debugw

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

func DurationNotify added in v0.0.20

func DurationNotify(msg string, v time.Duration, std time.Duration)

func Error

func Error(args ...any)

func ErrorEntry added in v0.1.6

func ErrorEntry(args ...any) *zapcore.CheckedEntry

func Errorf

func Errorf(template string, args ...any)

func Errorw

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

func Fatal

func Fatal(args ...any)

func FatalEntry added in v0.1.6

func FatalEntry(args ...any) *zapcore.CheckedEntry

func Fatalf

func Fatalf(template string, args ...any)

func Fatalw

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

func FileWithLineNum

func FileWithLineNum() string

FileWithLineNum return the file name and line number of the current file

func Info

func Info(args ...any)

func InfoEntry added in v0.1.6

func InfoEntry(args ...any) *zapcore.CheckedEntry

func Infof

func Infof(template string, args ...any)

func Infow

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

func Log added in v0.0.37

func Log(lvl zapcore.Level, args ...any)

func Logf added in v0.0.37

func Logf(lvl zapcore.Level, msg string, args ...any)

func Logw added in v0.0.37

func Logw(lvl zapcore.Level, msg string, fields ...zapcore.Field)

func NewDevelopmentEncoderConfig

func NewDevelopmentEncoderConfig() zapcore.EncoderConfig

func NewProductionEncoderConfig

func NewProductionEncoderConfig() zapcore.EncoderConfig

func NoCallerDebug added in v0.1.6

func NoCallerDebug(args ...any)

func NoCallerError added in v0.1.6

func NoCallerError(args ...any)

func NoCallerErrorf added in v0.1.6

func NoCallerErrorf(template string, args ...any)

func NoCallerErrorw added in v0.1.6

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

func NoCallerFatal added in v0.1.6

func NoCallerFatal(args ...any)

func NoCallerFatalf added in v0.1.6

func NoCallerFatalf(template string, args ...any)

func NoCallerFatalw added in v0.1.6

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

func NoCallerInfo added in v0.1.6

func NoCallerInfo(args ...any)

func NoCallerPanic added in v0.1.6

func NoCallerPanic(args ...any)

func NoCallerPanicw added in v0.1.6

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

func NoCallerWarn added in v0.1.6

func NoCallerWarn(args ...any)

func NoLEDebug added in v0.1.6

func NoLEDebug(args ...any)

func NoLEDebugf added in v0.1.6

func NoLEDebugf(template string, args ...any)

func NoLEDebugw added in v0.1.6

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

func NoLEError added in v0.1.6

func NoLEError(args ...any)

func NoLEErrorf added in v0.1.6

func NoLEErrorf(template string, args ...any)

func NoLEErrorw added in v0.1.6

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

func NoLEFatal added in v0.1.6

func NoLEFatal(args ...any)

func NoLEFatalf added in v0.1.6

func NoLEFatalf(template string, args ...any)

func NoLEFatalw added in v0.1.6

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

func NoLEInfo added in v0.1.6

func NoLEInfo(args ...any)

func NoLEInfof added in v0.1.6

func NoLEInfof(template string, args ...any)

func NoLEInfow added in v0.1.6

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

func NoLEPanic added in v0.1.6

func NoLEPanic(args ...any)

func NoLEPanicw added in v0.1.6

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

func NoLEWarn added in v0.1.6

func NoLEWarn(args ...any)

func Panic

func Panic(args ...any)

func PanicEntry added in v0.1.6

func PanicEntry(args ...any) *zapcore.CheckedEntry

func Panicf

func Panicf(template string, args ...any)

func Panicw

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

func Printf

func Printf(template string, args ...any)

func Println

func Println(args ...any)

func SetDefaultLogger

func SetDefaultLogger(lf *Config, cores ...zapcore.Core)

func Sprintln added in v0.0.36

func Sprintln(a ...any) string

func StackError added in v0.1.6

func StackError(args ...any)

with stack

func StackErrorf added in v0.1.6

func StackErrorf(template string, args ...any)

func StackErrorw added in v0.1.6

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

func Sync

func Sync() error

func TrimLineBreak added in v0.0.36

func TrimLineBreak(path string) string

func ValueNotify added in v0.0.20

func ValueNotify[T cmp.Ordered](msg string, v T, rangeMin, rangeMax T)

func Warn

func Warn(args ...any)

func WarnEntry added in v0.1.6

func WarnEntry(args ...any) *zapcore.CheckedEntry

func Warnf

func Warnf(template string, args ...any)

func Warnw

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

Types

type Config

type Config struct {
	Name              string `json:"name,omitempty"` //系统名称namespace.service
	Development       bool
	DisableCaller     bool
	DisableStacktrace bool
	Level             zapcore.Level       `json:"level,omitempty"`
	Sampling          *zap.SamplingConfig `json:"sampling" yaml:"sampling"`
	OutputPaths       OutPutPaths         `json:"outputPaths"`
	ErrorOutputPaths  []string
	// InitialFields is a collection of fields to add to the root logger.
	InitialFields map[string]interface{} `json:"initialFields" yaml:"initialFields"`
	zapcore.EncoderConfig
	EncodeLevelType string `json:"encodeLevelType,omitempty" comment:"capital;capitalColor;color"`
}

func NewDevelopmentConfig

func NewDevelopmentConfig(appName string) *Config

func NewProductionConfig

func NewProductionConfig(appName string) *Config

func (*Config) Init

func (lc *Config) Init()

func (*Config) NewLogger

func (lc *Config) NewLogger(cores ...zapcore.Core) *Logger

初始化日志对象

type Logger

type Logger struct {
	*zap.Logger
}

func Default

func Default() *Logger

func GetCallerSkipLogger

func GetCallerSkipLogger(skip int) *Logger

range -3~6

func GetNoCallerLogger

func GetNoCallerLogger() *Logger

func GetNoLineEndingLogger added in v0.1.6

func GetNoLineEndingLogger() *Logger

func GetStackLogger

func GetStackLogger() *Logger

func (*Logger) AddCore

func (l *Logger) AddCore(newCore zapcore.Core) *Logger

AddCore wrap the zap AddCore.

func (*Logger) AddSkip

func (l *Logger) AddSkip(skip int) *Logger

AddSkip wrap the zap AddCallerSkip.

func (*Logger) DPanic

func (l *Logger) DPanic(args ...any)

DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)

func (*Logger) DPanicf

func (l *Logger) DPanicf(template string, args ...any)

DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)

func (*Logger) DPanicw

func (l *Logger) DPanicw(msg string, fields ...zap.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 (*Logger) Debug

func (l *Logger) Debug(args ...any)

Debug uses fmt.Sprint to construct and log a message.

func (*Logger) Debugf

func (l *Logger) Debugf(template string, args ...any)

Debugf uses fmt.Sprintf to log a templated message.

func (*Logger) Debugfw

func (l *Logger) Debugfw(template string, args ...any) func(...zapcore.Field)

func (*Logger) Debugsw

func (l *Logger) Debugsw(msg string, args ...any)

func (*Logger) Debugw

func (l *Logger) Debugw(msg string, fields ...zap.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 (*Logger) Enabled

func (l *Logger) Enabled(ctx context.Context, level slog.Level) bool

func (*Logger) Error

func (l *Logger) Error(args ...any)

Error uses fmt.Sprint to construct and log a message.

func (*Logger) ErrorDepth

func (l *Logger) ErrorDepth(depth int, args ...any)

ErrorDepth logs to ERROR log at the specified depth. Arguments are handled in the manner of fmt.Println.

func (*Logger) Errorf

func (l *Logger) Errorf(template string, args ...any)

Errorf uses fmt.Sprintf to log a templated message.

func (*Logger) Errorln

func (l *Logger) Errorln(args ...any)

func (*Logger) Errorw

func (l *Logger) Errorw(msg string, fields ...zap.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 (*Logger) Fatal

func (l *Logger) Fatal(args ...any)

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.

func (*Logger) FatalDepth

func (l *Logger) FatalDepth(depth int, args ...any)

FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Println.

func (*Logger) Fatalf

func (l *Logger) Fatalf(template string, args ...any)

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func (*Logger) Fatalln

func (l *Logger) Fatalln(args ...any)

func (*Logger) Fatalw

func (l *Logger) Fatalw(msg string, fields ...zap.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 (*Logger) Handle

func (l *Logger) Handle(ctx context.Context, record slog.Record) error

func (*Logger) Info

func (l *Logger) Info(args ...any)

Info uses fmt.Sprint to construct and log a message.

func (*Logger) InfoDepth

func (l *Logger) InfoDepth(depth int, args ...any)

InfoDepth logs to INFO log at the specified depth. Arguments are handled in the manner of fmt.Println.

func (*Logger) Infof

func (l *Logger) Infof(template string, args ...any)

Infof uses fmt.Sprintf to log a templated message.

func (*Logger) Infofw

func (l *Logger) Infofw(template string, args ...any) func(...zapcore.Field)

func (*Logger) Infoln

func (l *Logger) Infoln(args ...any)

// 等同于xxxln,为了实现某些接口 如grpclog

func (*Logger) Infow

func (l *Logger) Infow(msg string, fields ...zap.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 (*Logger) Named

func (l *Logger) Named(name string) *Logger

Named adds a sub-scope to the logger's name. See Logger.Named for details.

func (*Logger) NewSLogger

func (l *Logger) NewSLogger() *slog.Logger

func (*Logger) Panic

func (l *Logger) Panic(args ...any)

Panic uses fmt.Sprint to construct and log a message, then panics.

func (*Logger) Panicf

func (l *Logger) Panicf(template string, args ...any)

Panicf uses fmt.Sprintf to log a templated message, then panics.

func (*Logger) Panicw

func (l *Logger) Panicw(msg string, fields ...zap.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 (*Logger) Print

func (l *Logger) Print(args ...any)

兼容gormv1

func (*Logger) Printf

func (l *Logger) Printf(template string, args ...any)

func (*Logger) Println

func (l *Logger) Println(args ...any)

func (*Logger) Sugar

func (l *Logger) Sugar() *zap.SugaredLogger

Sugar wrap the zap Sugar.

func (*Logger) V

func (l *Logger) V(level int) bool

grpclog

func (*Logger) Warn

func (l *Logger) Warn(args ...any)

Warn uses fmt.Sprint to construct and log a message.

func (*Logger) Warnf

func (l *Logger) Warnf(template string, args ...any)

Warnf uses fmt.Sprintf to log a templated message.

func (*Logger) Warning

func (l *Logger) Warning(args ...any)

func (*Logger) WarningDepth

func (l *Logger) WarningDepth(depth int, args ...any)

WarningDepth logs to WARNING log at the specified depth. Arguments are handled in the manner of fmt.Println.

func (*Logger) Warningf

func (l *Logger) Warningf(template string, args ...any)

grpclog

func (*Logger) Warningln

func (l *Logger) Warningln(args ...any)

func (*Logger) Warnw

func (l *Logger) Warnw(msg string, fields ...zap.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.

func (*Logger) With

func (l *Logger) With(fields ...zap.Field) *Logger

With wrap the zap With. Fields added to the child don't affect the parent, and vice versa.

func (*Logger) WithAttrs

func (l *Logger) WithAttrs(attrs []slog.Attr) slog.Handler

func (*Logger) WithGroup

func (l *Logger) WithGroup(name string) slog.Handler

func (*Logger) WithOptions

func (l *Logger) WithOptions(opts ...zap.Option) *Logger

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

func (*Logger) Zap added in v0.0.37

func (l *Logger) Zap() *zap.Logger

Sugar wrap the zap Sugar.

type OutPutPaths

type OutPutPaths struct {
	Console []string `json:"console,omitempty"`
	Json    []string `json:"json,omitempty"`
}

type RawJson added in v0.0.31

type RawJson json.RawMessage

func (RawJson) MarshalJSON added in v0.0.31

func (b RawJson) MarshalJSON() ([]byte, error)

func (RawJson) MarshalLogObject added in v0.0.31

func (b RawJson) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*RawJson) UnmarshalJSON added in v0.0.31

func (b *RawJson) UnmarshalJSON(raw []byte) error

type StdErrLevel

type StdErrLevel zapcore.Level

func (StdErrLevel) Enabled

func (l StdErrLevel) Enabled(lvl zapcore.Level) bool

type StdOutLevel

type StdOutLevel zapcore.Level

func (StdOutLevel) Enabled

func (l StdOutLevel) Enabled(lvl zapcore.Level) bool

type ZipConfig

type ZipConfig = zap.Config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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