Documentation ¶
Index ¶
- func DefaultFormatter(entry Entry) ([]byte, error)
- func JsonFormatter(entry Entry) ([]byte, error)
- func LevelColor(level Level) string
- func SuggestedFilePath(tool, filename string) (string, error)
- type Builder
- type Entry
- type FieldLogger
- type Fields
- type Formatter
- type Injector
- type Level
- type MockLogger
- func (m *MockLogger) Child(opts ...Option) FieldLogger
- func (m *MockLogger) Debug(opts ...interface{})
- func (m *MockLogger) Debugf(format string, opts ...interface{})
- func (m *MockLogger) Error(opts ...interface{})
- func (m *MockLogger) Errorf(format string, opts ...interface{})
- func (m *MockLogger) Extend(opts ...Option) FieldLogger
- func (m *MockLogger) Info(opts ...interface{})
- func (m *MockLogger) Infof(format string, opts ...interface{})
- func (m *MockLogger) Trace(opts ...interface{})
- func (m *MockLogger) Tracef(format string, opts ...interface{})
- func (m *MockLogger) Warn(opts ...interface{})
- func (m *MockLogger) Warnf(format string, opts ...interface{})
- func (m *MockLogger) WithFields(f Fields) FieldLogger
- func (m *MockLogger) Write(p []byte) (n int, err error)
- type NoOpLogger
- func (m NoOpLogger) Child(_ ...Option) FieldLogger
- func (m NoOpLogger) Debug(_ ...interface{})
- func (m NoOpLogger) Debugf(_ string, _ ...interface{})
- func (m NoOpLogger) Error(_ ...interface{})
- func (m NoOpLogger) Errorf(_ string, _ ...interface{})
- func (m NoOpLogger) Extend(_ ...Option) FieldLogger
- func (m NoOpLogger) Info(_ ...interface{})
- func (m NoOpLogger) Infof(_ string, _ ...interface{})
- func (m NoOpLogger) Trace(_ ...interface{})
- func (m NoOpLogger) Tracef(_ string, _ ...interface{})
- func (m NoOpLogger) Warn(_ ...interface{})
- func (m NoOpLogger) Warnf(_ string, _ ...interface{})
- func (m NoOpLogger) WithFields(Fields) FieldLogger
- func (m NoOpLogger) Write(p []byte) (n int, err error)
- type Option
- type StdLogger
- type ThreadSaveEntry
- type Transport
- type WriteFunc
- type Writer
- func (w *Writer) Child(opts ...Option) FieldLogger
- func (w *Writer) Close()
- func (w *Writer) Debug(opts ...interface{})
- func (w *Writer) Debugf(format string, opts ...interface{})
- func (w *Writer) Error(opts ...interface{})
- func (w *Writer) Errorf(format string, opts ...interface{})
- func (w *Writer) Extend(opts ...Option) FieldLogger
- func (w *Writer) Info(opts ...interface{})
- func (w *Writer) Infof(format string, opts ...interface{})
- func (w *Writer) InitError() error
- func (w *Writer) RegisterTransport(transport Transport, filters ...func(entry Entry) bool) error
- func (w *Writer) Trace(opts ...interface{})
- func (w *Writer) Tracef(format string, opts ...interface{})
- func (w *Writer) Wait() error
- func (w *Writer) Warn(opts ...interface{})
- func (w *Writer) Warnf(format string, opts ...interface{})
- func (w *Writer) WithFields(fields Fields) FieldLogger
- func (w *Writer) Write(p []byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultFormatter ¶
DefaultFormatter a simple Entry format function
func JsonFormatter ¶
JsonFormatter formats log line as json
func LevelColor ¶
func SuggestedFilePath ¶
SuggestedFilePath returns the suggested path for a log file based on the host operating system
Types ¶
type Builder ¶
Builder initializes a transport with a context If a builder returns an error its assumed that the log destination cannot be used and The error will be surfaced to the caller
type Entry ¶
type Entry struct { // Contains all the fields set by the user. Fields Fields `json:"data,omitempty"` // Timestamp at which the log entry was created Timestamp time.Time `json:"timestamp"` // Level the log entry was logged at: Trace, Debug, Info, Warn, Error, Fatal or Panic // This field will be set on entry firing and the value will be equal to the one in Logger struct field. Level Level `json:"level"` // Calling method, with package name Caller string `json:"caller,omitempty"` // Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic Message string `json:"message"` Error error `json:"error,omitempty"` }
type FieldLogger ¶
type FieldLogger interface { StdLogger io.Writer Child(opts ...Option) FieldLogger Extend(opts ...Option) FieldLogger WithFields(Fields) FieldLogger }
FieldLogger an extension ot StdLogger that appends contextual field data
type Formatter ¶
Formatter is an interface that is expected to receive an Entry and serialize it into a []byte
type Injector ¶
type Injector interface {
UseLogger(logger FieldLogger)
}
Injector an interface used to inject a field logger
type Level ¶
type Level uint32
Level type
const ( // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service./ ErrorLevel Level = iota // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel )
These are the different logging levels. You can set the logging level to log on your instance of logger, obtained with `logrus.New()`.
func ParseLevel ¶
ParseLevel takes a string level and returns the Logrus log level constant.
func (Level) MarshalText ¶
func (*Level) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type MockLogger ¶
MockLogger used for test
func (*MockLogger) Child ¶
func (m *MockLogger) Child(opts ...Option) FieldLogger
func (*MockLogger) Debug ¶
func (m *MockLogger) Debug(opts ...interface{})
func (*MockLogger) Debugf ¶
func (m *MockLogger) Debugf(format string, opts ...interface{})
func (*MockLogger) Error ¶
func (m *MockLogger) Error(opts ...interface{})
func (*MockLogger) Errorf ¶
func (m *MockLogger) Errorf(format string, opts ...interface{})
func (*MockLogger) Extend ¶
func (m *MockLogger) Extend(opts ...Option) FieldLogger
func (*MockLogger) Info ¶
func (m *MockLogger) Info(opts ...interface{})
func (*MockLogger) Infof ¶
func (m *MockLogger) Infof(format string, opts ...interface{})
func (*MockLogger) Trace ¶
func (m *MockLogger) Trace(opts ...interface{})
func (*MockLogger) Tracef ¶
func (m *MockLogger) Tracef(format string, opts ...interface{})
func (*MockLogger) Warn ¶
func (m *MockLogger) Warn(opts ...interface{})
func (*MockLogger) Warnf ¶
func (m *MockLogger) Warnf(format string, opts ...interface{})
func (*MockLogger) WithFields ¶
func (m *MockLogger) WithFields(f Fields) FieldLogger
type NoOpLogger ¶
type NoOpLogger struct{}
NoOpLogger for testing purposes
func (NoOpLogger) Child ¶
func (m NoOpLogger) Child(_ ...Option) FieldLogger
func (NoOpLogger) Debug ¶
func (m NoOpLogger) Debug(_ ...interface{})
func (NoOpLogger) Debugf ¶
func (m NoOpLogger) Debugf(_ string, _ ...interface{})
func (NoOpLogger) Error ¶
func (m NoOpLogger) Error(_ ...interface{})
func (NoOpLogger) Errorf ¶
func (m NoOpLogger) Errorf(_ string, _ ...interface{})
func (NoOpLogger) Extend ¶
func (m NoOpLogger) Extend(_ ...Option) FieldLogger
func (NoOpLogger) Info ¶
func (m NoOpLogger) Info(_ ...interface{})
func (NoOpLogger) Infof ¶
func (m NoOpLogger) Infof(_ string, _ ...interface{})
func (NoOpLogger) Trace ¶
func (m NoOpLogger) Trace(_ ...interface{})
func (NoOpLogger) Tracef ¶
func (m NoOpLogger) Tracef(_ string, _ ...interface{})
func (NoOpLogger) Warn ¶
func (m NoOpLogger) Warn(_ ...interface{})
func (NoOpLogger) Warnf ¶
func (m NoOpLogger) Warnf(_ string, _ ...interface{})
func (NoOpLogger) WithFields ¶
func (m NoOpLogger) WithFields(Fields) FieldLogger
type Option ¶
Option is a function that applies mutations to a *Writer
func WithDisableAutoConsume ¶
func WithDisableAutoConsume() Option
WithDisableAutoConsume turns off auto consumption of messages By default the logger will start multiplexing This should really only be used in tests that need to verify channel behavior
func WithFields ¶
WithFields an option that applies fields to a *Writer
func WithLevelString ¶
WithLevelString sets the level for this logger
func WithParent ¶
func WithParent(parent chan ThreadSaveEntry) Option
WithParent sets the level for this logger
func WithQueue ¶
func WithQueue(queue chan ThreadSaveEntry) Option
WithQueue an Option that applies a queue channel to a *Writer
type StdLogger ¶
type StdLogger interface { Error(opts ...interface{}) Errorf(format string, opts ...interface{}) Warn(opts ...interface{}) Warnf(format string, opts ...interface{}) Info(opts ...interface{}) Infof(format string, opts ...interface{}) Debug(opts ...interface{}) Debugf(format string, opts ...interface{}) Trace(opts ...interface{}) Tracef(format string, opts ...interface{}) }
StdLogger a standard interface defining methods for application logging
type ThreadSaveEntry ¶
type ThreadSaveEntry struct { // Contains all the fields set by the user. Fields [][]string `json:"data,omitempty"` // Timestamp at which the log entry was created Timestamp time.Time `json:"timestamp"` // Level the log entry was logged at: Trace, Debug, Info, Warn, Error, Fatal or Panic // This field will be set on entry firing and the value will be equal to the one in Logger struct field. Level Level `json:"level"` // Calling method, with package name Caller string `json:"caller,omitempty"` // Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic Message string `json:"message"` Error error `json:"error,omitempty"` }
type Transport ¶
type Transport interface { Name() string Stream() chan ThreadSaveEntry Write(entry Entry) error Cleanup() error }
Transport writes an entry to a given destination
type WriteFunc ¶
WriteFunc is a function passed to the Writer.RegisterTransport function. This method is used in a goroutine and is passed each log entry as they arrive. The behavior of the Writer is to attempt to deliver messages to each WriteFunc as fast as possible. If a WriteFunc cannot keep up and backpressure on the queue reaches 1000 messages will be dropped from this WriteFunc stream until it can handle additional capacity
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements the FieldLogger interface and provides a channel based write mechanism An Option can be provided that observes the queue and transports Entry records to a log sink
func (*Writer) Child ¶
func (w *Writer) Child(opts ...Option) FieldLogger
Child returns a new logger instance that inherits from its parent By default it receives its parents fields and level All log messages will be propagated to the parent and written to its parents transports This new instance may receive its own transports which will not receive logs from the parent This logger may be closed independently of its parent
func (*Writer) Close ¶
func (w *Writer) Close()
Close stops new Entry records from being produced by the logger allowing the caller to Wait until all messages have been handled by all Observers
func (*Writer) Debug ¶
func (w *Writer) Debug(opts ...interface{})
Debug writes a debug level message
func (*Writer) Error ¶
func (w *Writer) Error(opts ...interface{})
Error writes an error level message
func (*Writer) Extend ¶
func (w *Writer) Extend(opts ...Option) FieldLogger
Extend is an lighter-weight alternative to Child that allows reuse of parent logger options This will not create transports but instead reuse the parents queue
func (*Writer) InitError ¶
InitError check this property to validate that calling New did not result in a error from an option
func (*Writer) RegisterTransport ¶
RegisterTransport accepts a writeFunc and kicks off a go routine which ensures delivery of log messages to the new writeFunc WriteFunc is used in a goroutine and is passed each log entry as they arrive. The behavior of the Writer is to attempt to deliver messages to each WriteFunc as fast as possible. If a WriteFunc cannot keep up and backpressure on the queue reaches 1000 messages will be dropped from this WriteFunc stream until it can handle additional capacity The WriteFunc should only return an error if it should no longer receive log entries
func (*Writer) Trace ¶
func (w *Writer) Trace(opts ...interface{})
Trace writes a trace level message
func (*Writer) WithFields ¶
func (w *Writer) WithFields(fields Fields) FieldLogger
WithFields is a lighter-weight alternative to Child The Child method is very heavy and creates a new instance with channels, transports, and the works. When used improperly it can cause memory leaks and the most common task is to create a logger with additional fields