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) Debugf(format string, v ...any)
- func (b *Buffer) Errorf(format string, v ...any)
- func (b *Buffer) Fatalf(format string, v ...any)
- func (b *Buffer) Infof(format string, v ...any)
- func (b *Buffer) Level() Level
- func (b *Buffer) Noticef(format string, v ...any)
- func (b *Buffer) SetLevel(level Level)
- func (b *Buffer) Warnf(format string, v ...any)
- func (b *Buffer) WithFields(fields ...Field) Logger
- type ConsoleLogger
- func (l *ConsoleLogger) Debugf(format string, v ...any)
- func (l *ConsoleLogger) Errorf(format string, v ...any)
- func (l *ConsoleLogger) Fatalf(format string, v ...any)
- func (l *ConsoleLogger) Infof(format string, v ...any)
- func (l *ConsoleLogger) Level() Level
- func (l *ConsoleLogger) Noticef(format string, v ...any)
- func (l *ConsoleLogger) SetLevel(level Level)
- func (l *ConsoleLogger) Warnf(format string, v ...any)
- func (l *ConsoleLogger) WithFields(fields ...Field) Logger
- type DeprecatedLogger
- func (d DeprecatedLogger) Debug(format string, v ...any)
- func (d DeprecatedLogger) Error(format string, v ...any)
- func (d DeprecatedLogger) Fatal(format string, v ...any)
- func (d DeprecatedLogger) Info(format string, v ...any)
- func (d DeprecatedLogger) Notice(format string, v ...any)
- func (d DeprecatedLogger) Warn(format string, v ...any)
- type Field
- type Fields
- type GenericField
- type JSONPrinter
- type Level
- type Logger
- type Printer
- type TestPrinter
- type TextPrinter
Constants ¶
const (
DateFormat = "2006-01-02 15:04:05"
)
Variables ¶
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
// contains filtered or unexported fields
}
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) Debugf ¶ added in v3.125.0
func (l *ConsoleLogger) Debugf(format string, v ...any)
func (*ConsoleLogger) Errorf ¶ added in v3.125.0
func (l *ConsoleLogger) Errorf(format string, v ...any)
func (*ConsoleLogger) Fatalf ¶ added in v3.125.0
func (l *ConsoleLogger) Fatalf(format string, v ...any)
func (*ConsoleLogger) Infof ¶ added in v3.125.0
func (l *ConsoleLogger) Infof(format string, v ...any)
func (*ConsoleLogger) Level ¶
func (l *ConsoleLogger) Level() Level
func (*ConsoleLogger) Noticef ¶ added in v3.125.0
func (l *ConsoleLogger) Noticef(format string, v ...any)
func (*ConsoleLogger) SetLevel ¶
func (l *ConsoleLogger) SetLevel(level Level)
SetLevel sets the level in the logger
func (*ConsoleLogger) Warnf ¶ added in v3.125.0
func (l *ConsoleLogger) Warnf(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 DeprecatedLogger ¶ added in v3.125.0
type DeprecatedLogger struct {
Logger
}
DeprecatedLogger wraps the logger with the deprecated (no trailing "f") method names.
func (DeprecatedLogger) Debug ¶ added in v3.125.0
func (d DeprecatedLogger) Debug(format string, v ...any)
func (DeprecatedLogger) Error ¶ added in v3.125.0
func (d DeprecatedLogger) Error(format string, v ...any)
func (DeprecatedLogger) Fatal ¶ added in v3.125.0
func (d DeprecatedLogger) Fatal(format string, v ...any)
func (DeprecatedLogger) Info ¶ added in v3.125.0
func (d DeprecatedLogger) Info(format string, v ...any)
func (DeprecatedLogger) Notice ¶ added in v3.125.0
func (d DeprecatedLogger) Notice(format string, v ...any)
func (DeprecatedLogger) Warn ¶ added in v3.125.0
func (d DeprecatedLogger) Warn(format string, v ...any)
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 {
Debugf(format string, v ...any)
Errorf(format string, v ...any)
Fatalf(format string, v ...any)
Noticef(format string, v ...any)
Warnf(format string, v ...any)
Infof(format string, v ...any)
WithFields(fields ...Field) Logger
SetLevel(level Level)
Level() Level
}
func NewConsoleLogger ¶
type TestPrinter ¶ added in v3.93.0
type TestPrinter struct {
// contains filtered or unexported fields
}
TestPrinter is a log printer than calls the Logf method of a testing.T or testing.B.
func NewTestPrinter ¶ added in v3.93.0
func NewTestPrinter(tb testing.TB) TestPrinter
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