lion: go.pedge.io/lion Index | Files | Directories

package lion

import "go.pedge.io/lion"

Package lion provides structured logging, configurable to use serialization protocols such as Protocol Buffers.

Index

Package Files

defaults.go discard_pusher.go encoding.go json_marshaller.go lion.go lion_level.go logger.go multi_pusher.go read_puller.go text_marshaller.go write_pusher.go

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)
)

func AddGlobalHook Uses

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 DebugWriter Uses

func DebugWriter() io.Writer

DebugWriter calls DebugWriter on the global Logger.

func Debugf Uses

func Debugf(format string, args ...interface{})

Debugf calls Debugf on the global Logger.

func Debugln Uses

func Debugln(args ...interface{})

Debugln calls Debugln on the global Logger.

func ErrorWriter Uses

func ErrorWriter() io.Writer

ErrorWriter calls ErrorWriter on the global Logger.

func Errorf Uses

func Errorf(format string, args ...interface{})

Errorf calls Errorf on the global Logger.

func Errorln Uses

func Errorln(args ...interface{})

Errorln calls Errorln on the global Logger.

func Fatalf Uses

func Fatalf(format string, args ...interface{})

Fatalf calls Fatalf on the global Logger.

func Fatalln Uses

func Fatalln(args ...interface{})

Fatalln calls Fatalln on the global Logger.

func Flush Uses

func Flush() error

Flush calls Flush on the global Logger.

func InfoWriter Uses

func InfoWriter() io.Writer

InfoWriter calls InfoWriter on the global Logger.

func Infof Uses

func Infof(format string, args ...interface{})

Infof calls Infof on the global Logger.

func Infoln Uses

func Infoln(args ...interface{})

Infoln calls Infoln on the global Logger.

func Panicf Uses

func Panicf(format string, args ...interface{})

Panicf calls Panicf on the global Logger.

func Panicln Uses

func Panicln(args ...interface{})

Panicln calls Panicln on the global Logger.

func Printf Uses

func Printf(format string, args ...interface{})

Printf calls Printf on the global Logger.

func Println Uses

func Println(args ...interface{})

Println calls Println on the global Logger.

func RedirectStdLogger Uses

func RedirectStdLogger()

RedirectStdLogger will redirect logs to golang's standard logger to the global Logger instance.

func RegisterEncoderDecoder Uses

func RegisterEncoderDecoder(encoding string, encoderDecoder EncoderDecoder) error

RegisterEncoderDecoder registers an EncoderDecoder by encoding.

func SetJSONMarshalFunc Uses

func SetJSONMarshalFunc(jsonMarshalFunc JSONMarshalFunc)

SetJSONMarshalFunc sets the global JSONMarshalFunc to be used by default.

func SetLevel Uses

func SetLevel(level Level)

SetLevel sets the global Logger to to be at the given Level.

func SetLogger Uses

func SetLogger(logger Logger)

SetLogger sets the global Logger instance.

func WarnWriter Uses

func WarnWriter() io.Writer

WarnWriter calls WarnWriter on the global Logger.

func Warnf Uses

func Warnf(format string, args ...interface{})

Warnf calls Warnf on the global Logger.

func Warnln Uses

func Warnln(args ...interface{})

Warnln calls Warnln on the global Logger.

func Writer Uses

func Writer() io.Writer

Writer calls Writer on the global Logger.

type BaseLevelLogger Uses

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 Uses

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 Uses

type Decoder interface {
    Decode(encodedEntryMessage *EncodedEntryMessage) (*EntryMessage, error)
}

Decoder decodes EntryMessages.

type EncodedEntry Uses

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 Uses

func (e *EncodedEntry) Decode() (*Entry, error)

Decode decodes an encoded Entry.

type EncodedEntryMessage Uses

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 Uses

func (e *EncodedEntryMessage) Decode() (*EntryMessage, error)

Decode decodes an encoded EntryMessage.

type EncodedPusher Uses

type EncodedPusher interface {
    Flusher
    Push(encodedEntry *EncodedEntry) error
}

EncodedPusher pushes EncodedEntry objects.

