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 RemoveHandler(h Handler)
- func RemoveHandlerLevels(h Handler, levels ...Level)
- 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 Builder
- 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 ( // 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 RemoveHandlerLevels ¶
RemoveHandlerLevels removes the supplied levels, if no more levels exists for the handler it will no longer be registered and need to added via AddHandler again.
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
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 Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is used to create a new console logger
func NewBuilder ¶
func NewBuilder() *Builder
NewBuilder creates a new Builder for configuring and creating a new console logger
func (*Builder) WithGoSTDErrLogs ¶
func (*Builder) WithTimestampFormat ¶
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 (*Level) UnmarshalJSON ¶
UnmarshalJSON implementation.
Directories
¶
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
basic
command
|
|
|
custom-handler
command
|
|
|
handlers
|
|
|
json
Package json implements a JSON handler.
|
Package json implements a JSON handler. |
