log

package
v0.0.0-...-4bc4564 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugLevel logs a message at debug level
	DebugLevel = iota
	// InfoLevel logs a message at info level
	InfoLevel
	// TraceLevel logs a message at trace level
	TraceLevel
	// WarnLevel logs a message at warning level
	WarnLevel
	// ErrorLevel logs a message at error level
	ErrorLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
)
View Source
const CONSOLE = "console"

CONSOLE formats the log for the console, mostly used during development

View Source
const JSON = "json"

JSON formats the log using json format, mostly used by an automated logging system consumption

Variables

This section is empty.

Functions

func CleanUp

func CleanUp() error

CleanUp flushed any buffered log entries. Applications should take care to call CleanUp before exiting.

func Debug

func Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func Debugf

func Debugf(format string, args ...interface{})

Debugf logs a message at level Debug on the standard logger.

func Debugln

func Debugln(args ...interface{})

Debugln logs a message at level Debug on the standard logger.

func Debugw

func Debugw(msg string, keysAndValues Fields)

Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func Error

func Error(args ...interface{})

Error logs a message at level Error on the standard logger.

func Errorf

func Errorf(format string, args ...interface{})

Errorf logs a message at level Error on the standard logger.

func Errorln

func Errorln(args ...interface{})

Errorln logs a message at level Error on the standard logger.

func Errorw

func Errorw(msg string, keysAndValues Fields)

Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func Fatal

func Fatal(args ...interface{})

Fatal logs a message at level Fatal on the standard logger.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf logs a message at level Fatal on the standard logger.

func Fatalln

func Fatalln(args ...interface{})

Fatalln logs a message at level Fatal on the standard logger.

func Fatalw

func Fatalw(msg string, keysAndValues Fields)

Fatalw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func GetPackageLogLevel

func GetPackageLogLevel(packageName ...string) (int, error)

GetPackageLogLevel returns the current log level of a package.

func Info

func Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func Infof

func Infof(format string, args ...interface{})

Infof logs a message at level Info on the standard logger.

func Infoln

func Infoln(args ...interface{})

Infoln logs a message at level Info on the standard logger.

func Infow

func Infow(msg string, keysAndValues Fields)

Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func InitLogging

func InitLogging()

Set up our logging

func Panic

func Panic(args ...interface{})

Panic logs a message at level Panic on the standard logger.

func Panicf

func Panicf(format string, args ...interface{})

Panicf logs a message at level Panic on the standard logger.

func Panicln

func Panicln(args ...interface{})

Panicln logs a message at level Panic on the standard logger.

func Panicw

func Panicw(msg string, keysAndValues Fields)

Panicw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func SetAllLogLevel

func SetAllLogLevel(level int)

SetAllLogLevel sets the log level of all registered packages to level

func SetLogLevel

func SetLogLevel(level int) error

SetLogLevel sets the log level for the logger corresponding to the caller's package

func SetPackageLogLevel

func SetPackageLogLevel(packageName string, level int)

SetPackageLogLevel dynamically sets the log level of a given package to level. This is typically invoked at an application level during debugging

func ShortTimeEncoder

func ShortTimeEncoder(t time.Time, enc zc.PrimitiveArrayEncoder)

Short string with microsecond precision

func UpdateAllLoggers

func UpdateAllLoggers(defaultFields Fields) error

UpdateAllLoggers create new loggers for all registered packages with the defaultFields.

func V

func V(level int) bool

V reports whether verbosity level l is at least the requested verbose level.

func Warn

func Warn(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func Warnf

func Warnf(format string, args ...interface{})

Warnf logs a message at level Warn on the standard logger.

func Warning

func Warning(args ...interface{})

Warning logs a message at level Warn on the standard logger.

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs a message at level Warn on the standard logger.

func Warningln

func Warningln(args ...interface{})

Warningln logs a message at level Warn on the standard logger.

func Warnln

func Warnln(args ...interface{})

Warnln logs a message at level Warn on the standard logger.

func Warnw

func Warnw(msg string, keysAndValues Fields)

Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

Types

type Fields

type Fields map[string]interface{}

Fields is used as key-value pairs for structured logging

type Logger

type Logger interface {
	Debug(...interface{})
	Debugln(...interface{})
	Debugf(string, ...interface{})
	Debugw(string, Fields)

	Info(...interface{})
	Infoln(...interface{})
	Infof(string, ...interface{})
	Infow(string, Fields)

	Warn(...interface{})
	Warnln(...interface{})
	Warnf(string, ...interface{})
	Warnw(string, Fields)

	Error(...interface{})
	Errorln(...interface{})
	Errorf(string, ...interface{})
	Errorw(string, Fields)

	Panic(...interface{})
	Panicln(...interface{})
	Panicf(string, ...interface{})
	Panicw(string, Fields)

	Fatal(...interface{})
	Fatalln(...interface{})
	Fatalf(string, ...interface{})
	Fatalw(string, Fields)

	With(Fields) Logger

	// The following are added to be able to use this logger as a gRPC LoggerV2 if needed
	//
	Warning(...interface{})
	Warningln(...interface{})
	Warningf(string, ...interface{})

	// V reports whether verbosity level l is at least the requested verbose level.
	V(l int) bool
}

Logger represents an abstract logging interface. Any logging implementation used will need to abide by this interface

func AddPackage

func AddPackage(outputType string, level int, defaultFields Fields, pkgNames ...string) (Logger, error)

AddPackage registers a package to the log map. Each package gets its own logger which allows its config (loglevel) to be changed dynamically without interacting with the other packages. outputType is JSON, level is the lowest level log to output with this logger and defaultFields is a map of key-value pairs to always add to the output. Note: AddPackage also returns a reference to the actual logger. If a calling package uses this reference directly instead of using the publicly available functions in this log package then a number of functionalities will not be available to it, notably log tracing with filename.functionname.linenumber annotation.

pkgNames parameter should be used for testing only as this function detects the caller's package.

func SetDefaultLogger

func SetDefaultLogger(outputType string, level int, defaultFields Fields) (Logger, error)

SetLogger needs to be invoked before the logger API can be invoked. This function initialize the default logger (zap's sugaredlogger)

func UpdateLogger

func UpdateLogger(defaultFields Fields) (Logger, error)

UpdateLogger deletes the logger associated with a caller's package and creates a new logger with the defaultFields. If a calling package is holding on to a Logger reference obtained from AddPackage invocation, then that package needs to invoke UpdateLogger if it needs to make changes to the default fields and obtain a new logger reference

func With

func With(keysAndValues Fields) Logger

With returns a logger initialized with the key-value pairs

Jump to

Keyboard shortcuts

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