Documentation
¶
Index ¶
- type BatchWriter
- type Instance
- type KeyValueAppender
- type Logger
- func (l *Logger) Debug(msg string, args ...any) identifier.ID
- func (l *Logger) Debugf(format string, args ...any) identifier.ID
- func (l *Logger) Error(msg string, args ...any) identifier.ID
- func (l *Logger) Errorf(format string, args ...any) identifier.ID
- func (l *Logger) Info(msg string, args ...any) identifier.ID
- func (l *Logger) Infof(format string, args ...any) identifier.ID
- func (l *Logger) Recover()
- func (l *Logger) Release()
- func (l *Logger) Warn(msg string, args ...any) identifier.ID
- func (l *Logger) Warnf(format string, args ...any) identifier.ID
- func (l *Logger) With(args ...any) *Logger
- type Options
- type Severity
- type WriteBehavior
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BatchWriter ¶
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
func NewInstance ¶
Create a logger instance used for acquiring loggers.
type KeyValueAppender ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
A logger with optional meta data, which every log entry will inherit.
func (*Logger) Debug ¶
func (l *Logger) Debug(msg string, args ...any) identifier.ID
Logs a new entry of "Debug" severity, with optional meta data. Example usage:
log.Debug("hello world",
"myKey", "myValue",
"otherKey", 123,
)
func (*Logger) Debugf ¶
func (l *Logger) Debugf(format string, args ...any) identifier.ID
Logs a new entry of "Debug" severity, with a formatted (printf) message. Example usage:
log.Debugf("the number is %d", 123)
func (*Logger) Error ¶
func (l *Logger) Error(msg string, args ...any) identifier.ID
Logs a new entry of "Error" severity, with optional meta data. Example usage:
log.Error("hello world",
"myKey", "myValue",
"otherKey", 123,
)
func (*Logger) Errorf ¶
func (l *Logger) Errorf(format string, args ...any) identifier.ID
Logs a new entry of "Error" severity, with a formatted (printf) message. Example usage:
log.Errorf("the number is %d", 123)
func (*Logger) Info ¶
func (l *Logger) Info(msg string, args ...any) identifier.ID
Logs a new entry of "Info" severity, with optional meta data. Example usage:
log.Info("hello world",
"myKey", "myValue",
"otherKey", 123,
)
func (*Logger) Infof ¶
func (l *Logger) Infof(format string, args ...any) identifier.ID
Logs a new entry of "Info" severity, with a formatted (printf) message. Example usage:
log.Infof("the number is %d", 123)
func (*Logger) Recover ¶
func (l *Logger) Recover()
Recovers from a panic and logs it as a critical error. Usage:
go func() {
defer log.Recover()
panic("aaaaaahh")
}()
Example ¶
inst, err := NewInstance(io.Discard)
if err != nil {
log.Fatal(err)
}
log := inst.Logger()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
defer log.Recover()
panic("aaaaaahh")
}()
wg.Wait()
func (*Logger) Warn ¶
func (l *Logger) Warn(msg string, args ...any) identifier.ID
Logs a new entry of "Warning" severity, with optional meta data. Example usage:
log.Warn("hello world",
"myKey", "myValue",
"otherKey", 123,
)
type WriteBehavior ¶
type WriteBehavior uint8
const ( // Any writes to a full buffer will block. // This guarantees that no logs are lost, but might block the application // until there is room in the buffer. This also means that if the client // can't write any logs at all, the application might get locked. For this // reason, this option is discouraged for clients dependent on remote hosts. Block WriteBehavior = iota // Any writes to a full buffer will be dropped immediately. // This guarantees that the application will never be blocked by logging, // but also means that log messages might be lost during busy times. Loose // Any writes to a full buffer will fallback to a compressed, disk-based // ping-pong buffer and retried later. // This guarantees that no logs neither lost nor blocking the application, but // also requires that the client implements the BatchWriter interface. This // should be the prefered option when possible. Fallback )