Documentation ¶
Overview ¶
Package log provides simple log interfaces
Index ¶
- Constants
- Variables
- func SetNoStdErrLogs()
- func SetOptions(opts ...option)
- func Unsubscribe(sub *Subscription)
- func WithCaller(enabled bool) option
- func WithDefaultLevel(level Level) option
- func WithEventSubscriber(fn func(evt Event)) option
- type CallerInfo
- type Encoder
- type Event
- type Field
- func Bool(key string, val bool) Field
- func Caller() Field
- func CallerSkip(skip int) Field
- func Duration(key string, val time.Duration) Field
- func Error(err error) Field
- func Float64(key string, val float64) Field
- func Int(key string, val int) Field
- func Int64(key string, val int64) Field
- func Message(val interface{}) Field
- func Object(key string, val interface{}) Field
- func PID(key string, val fmt.Stringer) Field
- func Stack() Field
- func String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Time(key string, val time.Time) Field
- func TypeOf(key string, val interface{}) Field
- func Uint(key string, val uint) Field
- func Uint64(key string, val uint64) Field
- type Level
- type Logger
- func (l *Logger) Debug(msg string, fields ...Field)
- func (l *Logger) Error(msg string, fields ...Field)
- func (l *Logger) Info(msg string, fields ...Field)
- func (l *Logger) Level() Level
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) Warn(msg string, fields ...Field)
- func (l *Logger) With(fields ...Field) *Logger
- func (l *Logger) WithCaller() *Logger
- type Options
- type Subscription
Constants ¶
const ( MinLevel = Level(iota) DebugLevel InfoLevel WarnLevel ErrorLevel OffLevel DefaultLevel )
Variables ¶
var ( Development = &Options{ logLevel: DebugLevel, enableCaller: true, } Production = &Options{ logLevel: InfoLevel, enableCaller: false, } Current = Production )
Functions ¶
func SetNoStdErrLogs ¶
func SetNoStdErrLogs()
Disables Proto.Actor standard error logs if there is one or more additional log subscribers registered
func SetOptions ¶
func SetOptions(opts ...option)
func Unsubscribe ¶
func Unsubscribe(sub *Subscription)
func WithCaller ¶
func WithCaller(enabled bool) option
WithCaller option will print the file name and line number.
func WithDefaultLevel ¶
func WithDefaultLevel(level Level) option
func WithEventSubscriber ¶
func WithEventSubscriber(fn func(evt Event)) option
WithEventSubscriber option replaces the default Event subscriber with fn.
Specifying nil will disable logging of events.
Types ¶
type CallerInfo ¶
type CallerInfo struct {
// contains filtered or unexported fields
}
func (*CallerInfo) ShortFileName ¶
func (ci *CallerInfo) ShortFileName() string
func (*CallerInfo) String ¶
func (ci *CallerInfo) String() string
type Encoder ¶
type Encoder interface { EncodeBool(key string, val bool) EncodeFloat64(key string, val float64) EncodeInt(key string, val int) EncodeInt64(key string, val int64) EncodeDuration(key string, val time.Duration) EncodeUint(key string, val uint) EncodeUint64(key string, val uint64) EncodeString(key string, val string) EncodeObject(key string, val interface{}) EncodeType(key string, val reflect.Type) EncodeCaller(key string, val CallerInfo) }
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
func CallerSkip ¶
Caller constructs a field with function name and number of line
func Error ¶
Error constructs a Field that lazily stores err.Error() under the key "error". If passed a nil error, the field is skipped.
func Message ¶
func Message(val interface{}) Field
Message constructs a field to store the message under the key message
func Stack ¶
func Stack() Field
Stack constructs a Field that stores a stacktrace under the key "stacktrace".
This is eager and therefore an expensive operation.
func Stringer ¶
Stringer constructs a Field with the given key and the output of the value's String method. The String is not evaluated until encoding.
func Time ¶
Time constructs a Field with the given key and value. It represents a time.Time as a floating-point number of seconds since the Unix epoch.
func TypeOf ¶
TypeOf constructs a field with the given key and an arbitrary object that will log the type information lazily.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) WithCaller ¶
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription is returned from the Subscribe function.
This value and can be passed to Unsubscribe when the observer is no longer interested in receiving messages
func Subscribe ¶
func Subscribe(fn func(evt Event)) *Subscription
func (*Subscription) WithMinLevel ¶
func (s *Subscription) WithMinLevel(level Level) *Subscription
WithMinLevel filter messages below the provided level
For example, setting ErrorLevel will only pass error messages. Setting MinLevel will allow all messages, and is the default.