Documentation
¶
Index ¶
- Variables
- func AddLogObserver(w io.Writer, formatter Formatter) error
- func ClearLogObservers()
- func GetLogLevelPattern() string
- func GetOrCreate(name string) *logger
- func IsEnabledCorrelation() bool
- func IsEnabledLoggerName() bool
- func NewLogLineWrapperFormatter(marshalizer marshal.Marshalizer) (*logLineWrapperFormatter, error)
- func NewLogOutputSubject() *logOutputSubject
- 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 ToggleCorrelation(enable bool)
- func ToggleLoggerName(enable bool)
- type ConsoleFormatter
- type Formatter
- type LogCorrelationMessage
- func (*LogCorrelationMessage) Descriptor() ([]byte, []int)
- func (this *LogCorrelationMessage) Equal(that interface{}) bool
- func (m *LogCorrelationMessage) GetEpoch() uint32
- func (m *LogCorrelationMessage) GetRound() int64
- func (m *LogCorrelationMessage) GetShard() string
- func (m *LogCorrelationMessage) GetSubRound() string
- func (this *LogCorrelationMessage) GoString() string
- func (m *LogCorrelationMessage) Marshal() (dAtA []byte, err error)
- func (m *LogCorrelationMessage) MarshalTo(dAtA []byte) (int, error)
- func (m *LogCorrelationMessage) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*LogCorrelationMessage) ProtoMessage()
- func (m *LogCorrelationMessage) Reset()
- func (m *LogCorrelationMessage) Size() (n int)
- func (this *LogCorrelationMessage) String() string
- func (m *LogCorrelationMessage) Unmarshal(dAtA []byte) error
- func (m *LogCorrelationMessage) XXX_DiscardUnknown()
- func (m *LogCorrelationMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *LogCorrelationMessage) XXX_Merge(src proto.Message)
- func (m *LogCorrelationMessage) XXX_Size() int
- func (m *LogCorrelationMessage) XXX_Unmarshal(b []byte) error
- type LogLevel
- type LogLine
- type LogLineHandler
- type LogLineMessage
- func (*LogLineMessage) Descriptor() ([]byte, []int)
- func (this *LogLineMessage) Equal(that interface{}) bool
- func (m *LogLineMessage) GetArgs() []string
- func (m *LogLineMessage) GetCorrelation() LogCorrelationMessage
- func (m *LogLineMessage) GetLogLevel() int32
- func (m *LogLineMessage) GetLoggerName() string
- func (m *LogLineMessage) GetMessage() string
- func (m *LogLineMessage) GetTimestamp() int64
- func (this *LogLineMessage) GoString() string
- func (m *LogLineMessage) Marshal() (dAtA []byte, err error)
- func (m *LogLineMessage) MarshalTo(dAtA []byte) (int, error)
- func (m *LogLineMessage) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*LogLineMessage) ProtoMessage()
- func (m *LogLineMessage) Reset()
- func (m *LogLineMessage) Size() (n int)
- func (this *LogLineMessage) String() string
- func (m *LogLineMessage) Unmarshal(dAtA []byte) error
- func (m *LogLineMessage) XXX_DiscardUnknown()
- func (m *LogLineMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *LogLineMessage) XXX_Merge(src proto.Message)
- func (m *LogLineMessage) XXX_Size() int
- func (m *LogLineMessage) XXX_Unmarshal(b []byte) error
- type LogLineWrapper
- type LogOutputHandler
- type Logger
- type PlainFormatter
- type Profile
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidLengthLogLineMessage = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowLogLineMessage = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupLogLineMessage = fmt.Errorf("proto: unexpected end of group") )
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 IsEnabledCorrelation ¶ added in v1.0.99
func IsEnabledCorrelation() bool
IsEnabledCorrelation returns whether correlation elements are enabled
func IsEnabledLoggerName ¶ added in v1.0.99
func IsEnabledLoggerName() bool
IsEnabledLoggerName returns whether logger name is enabled
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 SetCorrelationEpoch ¶ added in v1.0.99
func SetCorrelationEpoch(epoch uint32)
SetCorrelationEpoch sets the current epoch as a log correlation element
func SetCorrelationRound ¶ added in v1.0.99
func SetCorrelationRound(round int64)
SetCorrelationRound sets the current round as a log correlation element
func SetCorrelationShard ¶ added in v1.0.99
func SetCorrelationShard(shardID string)
SetCorrelationShard sets the current shard ID as a log correlation element
func SetCorrelationSubround ¶ added in v1.0.99
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 ToggleCorrelation ¶ added in v1.0.99
func ToggleCorrelation(enable bool)
ToggleCorrelation enables or disables correlation elements for log lines
func ToggleLoggerName ¶ added in v1.0.99
func ToggleLoggerName(enable bool)
Toggle enables / disables logger name
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 LogCorrelationMessage ¶ added in v1.0.99
type LogCorrelationMessage struct { Shard string `protobuf:"bytes,1,opt,name=Shard,proto3" json:"Shard,omitempty"` Epoch uint32 `protobuf:"varint,2,opt,name=Epoch,proto3" json:"Epoch,omitempty"` Round int64 `protobuf:"varint,3,opt,name=Round,proto3" json:"Round,omitempty"` SubRound string `protobuf:"bytes,4,opt,name=SubRound,proto3" json:"SubRound,omitempty"` }
func GetCorrelation ¶ added in v1.0.99
func GetCorrelation() LogCorrelationMessage
GetCorrelation gets global correlation elements
func (*LogCorrelationMessage) Descriptor ¶ added in v1.0.99
func (*LogCorrelationMessage) Descriptor() ([]byte, []int)
func (*LogCorrelationMessage) Equal ¶ added in v1.0.99
func (this *LogCorrelationMessage) Equal(that interface{}) bool
func (*LogCorrelationMessage) GetEpoch ¶ added in v1.0.99
func (m *LogCorrelationMessage) GetEpoch() uint32
func (*LogCorrelationMessage) GetRound ¶ added in v1.0.99
func (m *LogCorrelationMessage) GetRound() int64
func (*LogCorrelationMessage) GetShard ¶ added in v1.0.99
func (m *LogCorrelationMessage) GetShard() string
func (*LogCorrelationMessage) GetSubRound ¶ added in v1.0.99
func (m *LogCorrelationMessage) GetSubRound() string
func (*LogCorrelationMessage) GoString ¶ added in v1.0.99
func (this *LogCorrelationMessage) GoString() string
func (*LogCorrelationMessage) Marshal ¶ added in v1.0.99
func (m *LogCorrelationMessage) Marshal() (dAtA []byte, err error)
func (*LogCorrelationMessage) MarshalTo ¶ added in v1.0.99
func (m *LogCorrelationMessage) MarshalTo(dAtA []byte) (int, error)
func (*LogCorrelationMessage) MarshalToSizedBuffer ¶ added in v1.0.99
func (m *LogCorrelationMessage) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*LogCorrelationMessage) ProtoMessage ¶ added in v1.0.99
func (*LogCorrelationMessage) ProtoMessage()
func (*LogCorrelationMessage) Reset ¶ added in v1.0.99
func (m *LogCorrelationMessage) Reset()
func (*LogCorrelationMessage) Size ¶ added in v1.0.99
func (m *LogCorrelationMessage) Size() (n int)
func (*LogCorrelationMessage) String ¶ added in v1.0.99
func (this *LogCorrelationMessage) String() string
func (*LogCorrelationMessage) Unmarshal ¶ added in v1.0.99
func (m *LogCorrelationMessage) Unmarshal(dAtA []byte) error
func (*LogCorrelationMessage) XXX_DiscardUnknown ¶ added in v1.0.99
func (m *LogCorrelationMessage) XXX_DiscardUnknown()
func (*LogCorrelationMessage) XXX_Marshal ¶ added in v1.0.99
func (m *LogCorrelationMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*LogCorrelationMessage) XXX_Merge ¶ added in v1.0.99
func (m *LogCorrelationMessage) XXX_Merge(src proto.Message)
func (*LogCorrelationMessage) XXX_Size ¶ added in v1.0.99
func (m *LogCorrelationMessage) XXX_Size() int
func (*LogCorrelationMessage) XXX_Unmarshal ¶ added in v1.0.99
func (m *LogCorrelationMessage) XXX_Unmarshal(b []byte) error
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 LogLine ¶
type LogLine struct { LoggerName string Correlation 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() 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 LogLineMessage ¶ added in v1.0.93
type LogLineMessage struct { Message string `protobuf:"bytes,1,opt,name=Message,proto3" json:"Message,omitempty"` LogLevel int32 `protobuf:"varint,2,opt,name=LogLevel,proto3" json:"LogLevel,omitempty"` Args []string `protobuf:"bytes,3,rep,name=Args,proto3" json:"Args,omitempty"` Timestamp int64 `protobuf:"varint,4,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` LoggerName string `protobuf:"bytes,5,opt,name=LoggerName,proto3" json:"LoggerName,omitempty"` Correlation LogCorrelationMessage `protobuf:"bytes,6,opt,name=Correlation,proto3" json:"Correlation"` }
func (*LogLineMessage) Descriptor ¶ added in v1.0.93
func (*LogLineMessage) Descriptor() ([]byte, []int)
func (*LogLineMessage) Equal ¶ added in v1.0.93
func (this *LogLineMessage) Equal(that interface{}) bool
func (*LogLineMessage) GetArgs ¶ added in v1.0.93
func (m *LogLineMessage) GetArgs() []string
func (*LogLineMessage) GetCorrelation ¶ added in v1.0.99
func (m *LogLineMessage) GetCorrelation() LogCorrelationMessage
func (*LogLineMessage) GetLogLevel ¶ added in v1.0.93
func (m *LogLineMessage) GetLogLevel() int32
func (*LogLineMessage) GetLoggerName ¶ added in v1.0.99
func (m *LogLineMessage) GetLoggerName() string
func (*LogLineMessage) GetMessage ¶ added in v1.0.93
func (m *LogLineMessage) GetMessage() string
func (*LogLineMessage) GetTimestamp ¶ added in v1.0.93
func (m *LogLineMessage) GetTimestamp() int64
func (*LogLineMessage) GoString ¶ added in v1.0.93
func (this *LogLineMessage) GoString() string
func (*LogLineMessage) Marshal ¶ added in v1.0.93
func (m *LogLineMessage) Marshal() (dAtA []byte, err error)
func (*LogLineMessage) MarshalTo ¶ added in v1.0.93
func (m *LogLineMessage) MarshalTo(dAtA []byte) (int, error)
func (*LogLineMessage) MarshalToSizedBuffer ¶ added in v1.0.93
func (m *LogLineMessage) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*LogLineMessage) ProtoMessage ¶ added in v1.0.93
func (*LogLineMessage) ProtoMessage()
func (*LogLineMessage) Reset ¶ added in v1.0.93
func (m *LogLineMessage) Reset()
func (*LogLineMessage) Size ¶ added in v1.0.93
func (m *LogLineMessage) Size() (n int)
func (*LogLineMessage) String ¶ added in v1.0.93
func (this *LogLineMessage) String() string
func (*LogLineMessage) Unmarshal ¶ added in v1.0.93
func (m *LogLineMessage) Unmarshal(dAtA []byte) error
func (*LogLineMessage) XXX_DiscardUnknown ¶ added in v1.0.93
func (m *LogLineMessage) XXX_DiscardUnknown()
func (*LogLineMessage) XXX_Marshal ¶ added in v1.0.93
func (m *LogLineMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*LogLineMessage) XXX_Merge ¶ added in v1.0.93
func (m *LogLineMessage) XXX_Merge(src proto.Message)
func (*LogLineMessage) XXX_Size ¶ added in v1.0.93
func (m *LogLineMessage) XXX_Size() int
func (*LogLineMessage) XXX_Unmarshal ¶ added in v1.0.93
func (m *LogLineMessage) XXX_Unmarshal(b []byte) error
type LogLineWrapper ¶
type LogLineWrapper struct {
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
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
type Profile ¶ added in v1.0.99
Profile holds global logger options
func GetCurrentProfile ¶ added in v1.0.99
func GetCurrentProfile() Profile
GetCurrentProfile gets the current logger profile
func UnmarshalProfile ¶ added in v1.0.99
UnmarshalProfile deserializes into a Profile object