logging

package
Version: v0.2103.7 Latest Latest
Warning

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

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

Documentation

Overview

Package logging implements support for structured logging.

This package is inspired heavily by go-logging, kit/log and the tendermint libs/log packages, and is oriented towards making the structured logging experience somewhat easier to use.

Index

Constants

View Source
const LogEvent = "log_event"

LogEvent is the structured log key used to signal log events to be easily parsed by the testing harness.

Values should be defined as constants in the respective modules that emit these events.

Variables

This section is empty.

Functions

func Initialize

func Initialize(w io.Writer, format Format, defaultLvl Level, moduleLvls map[string]Level) error

Initialize initializes the logging backend to write to the provided Writer with the given format and log levels specified for each module. If the requested module is not given, default level is taken. If the Writer is nil, all log output will be silently discarded.

Types

type Format

type Format uint

Format is a logging format.

const (
	// FmtLogfmt is the "logfmt" logging format.
	FmtLogfmt Format = iota
	// FmtJSON is the JSON logging format.
	FmtJSON
)

func (*Format) Set

func (f *Format) Set(s string) error

Set sets the Format to the value specified by the provided string.

func (*Format) String

func (f *Format) String() string

String returns the string representation of a Format.

func (*Format) Type

func (f *Format) Type() string

Type returns the list of supported Formats.

type Level

type Level uint

Level is a log level.

const (
	// LevelDebug is the log level for debug messages.
	LevelDebug Level = iota
	// LevelInfo is the log level for informative messages.
	LevelInfo
	// LevelWarn is the log level for warning messages.
	LevelWarn
	// LevelError is the log level for error messages.
	LevelError
)

func GetLevel

func GetLevel() Level

GetLevel returns the current global log level.

func (*Level) Set

func (l *Level) Set(s string) error

Set sets the Level to the value specified by the provided string.

func (*Level) String

func (l *Level) String() string

String returns the string representation of a Level.

func (*Level) Type

func (l *Level) Type() string

Type returns the list of supported Levels.

type Logger

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

Logger is a logger instance.

func GetLogger

func GetLogger(module string) *Logger

GetLogger creates a new logger instance with the specified module.

This may be called from any point, including before Initialize is called, allowing for the construction of a package level Logger.

func GetLoggerEx

func GetLoggerEx(module string, extraUnwind int) *Logger

GetLoggerEx creates a new logger instance with the specified module, using the specified extra levels of stack unwinding when determining a caller.

The GetLogger call is equivalent to GetLoggerEx with an extraUnwind of 0. This routine is primarily intended to facilitate writing additional logging wrappers.

func (*Logger) Debug

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

Debug logs the message and key value pairs at the Debug log level.

func (*Logger) Error

func (l *Logger) Error(msg string, keyvals ...interface{})

Error logs the message and key value pairs at the Error log level.

func (*Logger) Info

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

Info logs the message and key value pairs at the Info log level.

func (*Logger) Warn

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

Warn logs the message and key value pairs at the Warn log level.

func (*Logger) With

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

With returns a clone of the logger with the provided key/value pairs added via log.WithPrefix.

Jump to

Keyboard shortcuts

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