Documentation ¶
Index ¶
- func AtExit(handler func())
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Exit(code int)
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func SetAutoFormat()
- func SetAutoJSONFormat()
- func SetDefaultLevel()
- func SetJSONFormat()
- func SetLogLevel(level LogLevel)
- func SetOutput(output io.Writer)
- func SetOutputFile(path string) error
- func SetTextFormat()
- func SetUpstreamEndpoint(endpoint string)
- func Trace(args ...interface{})
- func Tracef(format string, args ...interface{})
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- type Fields
- type LogLevel
- type Logger
- func (logger Logger) Debug(args ...interface{})
- func (logger Logger) Debugf(format string, args ...interface{})
- func (logger Logger) Eprint(args ...interface{}) error
- func (logger Logger) Eprintf(format string, args ...interface{}) error
- func (logger Logger) Error(args ...interface{})
- func (logger Logger) Errorf(format string, args ...interface{})
- func (logger Logger) Ewrap(innerError error) error
- func (logger Logger) Fatal(args ...interface{})
- func (logger Logger) Fatalf(format string, args ...interface{})
- func (logger Logger) Info(args ...interface{})
- func (logger Logger) Infof(format string, args ...interface{})
- func (logger Logger) NewWriter(level LogLevel) io.Writer
- func (logger Logger) Panic(args ...interface{})
- func (logger Logger) Panicf(format string, args ...interface{})
- func (logger Logger) Sprint(args ...interface{}) string
- func (logger Logger) Sprintf(format string, args ...interface{}) string
- func (logger Logger) Trace(args ...interface{})
- func (logger Logger) Tracef(format string, args ...interface{})
- func (logger Logger) Warn(args ...interface{})
- func (logger Logger) Warnf(format string, args ...interface{})
- func (logger Logger) WithField(key string, value interface{}) Logger
- func (logger Logger) WithFields(fields map[string]interface{}) Logger
- type StructuredError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtExit ¶
func AtExit(handler func())
AtExit registers a function to be called when the program is shut down.
AtExit can be called multiple times and functions registered are called in reverse order (like "defer").
Since go doesn't provide any shutdown callback at the moment, the mechanism only works when application quits by calling Exit() here.
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf logs debugging information with formatting
func Exit ¶
func Exit(code int)
Exit quits the program by calling exit on the underlying logger and flushes all remaining logs if any
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf logs critical errros with formatting
func Panicf ¶
func Panicf(format string, args ...interface{})
Panicf logs critical errors with formatting and exits the program
func SetAutoFormat ¶
func SetAutoFormat()
SetAutoFormat uses the environment variable `LOG_COLOR` and terminal detection to select console or text output format
SetAutoFormat is the default choice and always invoked during initialization
func SetAutoJSONFormat ¶
func SetAutoJSONFormat()
SetAutoJSONFormat uses the environment variable `LOG_COLOR` and terminal detection to select console or JSON output format
func SetDefaultLevel ¶
func SetDefaultLevel()
SetDefaultLevel sets the default logging level depending on environment variable "LOG_LEVEL"
func SetJSONFormat ¶
func SetJSONFormat()
SetJSONFormat sets the upstream compatible logging format in JSON. For example:
{"timestamp":"2006/02/01T15:04:05.123+0200","level":"info","message":"A group of walrus emerges from theocean"}
func SetOutputFile ¶
SetOutputFile configure the root logger to write into specified file
func SetTextFormat ¶
func SetTextFormat()
SetTextFormat sets the default text format. For example:
time="2006/02/01T15:04:05.123+0200" level=debug msg="Started observing beach"
func SetUpstreamEndpoint ¶
func SetUpstreamEndpoint(endpoint string)
SetUpstreamEndpoint configures the root logger to duplicate and forward all logs to upstream This function should be called at most once.
Types ¶
type LogLevel ¶
type LogLevel string
LogLevel represents the logging level. The level here is abstract and meant to be translated to real logging levels used by the underlying library.
const ( PanicLevel LogLevel = "panic" FatalLevel LogLevel = "fatal" ErrorLevel LogLevel = "error" WarnLevel LogLevel = "warn" InfoLevel LogLevel = "info" DebugLevel LogLevel = "debug" TraceLevel LogLevel = "trace" )
Logging levels
func GetLogLevel ¶
func GetLogLevel() LogLevel
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger wraps a logger (Entry) of the underlying logging library Logger should always be passed by value
func Root ¶
func Root() Logger
Root gets the root logger that can be used to create sub-loggers.
Calling global logging functions in the package is the same as calling methods in the root logger.
func WithFields ¶
WithFields creates a sub-logger from the root logger with specifid fields
func (Logger) Debug ¶
func (logger Logger) Debug(args ...interface{})
Debug logs debugging information
func (Logger) Eprint ¶
Eprint prints the given arguments with fields in this logger to a StructuredError
Fields in the logger are copied into StructuredError for later logging
func (Logger) Eprintf ¶
Eprintf formats the given arguments with fields in this logger to a StructuredError
Fields in the logger are copied into StructuredError for later logging
func (Logger) Error ¶
func (logger Logger) Error(args ...interface{})
Error logs errors via the root logger
func (Logger) Ewrap ¶
Ewrap wraps the given error inside a newly-created StructuredError with context information
Fields in the logger are copied into StructuredError for later logging
func (Logger) NewWriter ¶
NewWriter creates an io.Writer on this logger. Each .Write() call would log a message.
func (Logger) Panic ¶
func (logger Logger) Panic(args ...interface{})
Panic logs critical errors and exits the program
func (Logger) Sprint ¶
Sprint prints the given arguments with fields in this logger to a string
e.g. "[MyClass] name=Foo status=200 My message"
func (Logger) Sprintf ¶
Sprintf formats the given arguments with fields in this logger to a string
e.g. "[MyClass] name=Foo status=200 Hi '<someone>'"
func (Logger) Trace ¶
func (logger Logger) Trace(args ...interface{})
Trace logs tracing information
func (Logger) WithFields ¶
WithFields creates a sub-logger with specifid fields
type StructuredError ¶
type StructuredError struct {
// contains filtered or unexported fields
}
StructuredError represents a thing that carries metadata that should be elevated to log fields when logged
func NewStructuredError ¶
func NewStructuredError(srcFields map[string]interface{}, err error) *StructuredError
NewStructuredError creates a StructuredError with a map of fields (to be copied) and a message
func (*StructuredError) Error ¶
func (se *StructuredError) Error() string
func (*StructuredError) String ¶
func (se *StructuredError) String() string
func (*StructuredError) Unwrap ¶
func (se *StructuredError) Unwrap() error