logger

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(ctx context.Context, enableLogLevelEndpoint, developmentMode bool)

Init bootstraps the logger. You must call this method just once at the beginning of your application. The default log level is Info.

Call Logger() or SugaredLogger() to retrieve an instance of the desired type of logger. Use WithCorrelationId() or WithContextCorrelationId() to add a correlation ID to your logs.

If enableLogLevelEndpoint is true, then an HTTP endpoint on port 53835 at /logger is exposed which can be used to change the log level dynamically. See the Zap documentation for more information.

If developmentMode is true, then the logLevel is set to Debug and caller fields are more explicit. Do not enable this in production.

func PanicLogger

func PanicLogger()

PanicLogger will pass the error which caused the go routine to panic and the stack trace onto the current SugaredLogger as a Fatal message and add the field "op" with value of "panic_logger". Use it to log panics as structured logs. Remember that you must defer this call at the beginning of each goroutine!

Example

defer logger.PanicLogger()

func SetCorrelationIdContextKey

func SetCorrelationIdContextKey(key string)

SetCorrelationIdContextKey sets the correlation ID context key. By default, it is "correlation_id"

func SetCorrelationIdFieldKey

func SetCorrelationIdFieldKey(key string)

SetCorrelationIdFieldKey sets the correlation ID field key in JSON responses. By default, it is "correlation_id"

Types

type CLogger

type CLogger struct {
	zap.Logger
}

CLogger is a superset of zap.Logger

func Logger

func Logger() *CLogger

Logger returns an instance of the sugar-free logger. You must have initialized the logger prior to this call.

func (*CLogger) With

func (l *CLogger) With(args ...zap.Field) *CLogger

func (*CLogger) WithContextCorrelationId

func (l *CLogger) WithContextCorrelationId(ctx context.Context) *CLogger

WithContextCorrelationId returns an instance of the same logger with the correlation ID taken from the context added to it.

func (*CLogger) WithCorrelationId

func (l *CLogger) WithCorrelationId(correlationId interface{}) *CLogger

WithCorrelationId returns an instance of the same logger with the correlation ID field added to it.

type CSugaredLogger

type CSugaredLogger struct {
	zap.SugaredLogger
}

CSugaredLogger is a superset of zap.SugaredLogger

func SugaredLogger

func SugaredLogger() *CSugaredLogger

SugaredLogger returns an instance of the sugared logger. You must have initialized the logger prior to this call.

func (*CSugaredLogger) Fatalln

func (l *CSugaredLogger) Fatalln(args ...interface{})

func (*CSugaredLogger) Print

func (l *CSugaredLogger) Print(args ...interface{})

func (*CSugaredLogger) Printf

func (l *CSugaredLogger) Printf(format string, args ...interface{})

func (*CSugaredLogger) Println

func (l *CSugaredLogger) Println(args ...interface{})

func (*CSugaredLogger) With

func (l *CSugaredLogger) With(args ...interface{}) *CSugaredLogger

func (*CSugaredLogger) WithContextCorrelationId

func (l *CSugaredLogger) WithContextCorrelationId(ctx context.Context) *CSugaredLogger

WithContextCorrelationId returns an instance of the same logger with the correlation ID taken from the context added to it.

func (*CSugaredLogger) WithCorrelationId

func (l *CSugaredLogger) WithCorrelationId(correlationId interface{}) *CSugaredLogger

WithCorrelationId returns an instance of the same logger with the correlation ID field added to it.

Jump to

Keyboard shortcuts

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