logging

package
v0.0.0-...-5a87418 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrorKey is used to associate an error with the a message
	ErrorKey = "error"

	// ComponentKey is used to associate a component or class with a log message
	ComponentKey = "component"

	// CallstackKey is used to associate a callstack with a log message
	CallstackKey = "callstack"

	// HostnameKey is used to associate a hostname with a log message
	HostnameKey = "hostname"

	// LevelKey is used to associate a level with a log message
	LevelKey = "level"

	// LocationKey is used to associate a location with a log message
	LocationKey = "location"

	// MessageKey is used to associate a message with a log message
	MessageKey = "message"

	// ServiceKey is used to associate a service with a log message
	ServiceKey = "service"

	// TimeKey is used to associate a time with a log message
	TimeKey = "time"

	// QueueID is used to associate a queue identifier with a log message
	QueueID = "queueID"

	// Topic is used to associate a topic name with a log message
	Topic = "topic"

	// Partition is used to associate a partition id with a log message
	Partition = "partition"

	// Offset is used to associate a Kafka message offset with a log message
	Offset = "offset"
)
View Source
const (
	DebugLevel = Level(zapcore.DebugLevel)
	InfoLevel  = Level(zapcore.InfoLevel)
	WarnLevel  = Level(zapcore.WarnLevel)
	ErrorLevel = Level(zapcore.ErrorLevel)
	FatalLevel = Level(zapcore.FatalLevel)
)

Logging level constants.

Variables

This section is empty.

Functions

func SetGlobalLogger

func SetGlobalLogger(l *Logger)

SetGlobalLogger sets the global logger. By default it is a no-op logger. Passing nil will panic.

Types

type Level

type Level zapcore.Level

Level indicates the importance of a log line. Higher levels are more important.

func ParseLevel

func ParseLevel(levelStr string) (Level, error)

ParseLevel converts a level string into a Level value. returns an error if the input string does not match known values.

func (*Level) MarshalText

func (level *Level) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface. It marshals the level into its string representation and returns it as a byte array. Text strings are one of the following: "debug", "info", "warn", "error", "fatal"

func (Level) String

func (level Level) String() string

String implements the fmt.Stringer interface. It converts log severity level to string

func (*Level) UnmarshalText

func (level *Level) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. It unmarshals a byte array representing a log string into a log level object and assigns it to the level. Text strings must be one of the following: "debug", "info", "warn", "error", "fatal"

type Logger

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

Logger is a logger implementation that wraps go-observation/logging

func Global

func Global() *Logger

Global returns the global logger. The default logger is a no-op logger.

func New

func New(serviceName string) *Logger

New constructs a new logger using the default stdout for output. The serviceName argument will be traced as the standard "service" field on every trace.

func NewGlobal

func NewGlobal(name string) *Logger

NewGlobal creates a new global logger, which has INFO as its default log level.

func NewNoOp

func NewNoOp() *Logger

NewNoOp returns a no-op Logger that doesn't emit any logs. This is the default global logger.

func NewWithOutput

func NewWithOutput(serviceName string, writer io.Writer) *Logger

NewWithOutput constructs a new logger and writes output to writer. writer is an io.writer that also supports concurrent writes. The writer will be wrapped with zapcore.AddSync()

func With

func With(fields ...interface{}) *Logger

With includes the specified fields with each log message sent by this logger

func WithComponent

func WithComponent(id string) *Logger

WithComponent includes the specified component id as a field with each log message sent by this logger

func WithError

func WithError(err error) *Logger

WithError includes the specified error with each log message sent by this logger

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...interface{})

Debug logs a message at DebugLevel

func (*Logger) Error

func (l *Logger) Error(err error, msg string, fields ...interface{})

Error logs a message at ErrorLevel. err is traced as {"error": err.Error()}

func (*Logger) Fatal

func (l *Logger) Fatal(err error, msg string, fields ...interface{})

Fatal logs a message at FatalLevel and then calls os.Exit(1). err is traced as {"error": err.Error()}

func (*Logger) Flush

func (l *Logger) Flush() error

Flush ensures that all buffered messages are written. Normally it only needs to be called before program exit.

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...interface{})

Info logs a message at InfoLevel

func (*Logger) SetAsGlobal

func (l *Logger) SetAsGlobal()

SetAsGlobal sets this logger as the global logger

func (*Logger) SetLevel

func (l *Logger) SetLevel(lvl Level) *Logger

SetLevel sets the log level for this logger

func (*Logger) SetLevelFromString

func (l *Logger) SetLevelFromString(lvlStr string) *Logger

SetLevelFromString sets the log level for this logger

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...interface{})

Warn logs a message at WarnLevel

func (*Logger) With

func (l *Logger) With(fields ...interface{}) *Logger

With includes the specified fields with each log message sent by this logger

func (*Logger) WithComponent

func (l *Logger) WithComponent(id string) *Logger

WithComponent includes the specified component id as a field with each log message sent by this logger

func (*Logger) WithError

func (l *Logger) WithError(err error) *Logger

WithError includes the specified error as a field with each log message sent by this logger

Jump to

Keyboard shortcuts

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