Documentation ¶
Overview ¶
Package log provides functions that are mainly wrappers for github.com/go-kit/log, but help provide consistent log behavior within the project.
In particular, this package focuses on providing level-based structured logging with the following standardized fields:
- "msg": The main log message
- "ts": Timestamp formatted with time.RFC3339Nano
- "caller": The file and line number (as "file.go:N") that emitted the log
- "error": (ERROR-level logs only) The error that serves as the reason for the log
Index ¶
- func ConfigureLogger(l *Logger, lvl string)
- func Debug(l Logger, msg interface{}, kv ...interface{})
- func Error(l Logger, msg interface{}, err error, kv ...interface{})
- func Errorf(l Logger, msg interface{}, err error, kv ...interface{}) error
- func Info(l Logger, msg interface{}, kv ...interface{})
- func Warn(l Logger, msg interface{}, kv ...interface{})
- func With(logger Logger, keyvals ...interface{}) log.Logger
- func WithPrefix(logger Logger, keyvals ...interface{}) log.Logger
- func WithSuffix(logger Logger, keyvals ...interface{}) log.Logger
- type Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigureLogger ¶
ConfigureLogger configures the Logger pointer with a level-based filter that emits JSON structured logs. lvl may be one of: DEBUG, INFO, WARN, ERROR and is not case-sensitive. The configured logger wil emit logs that always include a "ts"-keyed timestamp value and "caller"-keyed string value in the form "filename.go:lineno" that references where the log occurred.
func Debug ¶
func Debug(l Logger, msg interface{}, kv ...interface{})
Debug logs a message and any keyvals with DEBUG level
func Errorf ¶
Errorf is like Error() but returns a new error that wraps err with msg. It exists to provide brevity/syntactic sugar by allowing callers to handle and log errors in a DRY manner, as demonstrated in the following example:
// myFuncA is functionally equivalent myFuncB func myFuncA(thing string) error { err := doSomething(thing) if err != nil { log.Error(logger, "Error doing something", err, "thing", thing) return fmt.Errorf("Error doing something: %w", err) } return nil } // myFuncB is functionally equivalent to myFuncA func myFuncB(thing string) error { err := doSomething(thing) if err != nil { return log.Errorf(logger, "Error doing something", err, "thing", thing) } return nil }
Note that kvs are included in the log output, but not in the returned error.
func Info ¶
func Info(l Logger, msg interface{}, kv ...interface{})
Info logs a message and any keyvals with INFO level
func Warn ¶
func Warn(l Logger, msg interface{}, kv ...interface{})
Warn logs a message and any keyvals with WARN level
func WithPrefix ¶
WithPrefix is a wrapper for log.WithPrefix() and exists to provide brevity/syntactic sugar. This function has no effect on JSON log output.
func WithSuffix ¶
WithSuffix is a wrapper for log.WithSuffix() and exists to provide brevity/syntactic sugar. This function has no effect on JSON log output.