type Encoder Uses

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 Uses

type EncoderDecoder interface {
    Encoder
    Decoder
}

EncoderDecoder is an Encoder and Decoarder.

type Entry Uses

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.

func (*Entry) Encode Uses

func (e *Entry) Encode() (*EncodedEntry, error)

Encode encodes an Entry.

type EntryMessage Uses

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 Uses

func (e *EntryMessage) Encode() (*EncodedEntryMessage, error)

Encode encodes an EntryMessage.

func (*EntryMessage) Name Uses

func (e *EntryMessage) Name() (string, error)

Name gets the globally-unique name for an EntryMessge.

type ErrorHandler Uses

type ErrorHandler interface {
    Handle(err error)
}

ErrorHandler handles errors when logging. The default behavior is to panic.

type Flusher Uses

type Flusher interface {
    Flush() error
}

Flusher is an object that can be flushed to a persistent store.

type GlobalHook Uses

type GlobalHook func(Logger)

GlobalHook is a function that handles a change in the global Logger instance.

type IDAllocator Uses

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 Uses

type JSONMarshalFunc func(writer io.Writer, value interface{}) error

JSONMarshalFunc marshals JSON for a TextMarshaller.

It is used internally in a TextMarshaller, and is not a Marshaller itself.

func GlobalJSONMarshalFunc Uses

func GlobalJSONMarshalFunc() JSONMarshalFunc

GlobalJSONMarshalFunc returns the global JSONMarshalFunc instance.

type JSONMarshallerOption Uses

type JSONMarshallerOption func(*jsonMarshaller)

JSONMarshallerOption is an option for creating Marshallers.

func JSONMarshallerDisableNewlines Uses

func JSONMarshallerDisableNewlines() JSONMarshallerOption

JSONMarshallerDisableNewlines disables newlines after each marshalled Entry.

type Level Uses

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 Uses

func NameToLevel(name string) (Level, error)

NameToLevel returns the Level for the given name.

func (Level) String Uses

func (l Level) String() string

String returns the name of a Level or the numerical value if the Level is unknown.

type LevelLogger Uses

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.

func LogDebug Uses

func LogDebug() LevelLogger

LogDebug calls LogDebug on the global Logger.

func LogInfo Uses

func LogInfo() LevelLogger

LogInfo calls LogInfo on the global Logger.

type Logger Uses

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 AtLevel Uses

func AtLevel(level Level) Logger

AtLevel calls AtLevel on the global Logger.

func GlobalLogger Uses

func GlobalLogger() Logger

GlobalLogger returns the global Logger instance.

func NewLogger Uses

func NewLogger(pusher Pusher, options ...LoggerOption) Logger

NewLogger constructs a new Logger using the given Pusher.

func WithField Uses

func WithField(key string, value interface{}) Logger

WithField calls WithField on the global Logger.

func WithFields Uses

func WithFields(fields map[string]interface{}) Logger

WithFields calls WithFields on the global Logger.

func WithKeyValues Uses

func WithKeyValues(keyValues ...interface{}) Logger

WithKeyValues calls WithKeyValues on the global Logger.

type LoggerOption Uses

type LoggerOption func(*logger)

LoggerOption is an option for the Logger constructor.

func LoggerEnableID Uses

func LoggerEnableID() LoggerOption

LoggerEnableID enables IDs for the Logger.

func LoggerWithErrorHandler Uses

func LoggerWithErrorHandler(errorHandler ErrorHandler) LoggerOption

LoggerWithErrorHandler uses the ErrorHandler for the Logger.

func LoggerWithIDAllocator Uses

func LoggerWithIDAllocator(idAllocator IDAllocator) LoggerOption

LoggerWithIDAllocator uses the IDAllocator for the Logger.

func LoggerWithTimer Uses

func LoggerWithTimer(timer Timer) LoggerOption

LoggerWithTimer uses the Timer for the Logger.

type Marshaller Uses

type Marshaller interface {
    Marshal(entry *Entry) ([]byte, error)
}

Marshaller marshals Entry objects to be written.

func NewJSONMarshaller Uses

