Documentation ¶
Index ¶
- Variables
- func AddLogObserver(w io.Writer, formatter Formatter) error
- func ClearLogObservers()
- func DisplayByteSlice(slice []byte) string
- func GetCorrelation() proto.LogCorrelationMessage
- func GetLogLevelPattern() string
- func GetOrCreate(name string) *logger
- func IsEnabledCorrelation() bool
- func IsEnabledLoggerName() bool
- func NewLogLineWrapperFormatter(marshalizer Marshalizer) (*logLineWrapperFormatter, error)
- func NewLogOutputSubject() *logOutputSubject
- func NewLogger(name string, logLevel LogLevel, logOutput LogOutputHandler) *logger
- func NewProfileChangeSubject() *profileChangeSubject
- func NotifyProfileChange()
- func RemoveLogObserver(w io.Writer) error
- func SetCorrelationEpoch(epoch uint32)
- func SetCorrelationRound(round int64)
- func SetCorrelationShard(shardID string)
- func SetCorrelationSubround(subRound string)
- func SetDisplayByteSlice(f func(slice []byte) string) error
- func SetLogLevel(logLevelAndPattern string) error
- func SubscribeToProfileChange(observer ProfileChangeObserver)
- func ToHex(slice []byte) string
- func ToHexShort(slice []byte) string
- func ToggleCorrelation(enable bool)
- func ToggleLoggerName(enable bool)
- func UnsubscribeFromProfileChange(observer ProfileChangeObserver)
- type ConsoleFormatter
- type Formatter
- type LogLevel
- type LogLine
- type LogLineHandler
- type LogLineWrapper
- type LogOutputHandler
- type Logger
- type Marshalizer
- type PlainFormatter
- type Profile
- type ProfileChangeObserver
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 DisplayByteSlice ¶
DisplayByteSlice converts the provided byte slice to its string representation using displayByteSlice function pointer
func GetCorrelation ¶
func GetCorrelation() proto.LogCorrelationMessage
GetCorrelation gets global correlation elements
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 IsEnabledCorrelation ¶
func IsEnabledCorrelation() bool
IsEnabledCorrelation returns whether correlation elements are enabled
func IsEnabledLoggerName ¶
func IsEnabledLoggerName() bool
IsEnabledLoggerName returns whether logger name is enabled
func NewLogLineWrapperFormatter ¶
func NewLogLineWrapperFormatter(marshalizer 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 NewLogger ¶ added in v1.0.2
func NewLogger(name string, logLevel LogLevel, logOutput LogOutputHandler) *logger
NewLogger create a new logger instance
func NewProfileChangeSubject ¶ added in v1.0.2
func NewProfileChangeSubject() *profileChangeSubject
NewProfileChangeSubject -
func NotifyProfileChange ¶ added in v1.0.2
func NotifyProfileChange()
NotifyProfileChange notifies observers about a profile change
func RemoveLogObserver ¶
RemoveLogObserver removes an exiting observer by providing the writer pointer.
func SetCorrelationEpoch ¶
func SetCorrelationEpoch(epoch uint32)
SetCorrelationEpoch sets the current epoch as a log correlation element
func SetCorrelationRound ¶
func SetCorrelationRound(round int64)
SetCorrelationRound sets the current round as a log correlation element
func SetCorrelationShard ¶
func SetCorrelationShard(shardID string)
SetCorrelationShard sets the current shard ID as a log correlation element
func SetCorrelationSubround ¶
func SetCorrelationSubround(subRound string)
SetCorrelationSubround sets the current sub-round as a log correlation element
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
func SubscribeToProfileChange ¶ added in v1.0.2
func SubscribeToProfileChange(observer ProfileChangeObserver)
SubscribeToProfileChange subscribes an observer
func ToHexShort ¶
ToHexShort generates a short-hand of provided bytes slice showing only the first 3 and the last 3 bytes as hex in total, the resulting string is maximum 13 characters long
func ToggleCorrelation ¶
func ToggleCorrelation(enable bool)
ToggleCorrelation enables or disables correlation elements for log lines
func ToggleLoggerName ¶
func ToggleLoggerName(enable bool)
ToggleLoggerName enables / disables logger name
func UnsubscribeFromProfileChange ¶ added in v1.0.2
func UnsubscribeFromProfileChange(observer ProfileChangeObserver)
UnsubscribeFromProfileChange unsubscribes an observer
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 GetLoggerLogLevel ¶ added in v1.0.1
GetLoggerLogLevel gets the log level of the specified logger
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 LogLine ¶
type LogLine struct { LoggerName string Correlation proto.LogCorrelationMessage Message string LogLevel LogLevel Args []interface{} Timestamp time.Time }
LogLine is the structure used to hold a log line
type LogLineHandler ¶
type LogLineHandler interface { GetLoggerName() string GetCorrelation() proto.LogCorrelationMessage 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 {
proto.LogLineMessage
}
LogLineWrapper is a wrapper over protobuf.LogLineMessage that enables the structure to be used with protobuf marshaller
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
func GetLogOutputSubject ¶ added in v1.0.2
func GetLogOutputSubject() LogOutputHandler
GetLogOutputSubject returns the default log output subject
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{}) Log(logLevel LogLevel, message string, args ...interface{}) LogLine(line *LogLine) SetLevel(logLevel LogLevel) GetLevel() LogLevel IsInterfaceNil() bool }
Logger defines the behavior of a data logger component
type Marshalizer ¶
type Marshalizer interface { Marshal(obj interface{}) ([]byte, error) Unmarshal(obj interface{}, buff []byte) error IsInterfaceNil() bool }
Marshalizer defines the 2 basic operations: serialize (marshal) and deserialize (unmarshal)
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
type Profile ¶
Profile holds global logger options
func GetCurrentProfile ¶
func GetCurrentProfile() Profile
GetCurrentProfile gets the current logger profile
func UnmarshalProfile ¶
UnmarshalProfile deserializes into a Profile object
type ProfileChangeObserver ¶ added in v1.0.2
type ProfileChangeObserver interface {
OnProfileChanged()
}
ProfileChangeObserver defines the interface for observing profile changes