log

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNil = errors.New("the value is null")

Functions

func AppendContextFields

func AppendContextFields(parent context.Context, fields ...zap.Field) context.Context

func DefaultSamplingConfig

func DefaultSamplingConfig() *zap.SamplingConfig

DefaultSamplingConfig return the default sampling config for the zap logger. it would start sampling after exceeding initial entries(default was 64) per second and only sample the Thereafter(default was 10 which means sampling 10%) th entry.

func DynamicDebugLogging

func DynamicDebugLogging(parent context.Context) context.Context

DynamicDebugLogging open the debug level logging in dynamically

func GetContextFields

func GetContextFields(ctx context.Context) []zap.Field

Types

type Logger

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

func GlobalLogger

func GlobalLogger() *Logger

func NewLogger

func NewLogger(loglevel, encoding string, samplingConfig *zap.SamplingConfig, fileLogPath string) (*Logger, error)

func (*Logger) Check

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

Check returns a CheckedEntry if logging a message at the specified level is enabled. It's a completely optional optimization; in high-performance applications, Check can help avoid allocating a slice to hold fields.

func (*Logger) Core

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

Core returns the Logger's underlying zapcore.Core.

func (*Logger) DPanic

func (l *Logger) DPanic(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) DPanicCtx

func (l *Logger) DPanicCtx(ctx context.Context, msg string, fields ...zap.Field)

DPanicCtx 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(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) DebugCtx

func (l *Logger) DebugCtx(ctx context.Context, msg string, fields ...zap.Field)

DebugCtx 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) Error

func (l *Logger) Error(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) ErrorCtx

func (l *Logger) ErrorCtx(ctx context.Context, msg string, fields ...zap.Field)

ErrorCtx 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(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) FatalCtx

func (l *Logger) FatalCtx(ctx context.Context, msg string, fields ...zap.Field)

FatalCtx 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) GetZapLogger

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

GetZapLogger would return the zap logger

func (*Logger) Info

func (l *Logger) Info(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) InfoCtx

func (l *Logger) InfoCtx(ctx context.Context, msg string, fields ...zap.Field)

InfoCtx 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) IsDynamicDebugEnabled

func (l *Logger) IsDynamicDebugEnabled(ctx context.Context) bool

IsDynamicDebugEnabled check whether debug level logging enabled.

func (*Logger) Named

func (l *Logger) 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 (*Logger) Panic

func (l *Logger) Panic(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) PanicCtx

func (l *Logger) PanicCtx(ctx context.Context, msg string, fields ...zap.Field)

PanicCtx 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) Sync

func (l *Logger) Sync() error

Sync calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.

func (*Logger) Warn

func (l *Logger) Warn(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) WarnCtx

func (l *Logger) WarnCtx(ctx context.Context, msg string, fields ...zap.Field)

WarnCtx 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 creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.

func (*Logger) WithOptions

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

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

Jump to

Keyboard shortcuts

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