Documentation ¶
Overview ¶
Package logger provides a logger abstraction for writing log messages in configurable formats to different outputs, such as a console, plain text file, or a JSON file.
It is intended for internal use by buildkite-agent only.
Index ¶
- Constants
- Variables
- func ColorsSupported() bool
- type Buffer
- func (b *Buffer) Debug(format string, v ...any)
- func (b *Buffer) Error(format string, v ...any)
- func (b *Buffer) Fatal(format string, v ...any)
- func (b *Buffer) Info(format string, v ...any)
- func (b *Buffer) Level() Level
- func (b *Buffer) Notice(format string, v ...any)
- func (b *Buffer) SetLevel(level Level)
- func (b *Buffer) Warn(format string, v ...any)
- func (b *Buffer) WithFields(fields ...Field) Logger
- type ConsoleLogger
- func (l *ConsoleLogger) Debug(format string, v ...any)
- func (l *ConsoleLogger) Error(format string, v ...any)
- func (l *ConsoleLogger) Fatal(format string, v ...any)
- func (l *ConsoleLogger) Info(format string, v ...any)
- func (l *ConsoleLogger) Level() Level
- func (l *ConsoleLogger) Notice(format string, v ...any)
- func (l *ConsoleLogger) SetLevel(level Level)
- func (l *ConsoleLogger) Warn(format string, v ...any)
- func (l *ConsoleLogger) WithFields(fields ...Field) Logger
- type Field
- type Fields
- type GenericField
- type JSONPrinter
- type Level
- type Logger
- type Printer
- type TextPrinter
Constants ¶
View Source
const (
DateFormat = "2006-01-02 15:04:05"
)
Variables ¶
View Source
var Discard = &ConsoleLogger{ printer: &TextPrinter{ Writer: io.Discard, }, }
Functions ¶
func ColorsSupported ¶
func ColorsSupported() bool
Types ¶
type Buffer ¶ added in v3.24.0
type Buffer struct {
Messages []string
}
Buffer is a Logger implementation intended for testing; messages are stored internally.
func NewBuffer ¶ added in v3.25.0
func NewBuffer() *Buffer
NewBuffer creates a new Buffer with Messages slice initialized. This makes it simpler to assert empty []string when no log messages have been sent; otherwise Messages would be nil.
func (*Buffer) WithFields ¶ added in v3.24.0
type ConsoleLogger ¶
type ConsoleLogger struct {
// contains filtered or unexported fields
}
func (*ConsoleLogger) Debug ¶
func (l *ConsoleLogger) Debug(format string, v ...any)
func (*ConsoleLogger) Error ¶
func (l *ConsoleLogger) Error(format string, v ...any)
func (*ConsoleLogger) Fatal ¶
func (l *ConsoleLogger) Fatal(format string, v ...any)
func (*ConsoleLogger) Info ¶
func (l *ConsoleLogger) Info(format string, v ...any)
func (*ConsoleLogger) Level ¶
func (l *ConsoleLogger) Level() Level
func (*ConsoleLogger) Notice ¶
func (l *ConsoleLogger) Notice(format string, v ...any)
func (*ConsoleLogger) SetLevel ¶
func (l *ConsoleLogger) SetLevel(level Level)
SetLevel sets the level in the logger
func (*ConsoleLogger) Warn ¶
func (l *ConsoleLogger) Warn(format string, v ...any)
func (*ConsoleLogger) WithFields ¶
func (l *ConsoleLogger) WithFields(fields ...Field) Logger
WithFields returns a copy of the logger with the provided fields
type Field ¶
func StringField ¶
type GenericField ¶
type GenericField struct {
// contains filtered or unexported fields
}
func (GenericField) Key ¶
func (f GenericField) Key() string
func (GenericField) String ¶
func (f GenericField) String() string
type JSONPrinter ¶
func NewJSONPrinter ¶
func NewJSONPrinter(w io.Writer) *JSONPrinter
type Logger ¶
type Logger interface { Debug(format string, v ...any) Error(format string, v ...any) Fatal(format string, v ...any) Notice(format string, v ...any) Warn(format string, v ...any) Info(format string, v ...any) WithFields(fields ...Field) Logger SetLevel(level Level) Level() Level }
func NewConsoleLogger ¶
type TextPrinter ¶
type TextPrinter struct { Colors bool Writer io.Writer IsPrefixFn func(Field) bool IsVisibleFn func(Field) bool }
func NewTextPrinter ¶
func NewTextPrinter(w io.Writer) *TextPrinter
Click to show internal directories.
Click to hide internal directories.