zap

package
v3.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 13 Imported by: 5

README

Zap Logger

The Zap module implements the flamingo Logger interface and uses Zap logger.

Usage

Just add the module to your bootstrap, the module will Bind on the interface flamingo.Logger which is the interface you should inject in your application code to do logging.

Use the method .WithContext(ctx) whenever you have a context, this will make sure that traceId, spanId and session (if configured) are added to the log automatically.

Configuration

zap:
  loglevel: Info
  json: true
  colored: false
  devmode: false
  logsession: true # to enable logging sessionid as sha256
  sampling: # see zap sampling doc
    enabled: true
    initial: 100
    thereafter: 100
  fieldmap:
    key: value
  

More about Zap

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

Logger is a Wrapper for the zap logger fulfilling the flamingo.Logger interface

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

Debug logs a message at debug level

func (*Logger) Debugf

func (l *Logger) Debugf(log string, args ...interface{})

Debugf logs a message at debug level with format string

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

Error logs a message at error level

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

Fatal logs a message at fatal level The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func (*Logger) Flush

func (l *Logger) Flush()

Flush is used by buffered loggers and triggers the actual writing. It is a good habit to call Flush before letting the process exit. For the top level flamingo.Logger, this is called by the app itself.

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

Info logs a message at info level

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{})

Panic logs a message at panic level The logger then panics, even if logging at PanicLevel is disabled.

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

Warn logs a message at warn level

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) flamingo.Logger

WithContext returns a logger with fields filled from the context businessId: From Header X-Business-ID client_ip: From Header X-Forwarded-For or request if header is empty correlationId: The ID of the context method: HTTP verb from request path: URL path from request referer: referer from request request: received payload from request

func (*Logger) WithField

func (l *Logger) WithField(key flamingo.LogKey, value interface{}) flamingo.Logger

WithField creates a child logger and adds structured context to it.

func (*Logger) WithFields

func (l *Logger) WithFields(fields map[flamingo.LogKey]interface{}) flamingo.Logger

WithFields creates a child logger and adds structured context to it.

type Module

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

Module for logrus logging

func (*Module) Configure

func (m *Module) Configure(injector *dingo.Injector)

Configure the logrus logger as flamingo.Logger (in JSON mode kibana compatible)

func (*Module) CueConfig added in v3.1.0

func (m *Module) CueConfig() string

CueConfig Schema

func (*Module) FlamingoLegacyConfigAlias added in v3.1.0

func (*Module) FlamingoLegacyConfigAlias() map[string]string

FlamingoLegacyConfigAlias mapping

func (*Module) Inject

func (m *Module) Inject(config *struct {
	Area               string     `inject:"config:area"`
	JSON               bool       `inject:"config:core.zap.json,optional"`
	LogLevel           string     `inject:"config:core.zap.loglevel,optional"`
	ColoredOutput      bool       `inject:"config:core.zap.colored,optional"`
	DevelopmentMode    bool       `inject:"config:core.zap.devmode,optional"`
	SamplingEnabled    bool       `inject:"config:core.zap.sampling.enabled,optional"`
	SamplingInitial    float64    `inject:"config:core.zap.sampling.initial,optional"`
	SamplingThereafter float64    `inject:"config:core.zap.sampling.thereafter,optional"`
	FieldMap           config.Map `inject:"config:core.zap.fieldmap,optional"`
	LogSession         bool       `inject:"config:core.zap.logsession,optional"`
})

Inject dependencies

Jump to

Keyboard shortcuts

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