Documentation
¶
Overview ¶
Package logger contains Funnel's logging code.
Index ¶
- Constants
- Variables
- func Debug(msg string, args ...interface{})
- func PrintSimpleError(err error)
- func SetGRPCLogger(l *Logger)
- type Formatter
- type JSONFormatConfig
- func (*JSONFormatConfig) Descriptor() ([]byte, []int)deprecated
- func (x *JSONFormatConfig) GetDisableTimestamp() bool
- func (x *JSONFormatConfig) GetTimestampFormat() string
- func (*JSONFormatConfig) ProtoMessage()
- func (x *JSONFormatConfig) ProtoReflect() protoreflect.Message
- func (x *JSONFormatConfig) Reset()
- func (x *JSONFormatConfig) String() string
- type Logger
- func (l *Logger) Configure(conf *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
- type LoggerConfig
- func (*LoggerConfig) Descriptor() ([]byte, []int)deprecated
- func (x *LoggerConfig) GetFormatter() string
- func (x *LoggerConfig) GetJsonFormat() *JSONFormatConfig
- func (x *LoggerConfig) GetLevel() string
- func (x *LoggerConfig) GetOutputFile() string
- func (x *LoggerConfig) GetTextFormat() *TextFormatConfig
- func (*LoggerConfig) ProtoMessage()
- func (x *LoggerConfig) ProtoReflect() protoreflect.Message
- func (x *LoggerConfig) Reset()
- func (x *LoggerConfig) String() string
- type TextFormatConfig
- func (*TextFormatConfig) Descriptor() ([]byte, []int)deprecated
- func (x *TextFormatConfig) GetDisableColors() bool
- func (x *TextFormatConfig) GetDisableSorting() bool
- func (x *TextFormatConfig) GetDisableTimestamp() bool
- func (x *TextFormatConfig) GetForceColors() bool
- func (x *TextFormatConfig) GetFullTimestamp() bool
- func (x *TextFormatConfig) GetIndent() string
- func (x *TextFormatConfig) GetTimestampFormat() string
- func (*TextFormatConfig) ProtoMessage()
- func (x *TextFormatConfig) ProtoReflect() protoreflect.Message
- func (x *TextFormatConfig) Reset()
- func (x *TextFormatConfig) String() string
Constants ¶
const ( DebugLevel = "debug" InfoLevel = "info" ErrorLevel = "error" WarnLevel = "warn" )
Log levels
Variables ¶
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.
Types ¶
type JSONFormatConfig ¶
type JSONFormatConfig struct {
DisableTimestamp bool `protobuf:"varint,1,opt,name=DisableTimestamp,proto3" json:"DisableTimestamp,omitempty"`
TimestampFormat string `protobuf:"bytes,2,opt,name=TimestampFormat,proto3" json:"TimestampFormat,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 ¶
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.
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=OutputFile,proto3" json:"OutputFile,omitempty"`
JsonFormat *JSONFormatConfig `protobuf:"bytes,4,opt,name=JsonFormat,proto3" json:"JsonFormat,omitempty"`
TextFormat *TextFormatConfig `protobuf:"bytes,5,opt,name=TextFormat,proto3" json:"TextFormat,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=ForceColors,proto3" json:"ForceColors,omitempty"`
DisableColors bool `protobuf:"varint,2,opt,name=DisableColors,proto3" json:"DisableColors,omitempty"`
DisableTimestamp bool `protobuf:"varint,3,opt,name=DisableTimestamp,proto3" json:"DisableTimestamp,omitempty"`
FullTimestamp bool `protobuf:"varint,4,opt,name=FullTimestamp,proto3" json:"FullTimestamp,omitempty"`
TimestampFormat string `protobuf:"bytes,5,opt,name=TimestampFormat,proto3" json:"TimestampFormat,omitempty"`
DisableSorting bool `protobuf:"varint,6,opt,name=DisableSorting,proto3" json:"DisableSorting,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