Documentation
¶
Index ¶
- Constants
- Variables
- func AddHandler(h Handler, levels ...Level)
- func Alert(v ...interface{})
- func Alertf(s string, v ...interface{})
- func BytePool() *byteArrayPool
- func Debug(v ...interface{})
- func Debugf(s string, v ...interface{})
- func Error(v ...interface{})
- func Errorf(s string, v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(s string, v ...interface{})
- func HandleEntry(e Entry)
- func Info(v ...interface{})
- func Infof(s string, v ...interface{})
- func Notice(v ...interface{})
- func Noticef(s string, v ...interface{})
- func Panic(v ...interface{})
- func Panicf(s string, v ...interface{})
- func RedirectGoStdLog(redirect bool)
- func RemoveHandler(h Handler)
- func SetContext(ctx context.Context, e Entry) context.Context
- func SetExitFunc(fn func(code int))
- func SetWithErrorFn(fn func(Entry, error) Entry)
- func Warn(v ...interface{})
- func Warnf(s string, v ...interface{})
- func WithDefaultFields(fields ...Field)
- type Buffer
- type ConsoleBuilder
- type Entry
- func (e Entry) Alert(v ...interface{})
- func (e Entry) Alertf(s string, v ...interface{})
- func (e Entry) Debug(v ...interface{})
- func (e Entry) Debugf(s string, v ...interface{})
- func (e Entry) Error(v ...interface{})
- func (e Entry) Errorf(s string, v ...interface{})
- func (e Entry) Fatal(v ...interface{})
- func (e Entry) Fatalf(s string, v ...interface{})
- func (e Entry) Info(v ...interface{})
- func (e Entry) Infof(s string, v ...interface{})
- func (e Entry) Notice(v ...interface{})
- func (e Entry) Noticef(s string, v ...interface{})
- func (e Entry) Panic(v ...interface{})
- func (e Entry) Panicf(s string, v ...interface{})
- func (e Entry) Warn(v ...interface{})
- func (e Entry) Warnf(s string, v ...interface{})
- func (e Entry) WithError(err error) Entry
- func (e Entry) WithField(key string, value interface{}) Entry
- func (e Entry) WithFields(fields ...Field) Entry
- func (e Entry) WithTrace() Entry
- type Field
- type Fields
- type Handler
- type Level
- type Logger
Constants ¶
const ( SlogDebugLevel slog.Level = slog.LevelDebug SlogInfoLevel slog.Level = slog.LevelInfo SlogWarnLevel slog.Level = slog.LevelWarn SlogErrorLevel slog.Level = slog.LevelError SlogNoticeLevel slog.Level = slog.LevelInfo + 2 SlogPanicLevel slog.Level = slog.LevelError + 4 SlogAlertLevel slog.Level = SlogPanicLevel + 4 SlogFatalLevel slog.Level = SlogAlertLevel + 4 // same as syslog CRITICAL )
slog log levels.
const ( // DefaultTimeFormat is the default time format when parsing Time values. // it is exposed to allow handlers to use and not have to redefine DefaultTimeFormat = "2006-01-02T15:04:05.000000000Z07:00" // RFC3339Nano )
Variables ¶
var AllLevels = []Level{ DebugLevel, InfoLevel, NoticeLevel, WarnLevel, ErrorLevel, PanicLevel, AlertLevel, FatalLevel, }
AllLevels is an array of all log levels, for easier registering of all levels to a handler
Functions ¶
func AddHandler ¶
AddHandler adds a new log handlers and accepts which log levels that handlers will be triggered for
func Alertf ¶
func Alertf(s string, v ...interface{})
Alertf logs an alert log entry with formatting
func BytePool ¶
func BytePool() *byteArrayPool
BytePool returns a sync.Pool of bytes that multiple handlers can use in order to reduce allocation and keep a central copy for reuse.
func Errorf ¶
func Errorf(s string, v ...interface{})
Errorf logs an error log entry with formatting
func HandleEntry ¶
func HandleEntry(e Entry)
HandleEntry handles the log entry and fans out to all handlers with the proper log level This is exposed to allow for centralized logging whereby the log entry is marshalled, passed to a central logging server, unmarshalled and finally fanned out from there.
func Infof ¶
func Infof(s string, v ...interface{})
Infof logs a normal. information, entry with formatting
func Noticef ¶
func Noticef(s string, v ...interface{})
Noticef logs a notice log entry with formatting
func RedirectGoStdLog ¶
func RedirectGoStdLog(redirect bool)
RedirectGoStdLog is used to redirect Go's internal std log output to this logger AND registers a handler for slog that redirects slog output to this logger.
If you intend to use this log interface with another slog handler then you should not use this function and instead register a handler with slog directly and register the slog redirect, found under the handlers package or other custom redirect handler with this logger.
func SetContext ¶
SetContext sets a log entry into the provided context
func SetExitFunc ¶
func SetExitFunc(fn func(code int))
SetExitFunc sets the provided function as the exit function used in Fatal(), Fatalf(), Panic() and Panicf(). This is primarily used when wrapping this library, you can set this to enable testing (with coverage) of your Fatal() and Fatalf() methods.
func SetWithErrorFn ¶
SetWithErrorFn sets a custom WithError function handlers
func WithDefaultFields ¶
func WithDefaultFields(fields ...Field)
WithDefaultFields adds fields to the underlying logger instance that will be automatically added to ALL log entries.
Types ¶
type Buffer ¶
type Buffer struct {
B []byte
}
Buffer is a mere wrapper for a byte slice. It is intended to be used by Handlers.
type ConsoleBuilder ¶
type ConsoleBuilder struct {
// contains filtered or unexported fields
}
ConsoleBuilder is used to create a new console logger
func NewConsoleBuilder ¶
func NewConsoleBuilder() *ConsoleBuilder
NewConsoleBuilder creates a new ConsoleBuilder for configuring and creating a new console logger
func (*ConsoleBuilder) Build ¶
func (b *ConsoleBuilder) Build() *Logger
func (*ConsoleBuilder) WithTimestampFormat ¶
func (b *ConsoleBuilder) WithTimestampFormat(format string) *ConsoleBuilder
func (*ConsoleBuilder) WithWriter ¶
func (b *ConsoleBuilder) WithWriter(writer io.Writer) *ConsoleBuilder
type Entry ¶
type Entry struct { Message string `json:"message"` Timestamp time.Time `json:"timestamp"` Fields []Field `json:"fields"` Level Level `json:"level"` // contains filtered or unexported fields }
Entry defines a single log entry
func GetContext ¶
GetContext returns the log Entry found in the context, or a new Default log Entry if none is found
func WithFields ¶
WithFields returns a new log entry with the supplied fields appended
func WithTrace ¶
func WithTrace() Entry
WithTrace with add duration of how long the between this function call and the subsequent log
func (Entry) WithFields ¶
WithFields returns a new log entry with the supplied fields appended
type Field ¶
type Field struct { Key string `json:"key"` Value interface{} `json:"value"` }
Field is a single Field key and value
type Handler ¶
type Handler interface {
Log(Entry)
}
Handler is an interface that log handlers need to comply with
type Level ¶
type Level uint8
Level of the log
const ( DebugLevel Level = iota InfoLevel NoticeLevel WarnLevel ErrorLevel PanicLevel AlertLevel FatalLevel // same as syslog CRITICAL )
Log levels.
func ParseLevel ¶
ParseLevel parses the provided strings log level or if not supported return 255
func (*Level) UnmarshalJSON ¶
UnmarshalJSON implementation.