Documentation ¶
Overview ¶
Package lion provides structured logging, configurable to use serialization protocols such as Protocol Buffers.
Index ¶
- Variables
- func AddGlobalHook(globalHook GlobalHook)
- func DebugWriter() io.Writer
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func ErrorWriter() io.Writer
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func Flush() error
- func InfoWriter() io.Writer
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func Panicf(format string, args ...interface{})
- func Panicln(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func RedirectStdLogger()
- func RegisterEncoderDecoder(encoding string, encoderDecoder EncoderDecoder) error
- func SetJSONMarshalFunc(jsonMarshalFunc JSONMarshalFunc)
- func SetLevel(level Level)
- func SetLogger(logger Logger)
- func WarnWriter() io.Writer
- func Warnf(format string, args ...interface{})
- func Warnln(args ...interface{})
- func Writer() io.Writer
- type BaseLevelLogger
- type BaseLogger
- type Decoder
- type EncodedEntry
- type EncodedEntryMessage
- type EncodedPusher
- type Encoder
- type EncoderDecoder
- type Entry
- type EntryMessage
- type ErrorHandler
- type Flusher
- type GlobalHook
- type IDAllocator
- type JSONMarshalFunc
- type JSONMarshallerOption
- type Level
- type LevelLogger
- type Logger
- type LoggerOption
- type Marshaller
- type Puller
- type Pusher
- func EncodedPusherToPusher(encodedPusher EncodedPusher) Pusher
- func NewJSONWritePusher(writer io.Writer, jsonMarshallerOptions ...JSONMarshallerOption) Pusher
- func NewMultiPusher(pushers ...Pusher) Pusher
- func NewTextWritePusher(writer io.Writer, textMarshallerOptions ...TextMarshallerOption) Pusher
- func NewWritePusher(writer io.Writer, marshaller Marshaller) Pusher
- type TextMarshaller
- type TextMarshallerOption
- type Timer
- type Unmarshaller
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultLevel is the default Level. DefaultLevel = LevelInfo // DefaultIDAllocator is the default IDAllocator. DefaultIDAllocator = &idAllocator{instanceID, 0} // DefaultTimer is the default Timer. DefaultTimer = &timer{} // DefaultErrorHandler is the default ErrorHandler. DefaultErrorHandler = &errorHandler{} // DefaultJSONMarshalFunc is the default JSONMarshalFunc. DefaultJSONMarshalFunc = func(writer io.Writer, value interface{}) error { data, err := json.Marshal(value) if err != nil { return err } _, err = writer.Write(data) return err } // DefaultJSONMarshaller is the default JSON Marshaller. DefaultJSONMarshaller = NewJSONMarshaller() // DiscardPusher is a Pusher that discards all logs. DiscardPusher = discardPusherInstance // DiscardLogger is a Logger that discards all logs. DiscardLogger = NewLogger(DiscardPusher) // DefaultPusher is the default Pusher. DefaultPusher = NewTextWritePusher(os.Stderr) // DefaultLogger is the default Logger. DefaultLogger = NewLogger(DefaultPusher) )
Functions ¶
func AddGlobalHook ¶
func AddGlobalHook(globalHook GlobalHook)
AddGlobalHook adds a GlobalHook that will be called any time SetLogger or SetLevel is called. It will also be called when added.
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf calls Debugf on the global Logger.
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf calls Errorf on the global Logger.
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf calls Fatalf on the global Logger.
func Panicf ¶
func Panicf(format string, args ...interface{})
Panicf calls Panicf on the global Logger.
func Printf ¶
func Printf(format string, args ...interface{})
Printf calls Printf on the global Logger.
func RedirectStdLogger ¶
func RedirectStdLogger()
RedirectStdLogger will redirect logs to golang's standard logger to the global Logger instance.
func RegisterEncoderDecoder ¶
func RegisterEncoderDecoder(encoding string, encoderDecoder EncoderDecoder) error
RegisterEncoderDecoder registers an EncoderDecoder by encoding.
func SetJSONMarshalFunc ¶
func SetJSONMarshalFunc(jsonMarshalFunc JSONMarshalFunc)
SetJSONMarshalFunc sets the global JSONMarshalFunc to be used by default.
Types ¶
type BaseLevelLogger ¶
type BaseLevelLogger interface { Printf(format string, args ...interface{}) Println(args ...interface{}) }
BaseLevelLogger is a LevelLogger without the methods that are self-returning.
This is so sub-packages can implement these.
type BaseLogger ¶
type BaseLogger interface { Flusher Level() Level DebugWriter() io.Writer InfoWriter() io.Writer WarnWriter() io.Writer ErrorWriter() io.Writer Writer() io.Writer Debugf(format string, args ...interface{}) Debugln(args ...interface{}) Infof(format string, args ...interface{}) Infoln(args ...interface{}) Warnf(format string, args ...interface{}) Warnln(args ...interface{}) Errorf(format string, args ...interface{}) Errorln(args ...interface{}) Fatalf(format string, args ...interface{}) Fatalln(args ...interface{}) Panicf(format string, args ...interface{}) Panicln(args ...interface{}) Printf(format string, args ...interface{}) Println(args ...interface{}) }
BaseLogger is a Logger without the methods that are self-returning.
This is so sub-packages can implement these.
type Decoder ¶
type Decoder interface {
Decode(encodedEntryMessage *EncodedEntryMessage) (*EntryMessage, error)
}
Decoder decodes EntryMessages.
type EncodedEntry ¶
type EncodedEntry struct { // ID may not be set depending on LoggerOptions. // it is up to the user to determine if ID is required. ID string `json:"id,omitempty"` Level Level `json:"level,omitempty"` Time time.Time `json:"time,omitempty"` // both Contexts and Fields can be set Contexts []*EncodedEntryMessage `json:"contexts,omitempty"` Fields map[string]string `json:"fields,omitempty"` // zero or one of Event, Message, WriterOutput will be set Event *EncodedEntryMessage `json:"event,omitempty"` Message string `json:"message,omitempty"` WriterOutput []byte `json:"writer_output,omitempty"` }
EncodedEntry is an encoded log entry.
func (*EncodedEntry) Decode ¶
func (e *EncodedEntry) Decode() (*Entry, error)
Decode decodes an encoded Entry.
type EncodedEntryMessage ¶
type EncodedEntryMessage struct { // Encoding specifies the encoding, such as "json", "protobuf", "thrift". Encoding string `json:"encoding,omitempty"` // Name specifies the globally-unique name of the message type, such as "google.protobuf.Timestamp". Name string `json:"name,omitempty"` // Value is the encoded value. Value []byte `json:"value,omitempty"` }
EncodedEntryMessage is an encoded EntryMessage.
func (*EncodedEntryMessage) Decode ¶
func (e *EncodedEntryMessage) Decode() (*EntryMessage, error)
Decode decodes an encoded EntryMessage.
type EncodedPusher ¶
type EncodedPusher interface { Flusher Push(encodedEntry *EncodedEntry) error }
EncodedPusher pushes EncodedEntry objects.
type Encoder ¶
type Encoder interface { Encode(entryMessage *EntryMessage) (*EncodedEntryMessage, error) // Name just gets the globally-unique name for an EntryMessage. Name(entryMessage *EntryMessage) (string, error) }
Encoder encodes EntryMessages.
type EncoderDecoder ¶
EncoderDecoder is an Encoder and Decoarder.
type Entry ¶
type Entry struct { // ID may not be set depending on LoggerOptions. // it is up to the user to determine if ID is required. ID string `json:"id,omitempty"` Level Level `json:"level,omitempty"` Time time.Time `json:"time,omitempty"` // both Contexts and Fields can be set Contexts []*EntryMessage `json:"contexts,omitempty"` Fields map[string]string `json:"fields,omitempty"` // zero or one of Event, Message, WriterOutput will be set Event *EntryMessage `json:"event,omitempty"` Message string `json:"message,omitempty"` WriterOutput []byte `json:"writer_output,omitempty"` }
Entry is a log entry.
type EntryMessage ¶
type EntryMessage struct { // Encoding specifies the encoding to use, if converting to an EncodedEntryMessage, such as "json", "protobuf", "thrift". Encoding string `json:"encoding,omitempty"` // Value is the unmarshalled value to use. It is expected that Value can be marshalled to JSON. Value interface{} `json:"value,omitempty"` }
EntryMessage is a context or event in an Entry. It has different meanings depending on what state it is in.
func (*EntryMessage) Encode ¶
func (e *EntryMessage) Encode() (*EncodedEntryMessage, error)
Encode encodes an EntryMessage.
func (*EntryMessage) Name ¶
func (e *EntryMessage) Name() (string, error)
Name gets the globally-unique name for an EntryMessge.
type ErrorHandler ¶
type ErrorHandler interface {
Handle(err error)
}
ErrorHandler handles errors when logging. The default behavior is to panic.
type Flusher ¶
type Flusher interface {
Flush() error
}
Flusher is an object that can be flushed to a persistent store.
type GlobalHook ¶
type GlobalHook func(Logger)
GlobalHook is a function that handles a change in the global Logger instance.
type IDAllocator ¶
type IDAllocator interface {
Allocate() string
}
IDAllocator allocates unique IDs for Entry objects. The default behavior is to allocate a new UUID for the process, then add an incremented integer to the end.
type JSONMarshalFunc ¶
JSONMarshalFunc marshals JSON for a TextMarshaller.
It is used internally in a TextMarshaller, and is not a Marshaller itself.
func GlobalJSONMarshalFunc ¶
func GlobalJSONMarshalFunc() JSONMarshalFunc
GlobalJSONMarshalFunc returns the global JSONMarshalFunc instance.
type JSONMarshallerOption ¶
type JSONMarshallerOption func(*jsonMarshaller)
JSONMarshallerOption is an option for creating Marshallers.
func JSONMarshallerDisableNewlines ¶
func JSONMarshallerDisableNewlines() JSONMarshallerOption
JSONMarshallerDisableNewlines disables newlines after each marshalled Entry.
type Level ¶
type Level int32
Level is a logging level.
const ( // LevelDebug is the debug Level. LevelDebug Level = 0 // LevelInfo is the info Level. LevelInfo Level = 1 // LevelWarn is the warn Level. LevelWarn Level = 2 // LevelError is the error Level. LevelError Level = 3 // LevelFatal is the fatal Level. LevelFatal Level = 4 // LevelPanic is the panic Level. LevelPanic Level = 5 // LevelNone represents no Level. // It is always logged. LevelNone Level = 6 )
func NameToLevel ¶
NameToLevel returns the Level for the given name.
type LevelLogger ¶
type LevelLogger interface { BaseLevelLogger WithField(key string, value interface{}) LevelLogger WithFields(fields map[string]interface{}) LevelLogger WithKeyValues(keyvalues ...interface{}) LevelLogger // This generally should only be used internally or by sub-loggers such as the protobuf Logger. WithEntryMessageContext(context *EntryMessage) LevelLogger // This generally should only be used internally or by sub-loggers such as the protobuf Logger. LogEntryMessage(level Level, event *EntryMessage) }
LevelLogger is a logger tied to a specific Level.
It is returned from a Logger only.
If the requested Level is less than the Logger's level when LevelLogger is constructed, a discard logger will be returned. This is to help with performance concerns of doing lots of WithField/WithFields/etc calls, and then at the end finding the level is discarded.
If log calls are ignored, this has better performance than the standard Logger. If log calls are not ignored, this has slightly worse performance than the standard logger.
Main use of this is for debug calls.
type Logger ¶
type Logger interface { BaseLogger AtLevel(level Level) Logger WithField(key string, value interface{}) Logger WithFields(fields map[string]interface{}) Logger WithKeyValues(keyvalues ...interface{}) Logger // This generally should only be used internally or by sub-loggers such as the protobuf Logger. WithEntryMessageContext(context *EntryMessage) Logger // This generally should only be used internally or by sub-loggers such as the protobuf Logger. LogEntryMessage(level Level, event *EntryMessage) // NOTE: this function name may change, this is experimental LogDebug() LevelLogger // NOTE: this function name may change, this is experimental LogInfo() LevelLogger }
Logger is the main logging interface. All methods are also replicated on the package and attached to a global Logger.
func NewLogger ¶
func NewLogger(pusher Pusher, options ...LoggerOption) Logger
NewLogger constructs a new Logger using the given Pusher.
func WithFields ¶
WithFields calls WithFields on the global Logger.
func WithKeyValues ¶
func WithKeyValues(keyValues ...interface{}) Logger
WithKeyValues calls WithKeyValues on the global Logger.
type LoggerOption ¶
type LoggerOption func(*logger)
LoggerOption is an option for the Logger constructor.
func LoggerWithErrorHandler ¶
func LoggerWithErrorHandler(errorHandler ErrorHandler) LoggerOption
LoggerWithErrorHandler uses the ErrorHandler for the Logger.
func LoggerWithIDAllocator ¶
func LoggerWithIDAllocator(idAllocator IDAllocator) LoggerOption
LoggerWithIDAllocator uses the IDAllocator for the Logger.
func LoggerWithTimer ¶
func LoggerWithTimer(timer Timer) LoggerOption
LoggerWithTimer uses the Timer for the Logger.
type Marshaller ¶
Marshaller marshals Entry objects to be written.
func NewJSONMarshaller ¶
func NewJSONMarshaller(options ...JSONMarshallerOption) Marshaller
NewJSONMarshaller constructs a new Marshaller for JSON.
type Puller ¶
type Puller interface {
Pull() (*EncodedEntry, error)
}
Puller pulls EncodedEntry objects from a persistent store.
func NewReadPuller ¶
func NewReadPuller(reader io.Reader, unmarshaller Unmarshaller) Puller
NewReadPuller constructs a new Puller that reads from the given Reader.
type Pusher ¶
Pusher is the interface used to push Entry objects to a persistent store.
func EncodedPusherToPusher ¶
func EncodedPusherToPusher(encodedPusher EncodedPusher) Pusher
EncodedPusherToPusher returns a Pusher for the EncodedPusher
func NewJSONWritePusher ¶
func NewJSONWritePusher(writer io.Writer, jsonMarshallerOptions ...JSONMarshallerOption) Pusher
NewJSONWritePusher constructs a new Pusher using a JSON Marshaller.
func NewMultiPusher ¶
NewMultiPusher constructs a new Pusher that calls all the given Pushers.
func NewTextWritePusher ¶
func NewTextWritePusher(writer io.Writer, textMarshallerOptions ...TextMarshallerOption) Pusher
NewTextWritePusher constructs a new Pusher using a TextMarshaller.
func NewWritePusher ¶
func NewWritePusher(writer io.Writer, marshaller Marshaller) Pusher
NewWritePusher constructs a new Pusher that writes to the given io.Writer.
type TextMarshaller ¶
type TextMarshaller interface { Marshaller WithColors() TextMarshaller WithoutColors() TextMarshaller }
TextMarshaller is a Marshaller used for text.
func NewTextMarshaller ¶
func NewTextMarshaller(options ...TextMarshallerOption) TextMarshaller
NewTextMarshaller constructs a new Marshaller that produces human-readable marshalled Entry objects. This Marshaller is currently inefficient.
type TextMarshallerOption ¶
type TextMarshallerOption func(*textMarshaller)
TextMarshallerOption is an option for creating Marshallers.
func TextMarshallerDisableContexts ¶
func TextMarshallerDisableContexts() TextMarshallerOption
TextMarshallerDisableContexts will suppress the printing of Entry contexts.
func TextMarshallerDisableLevel ¶
func TextMarshallerDisableLevel() TextMarshallerOption
TextMarshallerDisableLevel will suppress the printing of Entry Levels.
func TextMarshallerDisableNewlines ¶
func TextMarshallerDisableNewlines() TextMarshallerOption
TextMarshallerDisableNewlines disables newlines after each marshalled Entry.
func TextMarshallerDisableTime ¶
func TextMarshallerDisableTime() TextMarshallerOption
TextMarshallerDisableTime will suppress the printing of Entry Timestamps.
type Unmarshaller ¶
type Unmarshaller interface {
Unmarshal(reader io.Reader, encodedtry *EncodedEntry) error
}
Unmarshaller unmarshalls a marshalled EncodedEntry object. At the end of a stream, Unmarshaller will return io.EOF.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package currentlion implements basic integration with Current using plaintext syslog.
|
Package currentlion implements basic integration with Current using plaintext syslog. |
Package envlion provides simple utilities to setup lion from the environment.
|
Package envlion provides simple utilities to setup lion from the environment. |
Package grpclion provides a logger for grpclog.
|
Package grpclion provides a logger for grpclog. |
Package sysloglion defines functionality for integration with syslog.
|
Package sysloglion defines functionality for integration with syslog. |