Documentation
¶
Index ¶
- Variables
- type BaseLogFormatter
- type BaseLogHandler
- func (b *BaseLogHandler) AddProcessor(processor LogProcessor) LogHandler
- func (b *BaseLogHandler) AddProcessorFn(fn LogProcessorFn) LogHandler
- func (b *BaseLogHandler) Close() error
- func (b *BaseLogHandler) GetBubbling() bool
- func (b *BaseLogHandler) GetDefaultFormatter() (LogFormatter, LogFormatterFn)
- func (b *BaseLogHandler) Handle(r *LogRecord) (bool, error)
- func (b *BaseLogHandler) LogLevels() []LogLevel
- func (b *BaseLogHandler) OnClose() error
- func (b *BaseLogHandler) Ref()
- func (b *BaseLogHandler) RemoveProcessor(processor LogProcessor) error
- func (b *BaseLogHandler) RemoveProcessorFn(fn LogProcessorFn)
- func (b *BaseLogHandler) ResetFormatter() error
- func (b *BaseLogHandler) ResetFormatterFn() error
- func (b *BaseLogHandler) SetBubbling(bubble bool) LogHandler
- func (b *BaseLogHandler) SetFormatter(formatter LogFormatter) LogHandler
- func (b *BaseLogHandler) SetFormatterFn(fn LogFormatterFn) LogHandler
- func (b *BaseLogHandler) ShouldHandlePost(*LogRecord) bool
- func (b *BaseLogHandler) ShouldHandlePre(*LogRecord) bool
- func (b *BaseLogHandler) Unref() error
- type BaseLogProcessor
- type ErrHandlerCloseFailure
- type ErrLoggerCloseFailure
- type ErrorSource
- type Fields
- type LogCaller
- type LogFormatter
- type LogFormatterFn
- type LogHandler
- type LogLevel
- type LogProcessor
- type LogProcessorFn
- type LogRecord
- type Logger
- func (l *Logger) AddHandler(handler LogHandler)
- func (l *Logger) AddProcessor(p LogProcessor)
- func (l *Logger) AddProcessorFn(fn LogProcessorFn)
- func (l *Logger) Close() error
- func (l *Logger) Critical(format string, v ...interface{})
- func (l *Logger) CriticalFields(fields Fields, format string, v ...interface{})
- func (l *Logger) Debug(format string, v ...interface{})
- func (l *Logger) DebugFields(fields Fields, format string, v ...interface{})
- func (l *Logger) Error(format string, v ...interface{})
- func (l *Logger) ErrorFields(fields Fields, format string, v ...interface{})
- func (l *Logger) Fatal(format string, v ...interface{})
- func (l *Logger) FatalFields(fields Fields, format string, v ...interface{})
- func (l *Logger) GetLevel() LogLevel
- func (l *Logger) GetName() string
- func (l *Logger) Info(format string, v ...interface{})
- func (l *Logger) InfoFields(fields Fields, format string, v ...interface{})
- func (l *Logger) IsCritical() bool
- func (l *Logger) IsDebug() bool
- func (l *Logger) IsError() bool
- func (l *Logger) IsFatal() bool
- func (l *Logger) IsInfo() bool
- func (l *Logger) IsTrace() bool
- func (l *Logger) Log(skip int, level LogLevel, format string, v ...interface{})
- func (l *Logger) LogFields(skip int, level LogLevel, fields Fields, format string, v ...interface{})
- func (l *Logger) RemoveHandler(handler LogHandler) error
- func (l *Logger) RemoveProcessor(p LogProcessor) error
- func (l *Logger) RemoveProcessorFn(fn LogProcessorFn)
- func (l *Logger) Trace(format string, v ...interface{})
- func (l *Logger) TraceFields(fields Fields, format string, v ...interface{})
- func (l *Logger) Warn(format string, v ...interface{})
- func (l *Logger) WarnFields(fields Fields, format string, v ...interface{})
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type BaseLogFormatter ¶
type BaseLogFormatter struct {
LogFormatter
// contains filtered or unexported fields
}
func NewBaseLogFormatter ¶
func NewBaseLogFormatter() *BaseLogFormatter
func (*BaseLogFormatter) Close ¶
func (b *BaseLogFormatter) Close() error
func (*BaseLogFormatter) Ref ¶
func (b *BaseLogFormatter) Ref()
func (*BaseLogFormatter) Unref ¶
func (b *BaseLogFormatter) Unref() error
type BaseLogHandler ¶
type BaseLogHandler struct {
LogHandler
// contains filtered or unexported fields
}
func NewBaseLogHandler ¶
func NewBaseLogHandler() *BaseLogHandler
func (*BaseLogHandler) AddProcessor ¶
func (b *BaseLogHandler) AddProcessor(processor LogProcessor) LogHandler
Add an processor object to the list of processors; calls Ref() on the processor to add
func (*BaseLogHandler) AddProcessorFn ¶
func (b *BaseLogHandler) AddProcessorFn(fn LogProcessorFn) LogHandler
Add a processor function to the list of processors
func (*BaseLogHandler) Close ¶
func (b *BaseLogHandler) Close() error
func (*BaseLogHandler) GetBubbling ¶
func (b *BaseLogHandler) GetBubbling() bool
Returns the bubbling state of the handler: `true` when handled messages should not be consumed but be processed by the next handler instead; `false` when handled messages should be consumed
func (*BaseLogHandler) GetDefaultFormatter ¶ added in v0.3.0
func (b *BaseLogHandler) GetDefaultFormatter() (LogFormatter, LogFormatterFn)
Returns a tuple of the default formatter object and default formatter function. Will be used in ResetFormatter() and ResetFormatterFn() to restore the default formatter of an handler.
func (*BaseLogHandler) Handle ¶
func (b *BaseLogHandler) Handle(r *LogRecord) (bool, error)
Handles the given logrecord. Returns a bool weather or not the record was consumed and any error that might araise.
func (*BaseLogHandler) LogLevels ¶
func (b *BaseLogHandler) LogLevels() []LogLevel
func (*BaseLogHandler) OnClose ¶
func (b *BaseLogHandler) OnClose() error
func (*BaseLogHandler) Ref ¶
func (b *BaseLogHandler) Ref()
func (*BaseLogHandler) RemoveProcessor ¶ added in v0.3.0
func (b *BaseLogHandler) RemoveProcessor(processor LogProcessor) error
Remove a processor object from the list of processors If one is found, it is Unref() is called on it, and the potential error is returned.
Note: calling RemoveProcessor() with an processor that's NOT part of the list, is NOT an error!
func (*BaseLogHandler) RemoveProcessorFn ¶ added in v0.3.0
func (b *BaseLogHandler) RemoveProcessorFn(fn LogProcessorFn)
Remove a processor function from the list of processors
func (*BaseLogHandler) ResetFormatter ¶ added in v0.3.0
func (b *BaseLogHandler) ResetFormatter() error
Reset the formatter object to the default one. If the previous formatter was an formatter object, Unref() is called on it.
func (*BaseLogHandler) ResetFormatterFn ¶ added in v0.3.0
func (b *BaseLogHandler) ResetFormatterFn() error
Resets the formatter function to the default one. If the previous formatter was an formatter object, Unref() is called on it.
Note: this function is effectivly the
func (*BaseLogHandler) SetBubbling ¶
func (b *BaseLogHandler) SetBubbling(bubble bool) LogHandler
Sets the bubbling state of the handler: `true` when handled messages should not be consumed but be processed by the next handler instead; `false` when handled messages should be consumed
func (*BaseLogHandler) SetFormatter ¶
func (b *BaseLogHandler) SetFormatter(formatter LogFormatter) LogHandler
Sets the formatter object. Note: when an formatter is already set, it is reset and potential errors are handed to panic().
func (*BaseLogHandler) SetFormatterFn ¶
func (b *BaseLogHandler) SetFormatterFn(fn LogFormatterFn) LogHandler
Sets the formatter function. Note: when an formatter is already set, it is reset and potential errors are handed to panic().
func (*BaseLogHandler) ShouldHandlePost ¶
func (b *BaseLogHandler) ShouldHandlePost(*LogRecord) bool
Returns true if the given logrecord should be handled; called AFTER all handler-local processors where run on the logrecord. Will NOT be called if the logrecord's loglevel is NONE after the process step.
This default implementation returns always `true`.
func (*BaseLogHandler) ShouldHandlePre ¶
func (b *BaseLogHandler) ShouldHandlePre(*LogRecord) bool
Returns true if the given logrecord should be handled; called BEFORE all handler-local processors where run on the logrecord. Will recieve records with an loglevel to NONE.
This default implementation returns always `true`.
func (*BaseLogHandler) Unref ¶
func (b *BaseLogHandler) Unref() error
type BaseLogProcessor ¶
type BaseLogProcessor struct {
LogProcessor
// contains filtered or unexported fields
}
func NewBaseLogProcessor ¶
func NewBaseLogProcessor() *BaseLogProcessor
func (*BaseLogProcessor) Close ¶
func (b *BaseLogProcessor) Close() error
func (*BaseLogProcessor) Ref ¶
func (b *BaseLogProcessor) Ref()
func (*BaseLogProcessor) Unref ¶
func (b *BaseLogProcessor) Unref() error
type ErrHandlerCloseFailure ¶
type ErrHandlerCloseFailure struct {
ProcessorCloseErrors []ErrorSource
FormatterCloseError *ErrorSource
HandlerOnCloseError *ErrorSource
}
func (*ErrHandlerCloseFailure) Error ¶
func (e *ErrHandlerCloseFailure) Error() string
type ErrLoggerCloseFailure ¶
type ErrLoggerCloseFailure struct {
ProcessorCloseErrors []ErrorSource
HandlerCloseErrors []ErrorSource
}
func (*ErrLoggerCloseFailure) Error ¶
func (e *ErrLoggerCloseFailure) Error() string
type ErrorSource ¶
type LogFormatter ¶
type LogFormatterFn ¶
type LogHandler ¶
type LogHandler interface {
// Call this to properly close the handler.
// Co NOT overwritte this if you are not knowing what you are doing; use OnClose() instead!
Close() error
// Can be implemented by extenders to be called when closing and not interfere with the basic handler's
// closing mecanism
OnClose() error
// Increases the reference count by one
Ref()
// Decreases the reference count by one; if zero or lower, this function calls Close() to close this handler
// and returns it's result
Unref() error
// Returns all levels the handler is interested in; including NONE dosn't affect anything
LogLevels() []LogLevel
// Returns true if the given record should be handled; called *before* handler-local processors are run.
// Will recieve records with a loglevel of NONE to allow handler-local processor to make it valid again.
ShouldHandlePre(*LogRecord) bool
// Returns true if the given record should be handled; called *after* handler-local processors are run.
// Will *not* recieve records with a loglevel of NONE.
ShouldHandlePost(*LogRecord) bool
// Handles an log record, returns true if the record was handled
// and should not be handled by other handlers
Handle(*LogRecord) (bool, error)
// Writes an formatted logrecord.
Write([]byte) error
// Sets if the handler allows handled records to bubble
SetBubbling(bool) LogHandler
// Returns true if the handler allows handled records to bubble
GetBubbling() bool
// Sets the formatter to an formatting function
SetFormatterFn(LogFormatterFn) LogHandler
// Sets the formatter to an formatter object and calls Ref() on it
SetFormatter(LogFormatter) LogHandler
// Resets the formatter function to the default one.
// If the previous formatter was an formatter object, Unref() is called on it.
ResetFormatterFn() error
// Reset the formatter object to the default one.
// If the previous formatter was an formatter object, Unref() is called on it.
ResetFormatter() error
// Adds an processor function to run for just this handler
AddProcessorFn(LogProcessorFn) LogHandler
// Adds an processor object to run for just this handler and calls Ref() on it
AddProcessor(LogProcessor) LogHandler
// Remove a processor function from the list of processors
RemoveProcessorFn(fn LogProcessorFn)
// Remove a processor object from the list of processors
// If one is found, it is Unref() is called on it, and the potential error is returned.
//
// Note: calling RemoveProcessor() with an processor that's NOT part of the list, is NOT an error!
RemoveProcessor(processor LogProcessor) error
// Returns a tuple of the default formatter object and default formatter function.
// Will be used in ResetFormatter() and ResetFormatterFn() to restore the default formatter of an handler.
GetDefaultFormatter() (LogFormatter, LogFormatterFn)
}
type LogProcessor ¶
type LogProcessorFn ¶
type LogRecord ¶
type LogRecord struct {
Source string `json:"source,omitempty"`
Created time.Time `json:"created_at"`
Level LogLevel `json:"lvl"`
Message string `json:"msg"`
Caller *LogCaller `json:"caller,omitempty"`
Fields Fields `json:"fields"`
}
func NewLogRecord ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) AddHandler ¶
func (l *Logger) AddHandler(handler LogHandler)
func (*Logger) AddProcessor ¶
func (l *Logger) AddProcessor(p LogProcessor)
func (*Logger) AddProcessorFn ¶
func (l *Logger) AddProcessorFn(fn LogProcessorFn)
Adds an processor to modify/enhance log-entries before they are send to each handler
func (*Logger) CriticalFields ¶
func (*Logger) DebugFields ¶
func (*Logger) ErrorFields ¶
func (*Logger) FatalFields ¶
func (*Logger) InfoFields ¶
func (*Logger) IsCritical ¶
func (*Logger) RemoveHandler ¶ added in v0.3.0
func (l *Logger) RemoveHandler(handler LogHandler) error
func (*Logger) RemoveProcessor ¶ added in v0.3.0
func (l *Logger) RemoveProcessor(p LogProcessor) error
func (*Logger) RemoveProcessorFn ¶ added in v0.3.0
func (l *Logger) RemoveProcessorFn(fn LogProcessorFn)
Removes an processor function previously added by AddProcessorFn