func NewJSONMarshaller(options ...JSONMarshallerOption) Marshaller

NewJSONMarshaller constructs a new Marshaller for JSON.

type Puller Uses

type Puller interface {
    Pull() (*EncodedEntry, error)
}

Puller pulls EncodedEntry objects from a persistent store.

func NewReadPuller Uses

func NewReadPuller(reader io.Reader, unmarshaller Unmarshaller) Puller

NewReadPuller constructs a new Puller that reads from the given Reader.

type Pusher Uses

type Pusher interface {
    Flusher
    Push(entry *Entry) error
}

Pusher is the interface used to push Entry objects to a persistent store.

func EncodedPusherToPusher Uses

func EncodedPusherToPusher(encodedPusher EncodedPusher) Pusher

EncodedPusherToPusher returns a Pusher for the EncodedPusher

func NewJSONWritePusher Uses

func NewJSONWritePusher(writer io.Writer, jsonMarshallerOptions ...JSONMarshallerOption) Pusher

NewJSONWritePusher constructs a new Pusher using a JSON Marshaller.

func NewMultiPusher Uses

func NewMultiPusher(pushers ...Pusher) Pusher

NewMultiPusher constructs a new Pusher that calls all the given Pushers.

func NewTextWritePusher Uses

func NewTextWritePusher(writer io.Writer, textMarshallerOptions ...TextMarshallerOption) Pusher

NewTextWritePusher constructs a new Pusher using a TextMarshaller.

func NewWritePusher Uses

func NewWritePusher(writer io.Writer, marshaller Marshaller) Pusher

NewWritePusher constructs a new Pusher that writes to the given io.Writer.

type TextMarshaller Uses

type TextMarshaller interface {
    Marshaller
    WithColors() TextMarshaller
    WithoutColors() TextMarshaller
}

TextMarshaller is a Marshaller used for text.

func NewTextMarshaller Uses

func NewTextMarshaller(options ...TextMarshallerOption) TextMarshaller

NewTextMarshaller constructs a new Marshaller that produces human-readable marshalled Entry objects. This Marshaller is currently inefficient.

type TextMarshallerOption Uses

type TextMarshallerOption func(*textMarshaller)

TextMarshallerOption is an option for creating Marshallers.

func TextMarshallerDisableContexts Uses

func TextMarshallerDisableContexts() TextMarshallerOption

TextMarshallerDisableContexts will suppress the printing of Entry contexts.

func TextMarshallerDisableLevel Uses

func TextMarshallerDisableLevel() TextMarshallerOption

TextMarshallerDisableLevel will suppress the printing of Entry Levels.

func TextMarshallerDisableNewlines Uses

func TextMarshallerDisableNewlines() TextMarshallerOption

TextMarshallerDisableNewlines disables newlines after each marshalled Entry.

func TextMarshallerDisableTime Uses

func TextMarshallerDisableTime() TextMarshallerOption

TextMarshallerDisableTime will suppress the printing of Entry Timestamps.

type Timer Uses

type Timer interface {
    Now() time.Time
}

Timer returns the current time. The default behavior is to call time.Now().UTC().

type Unmarshaller Uses

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.

Directories

PathSynopsis
currentPackage currentlion implements basic integration with Current using plaintext syslog.
envPackage envlion provides simple utilities to setup lion from the environment.
example/currentPackage main implements an example integration with Current.
gcloudPackage gcloudlion integrates lion with the Google Cloud Logging service.
ginPackage ginlion defines functionality to integrate lion with gin.
grpcPackage grpclion provides a logger for grpclog.
kitPackage kitlion defines functionality to integrate lion with go-kit.
protoPackage protolion defines the Protocol Buffers functionality for lion.
proto/testingPackage protoliontesting defines testing for protolion.
syslogPackage sysloglion defines functionality for integration with syslog.
tailPackage taillion implements tailing of lion log files.
thriftPackage thriftlion defines the Thrift functionality for lion.
thrift/testingPackage thriftliontesting defines testing for thriftlion.

Package lion imports 14 packages (graph) and is imported by 15 packages. Updated 2017-07-25. Refresh now. Tools for package owners.