Documentation
¶
Overview ¶
Package protolog defines the main protolog functionality.
Index ¶
- Variables
- func AddGlobalHook(globalHook GlobalHook)
- func Debug(Event proto.Message)
- func DebugWriter() io.Writer
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func Error(Event proto.Message)
- func ErrorWriter() io.Writer
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatal(Event proto.Message)
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func Flush() error
- func Info(Event proto.Message)
- func InfoWriter() io.Writer
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func Panic(Event proto.Message)
- func Panicf(format string, args ...interface{})
- func Panicln(args ...interface{})
- func Print(Event proto.Message)
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func RedirectStdLogger()
- func SetLevel(level Level)
- func SetLogger(logger Logger)
- func Warn(Event proto.Message)
- func WarnWriter() io.Writer
- func Warnf(format string, args ...interface{})
- func Warnln(args ...interface{})
- func Writer() io.Writer
- type Entry
- type ErrorHandler
- type Flusher
- type GlobalHook
- type IDAllocator
- type Level
- type Logger
- type LoggerOption
- type Marshaller
- type Puller
- type Pusher
- type ReadPullerOption
- type TextMarshaller
- type TextMarshallerOption
- type Timer
- type Unmarshaller
- type WritePusherOption
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{} // DelimitedMarshaller is a Marshaller that uses the protocol buffers write delimited scheme. DelimitedMarshaller = &delimitedMarshaller{} // DelimitedUnmarshaller is an Unmarshaller that uses the protocol buffers write delimited scheme. DelimitedUnmarshaller = &delimitedUnmarshaller{} // 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.
Types ¶
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 may be set Contexts []proto.Message `json:"contexts,omitempty"` Fields map[string]string `json:"fields,omitempty"` // one of Event, Message, WriterOutput will be set Event proto.Message `json:"event,omitempty"` Message string `json:"message,omitempty"` WriterOutput []byte `json:"writer_output,omitempty"` }
Entry is the go equivalent of an Entry.
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 Level ¶
type Level int32
Level is a logging level.
const ( // LevelNone represents no Level. LevelNone Level = 0 // LevelDebug is the debug Level. LevelDebug Level = 1 // LevelInfo is the info Level. LevelInfo Level = 2 // LevelWarn is the warn Level. LevelWarn Level = 3 // LevelError is the error Level. LevelError Level = 4 // LevelFatal is the fatal Level. LevelFatal Level = 5 // LevelPanic is the panic Level. LevelPanic Level = 6 )
func NameToLevel ¶
NameToLevel returns the Level for the given name.
type Logger ¶
type Logger interface { Flusher AtLevel(level Level) Logger WithContext(context proto.Message) Logger Debug(event proto.Message) Info(event proto.Message) Warn(event proto.Message) Error(event proto.Message) Fatal(event proto.Message) Panic(event proto.Message) Print(event proto.Message) DebugWriter() io.Writer InfoWriter() io.Writer WarnWriter() io.Writer ErrorWriter() io.Writer Writer() io.Writer WithField(key string, value interface{}) Logger WithFields(fields map[string]interface{}) Logger 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{}) }
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 WithContext ¶
WithContext calls WithContext on the global Logger.
func WithFields ¶
WithFields calls WithFields 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 LoggerWithIDEnabled ¶
func LoggerWithIDEnabled() LoggerOption
LoggerWithIDEnabled enables IDs 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.
type Puller ¶
Puller pulls Entry objects from a persistent store.
func NewReadPuller ¶
func NewReadPuller(reader io.Reader, options ...ReadPullerOption) 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 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 and newlines.
func NewWritePusher ¶
func NewWritePusher(writer io.Writer, options ...WritePusherOption) Pusher
NewWritePusher constructs a new Pusher that writes to the given io.Writer.
type ReadPullerOption ¶
type ReadPullerOption func(*readPuller)
ReadPullerOption is an option for a read Puller.
func ReadPullerWithUnmarshaller ¶
func ReadPullerWithUnmarshaller(unmarshaller Unmarshaller) ReadPullerOption
ReadPullerWithUnmarshaller uses the Unmarshaller for the read Puller.
By default, DelimitedUnmarshaller is used.
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 ¶
Unmarshaller unmarshalls a marshalled Entry object. At the end of a stream, Unmarshaller will return io.EOF.
type WritePusherOption ¶
type WritePusherOption func(*writePusher)
WritePusherOption is an option for constructing a new write Pusher.
func WritePusherWithMarshaller ¶
func WritePusherWithMarshaller(marshaller Marshaller) WritePusherOption
WritePusherWithMarshaller uses the Marshaller for the write Pusher.
By default, DelimitedMarshaller is used.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package protolog_glog defines functionality for integration with glog.
|
Package protolog_glog defines functionality for integration with glog. |
Package protolog_logrus defines functionality for integration with Logrus.
|
Package protolog_logrus defines functionality for integration with Logrus. |
Package protologpb is a generated protocol buffer package.
|
Package protologpb is a generated protocol buffer package. |
Package protolog_syslog defines functionality for integration with syslog.
|
Package protolog_syslog defines functionality for integration with syslog. |