logger

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 22 Imported by: 12

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

View Source
var File_logger_logger_proto protoreflect.FileDescriptor

Functions

func Debug

func Debug(msg string, args ...interface{})

Debug logs debug messages to a global logger.

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 JSONFormatConfig

type JSONFormatConfig struct {
	DisableTimestamp bool   `protobuf:"varint,1,opt,name=disable_timestamp,json=disableTimestamp,proto3" json:"disable_timestamp,omitempty"`
	TimestampFormat  string `protobuf:"bytes,2,opt,name=timestamp_format,json=timestampFormat,proto3" json:"timestamp_format,omitempty"`
	// contains filtered or unexported fields
}

func (*JSONFormatConfig) Descriptor deprecated added in v0.11.4

func (*JSONFormatConfig) Descriptor() ([]byte, []int)

Deprecated: Use JSONFormatConfig.ProtoReflect.Descriptor instead.

func (*JSONFormatConfig) GetDisableTimestamp added in v0.11.4

func (x *JSONFormatConfig) GetDisableTimestamp() bool

func (*JSONFormatConfig) GetTimestampFormat added in v0.11.4

func (x *JSONFormatConfig) GetTimestampFormat() string

func (*JSONFormatConfig) ProtoMessage added in v0.11.4

func (*JSONFormatConfig) ProtoMessage()

func (*JSONFormatConfig) ProtoReflect added in v0.11.4

func (x *JSONFormatConfig) ProtoReflect() protoreflect.Message

func (*JSONFormatConfig) Reset added in v0.11.4

func (x *JSONFormatConfig) Reset()

func (*JSONFormatConfig) String added in v0.11.4

func (x *JSONFormatConfig) String() string

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger handles structured, configurable application logging.

func NewLogger

func NewLogger(ns string, conf *LoggerConfig) *Logger

NewLogger returns a new Logger instance.

func (*Logger) Configure

func (l *Logger) Configure(conf *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.

type LoggerConfig added in v0.11.4

type LoggerConfig struct {
	Level      string            `protobuf:"bytes,1,opt,name=level,proto3" json:"level,omitempty"`
	Formatter  string            `protobuf:"bytes,2,opt,name=formatter,proto3" json:"formatter,omitempty"`
	OutputFile string            `protobuf:"bytes,3,opt,name=output_file,json=outputFile,proto3" json:"output_file,omitempty"`
	JsonFormat *JSONFormatConfig `protobuf:"bytes,4,opt,name=json_format,json=jsonFormat,proto3" json:"json_format,omitempty"`
	TextFormat *TextFormatConfig `protobuf:"bytes,5,opt,name=text_format,json=textFormat,proto3" json:"text_format,omitempty"`
	// contains filtered or unexported fields
}

func DebugConfig

func DebugConfig() *LoggerConfig

DebugConfig returns a Config instance with default values useful for testing/debugging.

func DefaultConfig

func DefaultConfig() *LoggerConfig

DefaultConfig returns a Config instance with default values.

func (*LoggerConfig) Descriptor deprecated added in v0.11.4

func (*LoggerConfig) Descriptor() ([]byte, []int)

Deprecated: Use LoggerConfig.ProtoReflect.Descriptor instead.

func (*LoggerConfig) GetFormatter added in v0.11.4

func (x *LoggerConfig) GetFormatter() string

func (*LoggerConfig) GetJsonFormat added in v0.11.4

func (x *LoggerConfig) GetJsonFormat() *JSONFormatConfig

func (*LoggerConfig) GetLevel added in v0.11.4

func (x *LoggerConfig) GetLevel() string

func (*LoggerConfig) GetOutputFile added in v0.11.4

func (x *LoggerConfig) GetOutputFile() string

func (*LoggerConfig) GetTextFormat added in v0.11.4

func (x *LoggerConfig) GetTextFormat() *TextFormatConfig

func (*LoggerConfig) ProtoMessage added in v0.11.4

func (*LoggerConfig) ProtoMessage()

func (*LoggerConfig) ProtoReflect added in v0.11.4

func (x *LoggerConfig) ProtoReflect() protoreflect.Message

func (*LoggerConfig) Reset added in v0.11.4

func (x *LoggerConfig) Reset()

func (*LoggerConfig) String added in v0.11.4

func (x *LoggerConfig) String() string

type TextFormatConfig

type TextFormatConfig struct {
	ForceColors      bool   `protobuf:"varint,1,opt,name=force_colors,json=forceColors,proto3" json:"force_colors,omitempty"`
	DisableColors    bool   `protobuf:"varint,2,opt,name=disable_colors,json=disableColors,proto3" json:"disable_colors,omitempty"`
	DisableTimestamp bool   `protobuf:"varint,3,opt,name=disable_timestamp,json=disableTimestamp,proto3" json:"disable_timestamp,omitempty"`
	FullTimestamp    bool   `protobuf:"varint,4,opt,name=full_timestamp,json=fullTimestamp,proto3" json:"full_timestamp,omitempty"`
	TimestampFormat  string `protobuf:"bytes,5,opt,name=timestamp_format,json=timestampFormat,proto3" json:"timestamp_format,omitempty"`
	DisableSorting   bool   `protobuf:"varint,6,opt,name=disable_sorting,json=disableSorting,proto3" json:"disable_sorting,omitempty"`
	Indent           string `protobuf:"bytes,7,opt,name=indent,proto3" json:"indent,omitempty"`
	// contains filtered or unexported fields
}

func (*TextFormatConfig) Descriptor deprecated added in v0.11.4

func (*TextFormatConfig) Descriptor() ([]byte, []int)

Deprecated: Use TextFormatConfig.ProtoReflect.Descriptor instead.

func (*TextFormatConfig) GetDisableColors added in v0.11.4

func (x *TextFormatConfig) GetDisableColors() bool

func (*TextFormatConfig) GetDisableSorting added in v0.11.4

func (x *TextFormatConfig) GetDisableSorting() bool

func (*TextFormatConfig) GetDisableTimestamp added in v0.11.4

func (x *TextFormatConfig) GetDisableTimestamp() bool

func (*TextFormatConfig) GetForceColors added in v0.11.4

func (x *TextFormatConfig) GetForceColors() bool

func (*TextFormatConfig) GetFullTimestamp added in v0.11.4

func (x *TextFormatConfig) GetFullTimestamp() bool

func (*TextFormatConfig) GetIndent added in v0.11.4

func (x *TextFormatConfig) GetIndent() string

func (*TextFormatConfig) GetTimestampFormat added in v0.11.4

func (x *TextFormatConfig) GetTimestampFormat() string

func (*TextFormatConfig) ProtoMessage added in v0.11.4

func (*TextFormatConfig) ProtoMessage()

func (*TextFormatConfig) ProtoReflect added in v0.11.4

func (x *TextFormatConfig) ProtoReflect() protoreflect.Message

func (*TextFormatConfig) Reset added in v0.11.4

func (x *TextFormatConfig) Reset()

func (*TextFormatConfig) String added in v0.11.4

func (x *TextFormatConfig) String() string

Jump to

Keyboard shortcuts

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