logging

package
v0.0.0-...-2b5ea0c Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrKey = "error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrInfoExtractor

type ErrInfoExtractor func(error) string

ErrInfoExtractor defines a function signature for functions that can extract information from an error.

type Fields

type Fields map[string]interface{}

type Logger

type Logger interface {
	// Error Used when an error has occurred that is not recoverable, and will most likely
	// involve returning an error to the consumer/user. Implementations must include a stacktrace at this level.
	Error(msg string)

	// Warn Used when a potential issue may exist, but the system can continue to function.
	Warn(msg string)

	// Info Used when something of interest has occurred that is useful to have logged in a
	// production setting.
	Info(msg string)

	// Debug Used when providing information on specific code paths with the application that are
	// being executed that are not required in a production setting.
	Debug(msg string)

	// WithField returns a new instance of the Logger that has the specified field attached
	// in all subsequent messages.
	WithField(key string, value interface{}) Logger

	// WithError provides a wrapper around WithField to add an error field to the logger,
	// ensuring consistency of error message keys.
	WithError(err error) Logger

	// WithFields returns a new instance of the Logger that has the specified fields attached
	// in all subsequent messages.
	WithFields(fields Fields) Logger

	// Flush ensures that any pending log messages are written out. For some implementations
	// this function will be a no-op.
	Flush() error
}

Logger defines the repository interface for a generic application logger, intended to result in structured logging using the WithField(s) functions to add context to the logger.

Implementations are expected to provide new instances of the Logger when returning from the WithField(s) functions to allow for the creation of child loggers that's subsequent use don't influence the parent.

type ZapJSONLogger

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

ZapJSONLogger is an implementation of the logging repository that uses zap's sugared logger.

func NewZapJSONLogger

func NewZapJSONLogger(logLevel string, outWriter, errWriter io.Writer) (*ZapJSONLogger, error)

NewZapJSONLogger creates a zap based logger that implements to Logger repository defined in this package. The logger should be flushed before the application exits.

func (*ZapJSONLogger) Debug

func (z *ZapJSONLogger) Debug(msg string)

Debug logs a debug level message

func (*ZapJSONLogger) Error

func (z *ZapJSONLogger) Error(msg string)

Error logs an error level message. Logs at this level implicitly add a stacktrace field.

func (*ZapJSONLogger) Flush

func (z *ZapJSONLogger) Flush() error

Flush syncs that zap logger.

func (*ZapJSONLogger) Info

func (z *ZapJSONLogger) Info(msg string)

Info logs an info level message.

func (*ZapJSONLogger) Warn

func (z *ZapJSONLogger) Warn(msg string)

Warn logs a warning level message.

func (*ZapJSONLogger) WithError

func (z *ZapJSONLogger) WithError(err error) Logger

WithError provides a wrapper around WithField to add an error field to the logger, ensuring consistency of error message keys. It will also unwrap the error, unlike a normal WithField call.

func (*ZapJSONLogger) WithField

func (z *ZapJSONLogger) WithField(key string, value interface{}) Logger

WithField returns a new logger with the specified key-value pair attached for subsequent logging operations. This function returns a repositories logger interface rather than the explicit ZapJSONLogger to allow it to satisfy the Logger interface

func (*ZapJSONLogger) WithFields

func (z *ZapJSONLogger) WithFields(fields Fields) Logger

WithFields returns a new logger with the specified key-value pairs attached for subsequent logging operations. This function returns a repositories logger interface rather than the explicit ZapJSONLogger to allow it to satisfy the Logger interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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