Documentation ¶
Index ¶
- Variables
- func AddLogObserver(w io.Writer, formatter Formatter) error
- func ClearLogObservers()
- func GetLogLevelPattern() string
- func GetOrCreate(name string) *logger
- func NewLogLineWrapperFormatter(marshalizer marshal.Marshalizer) (*logLineWrapperFormatter, error)
- func NewLogOutputSubject() *logOutputSubject
- func RemoveLogObserver(w io.Writer) error
- func SetDisplayByteSlice(f func(slice []byte) string) error
- func SetLogLevel(logLevelAndPattern string) error
- type ConsoleFormatter
- type Formatter
- type LogLevel
- type LogLine
- type LogLineHandler
- type LogLineWrapper
- type LogOutputHandler
- type Logger
- type PlainFormatter
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidLogLevelPattern = errors.New("un-parsable log level and pattern provided")
ErrInvalidLogLevelPattern signals that an un-parsable log level and patter was provided
var ErrNilDisplayByteSliceHandler = errors.New("nil display byte slice handler")
ErrNilDisplayByteSliceHandler signals that a nil display byte slice handler has been provided
var ErrNilFormatter = errors.New("nil formatter provided")
ErrNilFormatter signals that a nil formatter has been provided
var ErrNilMarshalizer = errors.New("nil marshalizer")
ErrNilMarshalizer signals that a nil marshalizer has been provided
var ErrNilWriter = errors.New("nil writer provided")
ErrNilWriter signals that a nil writer has been provided
var ErrWriterNotFound = errors.New("writer not found while searching container")
ErrWriterNotFound signals that the provided writer was not found while searching container list
var Levels = []LogLevel{ LogTrace, LogDebug, LogInfo, LogWarning, LogError, LogNone, }
Levels contain all defined levels as a slice for an easier iteration
Functions ¶
func AddLogObserver ¶
AddLogObserver adds a new observer (writer + formatter) to the already built-in log observers queue This method is useful when adding a new output device for logs is needed (such as files, streams, API routes and so on)
func GetLogLevelPattern ¶
func GetLogLevelPattern() string
GetLogLevelPattern returns the last set log level pattern. The format returned is MATCHING_STRING1:LOG_LEVEL1,MATCHING_STRING2:LOG_LEVEL2".
func GetOrCreate ¶
func GetOrCreate(name string) *logger
GetOrCreate returns a log based on the name provided, generating a new log if there is no log with provided name
func NewLogLineWrapperFormatter ¶
func NewLogLineWrapperFormatter(marshalizer marshal.Marshalizer) (*logLineWrapperFormatter, error)
NewLogLineWrapperFormatter creates a new logLineWrapperFormatter that is able to marshalize the provided logLine
func NewLogOutputSubject ¶
func NewLogOutputSubject() *logOutputSubject
NewLogOutputSubject returns an initialized, empty logOutputSubject with no observers
func RemoveLogObserver ¶
RemoveLogObserver removes an exiting observer by providing the writer pointer.
func SetDisplayByteSlice ¶
SetDisplayByteSlice sets the converter function from byte slice to string default, this will call hex.EncodeToString
func SetLogLevel ¶
SetLogLevel changes the log level of the contained loggers. The expected format is "MATCHING_STRING1:LOG_LEVEL1,MATCHING_STRING2:LOG_LEVEL2". If matching string is *, it will change the log levels of all contained loggers and will also set the defaultLogLevelProperty. Otherwise, the log level will be modified only on those loggers that will contain the matching string on any position. For example, having the parameter "DEBUG|process" will set the DEBUG level on all loggers that will contain the "process" string in their name ("process/sync", "process/interceptors", "process" and so on). The rules are applied in the exact manner as they are provided, starting from left to the right part of the string Example: *:INFO,p2p:ERROR,*:DEBUG,data:INFO will result in having the data package logger(s) on INFO log level and all other packages on DEBUG level
Types ¶
type ConsoleFormatter ¶
type ConsoleFormatter struct { }
ConsoleFormatter implements formatter interface and is used to format log lines to be written on the console It uses ANSI-color for colorized console/terminal output.
func (*ConsoleFormatter) IsInterfaceNil ¶
func (cf *ConsoleFormatter) IsInterfaceNil() bool
IsInterfaceNil returns true if there is no value under the interface
func (*ConsoleFormatter) Output ¶
func (cf *ConsoleFormatter) Output(line LogLineHandler) []byte
Output converts the provided LogLineHandler into a slice of bytes ready for output
type Formatter ¶
type Formatter interface { Output(line LogLineHandler) []byte IsInterfaceNil() bool }
Formatter describes what a log formatter should be able to do
type LogLevel ¶
type LogLevel byte
LogLevel defines the priority level of a log line. Trace is the lowest priority level, Error is the highest
const ( LogTrace LogLevel = 0 LogDebug LogLevel = 1 LogInfo LogLevel = 2 LogWarning LogLevel = 3 LogError LogLevel = 4 LogNone LogLevel = 5 )
These constants are the string representation of the package logging levels.
func GetLogLevel ¶
GetLogLevel gets the corresponding log level from provided string. The search is case insensitive.
func ParseLogLevelAndMatchingString ¶
ParseLogLevelAndMatchingString can parse a string in the form "MATCHING_STRING1:LOG_LEVEL1,MATCHING_STRING2:LOG_LEVEL2" into its corresponding log level and matching string. Errors if something goes wrong. For example, having the parameter "DEBUG|process" will set the DEBUG level on all loggers that will contain the "process" string in their name ("process/sync", "process/interceptors", "process" and so on). The rules are applied in the exact manner as they are provided, starting from left to the right part of the string Example: *:INFO,p2p:ERROR,*:DEBUG,data:INFO will result in having the data package logger(s) on INFO log level and all other packages on DEBUG level
type LogLineHandler ¶
type LogLineHandler interface { GetMessage() string GetLogLevel() int32 GetArgs() []string GetTimestamp() int64 IsInterfaceNil() bool }
LogLineHandler defines the get methods for a log line struct used by the formatter interface
type LogLineWrapper ¶
type LogLineWrapper struct {
protobuf.LogLineMessage
}
LogLineWrapper is a wrapper over protobuf.LogLineMessage that enables the structure to be used with capnp marshalizer
func (*LogLineWrapper) IsInterfaceNil ¶
func (llw *LogLineWrapper) IsInterfaceNil() bool
IsInterfaceNil returns true if there is no value under the interface
type LogOutputHandler ¶
type LogOutputHandler interface { Output(line *LogLine) AddObserver(w io.Writer, format Formatter) error RemoveObserver(w io.Writer) error ClearObservers() IsInterfaceNil() bool }
LogOutputHandler defines the properties of a subject-observer component able to output log lines
type Logger ¶
type Logger interface { Trace(message string, args ...interface{}) Debug(message string, args ...interface{}) Info(message string, args ...interface{}) Warn(message string, args ...interface{}) Error(message string, args ...interface{}) LogIfError(err error, args ...interface{}) SetLevel(logLevel LogLevel) IsInterfaceNil() bool }
Logger defines the behavior of a data logger component
type PlainFormatter ¶
type PlainFormatter struct { }
PlainFormatter implements formatter interface and is used to format log lines to be written in the same form as ConsoleFormatter but it doesn't use the ANSI colors (useful when writing to a file, for example)
func (*PlainFormatter) IsInterfaceNil ¶
func (pf *PlainFormatter) IsInterfaceNil() bool
IsInterfaceNil returns true if there is no value under the interface
func (*PlainFormatter) Output ¶
func (pf *PlainFormatter) Output(line LogLineHandler) []byte
Output converts the provided LogLineHandler into a slice of bytes ready for output