logger

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package logger contains Funnel's logging code.

Index

Constants

View Source
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.

func SetGRPCLogger

func SetGRPCLogger(l *Logger)

SetGRPCLogger sets the global GRPC logger.

Types

type Formatter

type Formatter logrus.Formatter

Formatter defines a log output formatter.

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

func (l *Logger) Debug(msg string, args ...any)

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

func (l *Logger) Error(msg string, args ...any)

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

func (l *Logger) Info(msg string, args ...any)

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

func (l *Logger) SetFormatter(f Formatter)

SetFormatter sets the formatter of the logger.

func (*Logger) SetLevel

func (l *Logger) SetLevel(lvl string)

SetLevel sets the level of the logger.

func (*Logger) SetOutput

func (l *Logger) SetOutput(o io.Writer)

SetOutput sets the output of the logger.

func (*Logger) Sub

func (l *Logger) Sub(ns string) *Logger

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

func (l *Logger) Warn(msg string, args ...any)

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

func (l *Logger) WithFields(args ...any) *Logger

WithFields returns a new Logger instance with the given fields added to all log messages.

Jump to

Keyboard shortcuts

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