Documentation
¶
Overview ¶
Package logger contains Funnel's logging code.
Index ¶
- Constants
- func ArgListToMap(args ...interface{}) map[string]interface{}
- func Debug(msg string, args ...interface{})
- func DebugConfig() *logconfig.LoggerConfig
- func DefaultConfig() *logconfig.LoggerConfig
- func PrintSimpleError(err error)
- func SetGRPCLogger(l *Logger)
- type Formatter
- type Logger
- func (l *Logger) Configure(conf *logconfig.LoggerConfig)
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) Discard()
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) SetFormatter(f Formatter)
- func (l *Logger) SetLevel(lvl string)
- func (l *Logger) SetOutput(o io.Writer)
- func (l *Logger) Sub(ns string) *Logger
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WithFields(args ...any) *Logger
Constants ¶
const ( DebugLevel = "debug" InfoLevel = "info" ErrorLevel = "error" WarnLevel = "warn" )
Log levels
Variables ¶
This section is empty.
Functions ¶
func ArgListToMap ¶
func ArgListToMap(args ...interface{}) map[string]interface{}
ArgListToMap converts an argument list to a map, e.g. ("key", value, "key2", value2) => {"key": value, "key2", value2}
func Debug ¶
func Debug(msg string, args ...interface{})
Debug logs debug messages to a global logger.
func DebugConfig ¶
func DebugConfig() *logconfig.LoggerConfig
DebugConfig returns a Config instance with default values useful for testing/debugging.
func DefaultConfig ¶
func DefaultConfig() *logconfig.LoggerConfig
DefaultConfig returns a Config instance with default values.
func PrintSimpleError ¶
func PrintSimpleError(err error)
PrintSimpleError prints out an error message with a red "ERROR:" prefix.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger handles structured, configurable application logging.
func NewLogger ¶
func NewLogger(ns string, conf *logconfig.LoggerConfig) *Logger
NewLogger returns a new Logger instance.
func (*Logger) Configure ¶
func (l *Logger) Configure(conf *logconfig.LoggerConfig)
Configure configures the logging level and output path.
func (*Logger) Debug ¶
Debug logs a debug message.
After the first argument, arguments are key-value pairs which are written as structured logs.
log.Debug("Some message here", "key1", value1, "key2", value2)
func (*Logger) Discard ¶
func (l *Logger) Discard()
Discard configures the logger to discard all logs.
func (*Logger) Error ¶
Error logs an error message
After the first argument, arguments are key-value pairs which are written as structured logs.
log.Error("Some message here", "key1", value1, "key2", value2)
Error has a two-argument version that can be used as a shortcut.
err := startServer()
log.Error("Couldn't start server", err)
func (*Logger) Info ¶
Info logs an info message
After the first argument, arguments are key-value pairs which are written as structured logs.
log.Info("Some message here", "key1", value1, "key2", value2)
func (*Logger) SetFormatter ¶
SetFormatter sets the formatter of the logger.
func (*Logger) Sub ¶
Sub is a shortcut for l.WithFields("ns", ns), it creates a new logger which inherits the parent's configuration but changes the namespace.
func (*Logger) Warn ¶
Warn logs an warning message
After the first argument, arguments are key-value pairs which are written as structured logs.
log.Info("Some message here", "key1", value1, "key2", value2)
func (*Logger) WithFields ¶
WithFields returns a new Logger instance with the given fields added to all log messages.