log

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: BSD-3-Clause Imports: 5 Imported by: 3

Documentation

Index

Constants

View Source
const ContextKey = contextKey(1)
View Source
const (
	// ScopeKey to distinguish scope of logs. Convenient for searching log.
	// e.g. scope: process-receipt
	//
	//   log.WithKeyValue(ctx, log.ScopeKey, "process-receipt")
	ScopeKey = "scope"
)

Variables

This section is empty.

Functions

func BuildAndSetBgLogger

func BuildAndSetBgLogger(config Config)

func SetBgLogger

func SetBgLogger(logger *Core)

SetBgLogger set background logger

func WithKeyValue

func WithKeyValue(ctx context.Context, key, value string) context.Context

WithKeyValue attach key/value to logger

func WithLogger

func WithLogger(ctx context.Context, logger *Core) context.Context

WithLogger add logger to context

func WithZapOptions

func WithZapOptions(ctx context.Context, option ...zap.Option) context.Context

WithZapOptions clones the context's Logger, applies the supplied Options.

Types

type Config

type Config struct {
	ZapConfig zap.Config
	ZapLevel  zapcore.Level
}

func DevelopmentAndJSONConfig

func DevelopmentAndJSONConfig() Config

DevelopmentAndJSONConfig set background logger to development mode with JSON style.

func DevelopmentAndTextConfig

func DevelopmentAndTextConfig() Config

DevelopmentAndTextConfig set background logger to development mode with text style.

func ProductionAndJSONConfig

func ProductionAndJSONConfig() Config

ProductionAndJSONConfig set background logger to production mode with JSON style.

func ProductionAndTextConfig

func ProductionAndTextConfig() Config

ProductionAndTextConfig set background logger to production mode with text style.

type Core

type Core struct {
	*zap.Logger
}

func BgLogger

func BgLogger() *Core

BgLogger return background logger

func BuildLogger

func BuildLogger(config Config) *Core

func Logger

func Logger(ctx context.Context) *Core

Logger gets a contextual logger from current context. contextual logger will output common fields from context.

func (*Core) DPanic

func (c *Core) 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 (*Core) DPanicf

func (c *Core) DPanicf(format string, v ...interface{})

DPanicf formats according to a format specifier and logs the formatted message at DPanicLevel.

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 (*Core) Debug

func (c *Core) 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 (*Core) Debugf

func (c *Core) Debugf(format string, v ...interface{})

Debugf formats according to a format specifier and logs the formatted message at DebugLevel.

func (*Core) Error

func (c *Core) Error(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 (*Core) Errorf

func (c *Core) Errorf(format string, v ...interface{})

Errorf formats according to a format specifier and logs the formatted message at ErrorLevel.

func (*Core) Fatal

func (c *Core) 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 (*Core) Fatalf

func (c *Core) Fatalf(format string, v ...interface{})

Fatalf formats according to a format specifier and logs the formatted message at FatalLevel.

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func (*Core) Info

func (c *Core) 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 (*Core) Infof

func (c *Core) Infof(format string, v ...interface{})

Infof formats according to a format specifier and logs the formatted message at InfoLevel.

func (*Core) Panic

func (c *Core) 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 (*Core) Panicf

func (c *Core) Panicf(format string, v ...interface{})

Panicf formats according to a format specifier and logs the formatted message at PanicLevel.

The logger then panics, even if logging at PanicLevel is disabled.

func (*Core) Warn

func (c *Core) 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 (*Core) Warnf

func (c *Core) Warnf(format string, v ...interface{})

Warnf formats according to a format specifier and logs the formatted message at WarnLevel.

type Levels

type Levels map[string]*zap.AtomicLevel

func GetLevels

func GetLevels() *Levels

GetLevels return a global log levels

func NewLogLevels

func NewLogLevels(defaultLevel zapcore.Level) *Levels

NewLogLevels return a new log levels

func (*Levels) Get

func (l *Levels) Get() *zap.AtomicLevel

func (*Levels) GetWithScope

func (l *Levels) GetWithScope(scope string) *zap.AtomicLevel

func (*Levels) Set

func (l *Levels) Set(level zapcore.Level)

func (*Levels) SetWithScope

func (l *Levels) SetWithScope(scope string, level zapcore.Level)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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