logger

package
v1.0.77 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2020 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidLogLevelPattern = errors.New("un-parsable log level and pattern provided")

ErrInvalidLogLevelPattern signals that an un-parsable log level and patter was provided

View Source
var ErrNilDisplayByteSliceHandler = errors.New("nil display byte slice handler")

ErrNilDisplayByteSliceHandler signals that a nil display byte slice handler has been provided

View Source
var ErrNilFormatter = errors.New("nil formatter provided")

ErrNilFormatter signals that a nil formatter has been provided

View Source
var ErrNilMarshalizer = errors.New("nil marshalizer")

ErrNilMarshalizer signals that a nil marshalizer has been provided

View Source
var ErrNilWriter = errors.New("nil writer provided")

ErrNilWriter signals that a nil writer has been provided

View Source
var ErrWriterNotFound = errors.New("writer not found while searching container")

ErrWriterNotFound signals that the provided writer was not found while searching container list

Levels contain all defined levels as a slice for an easier iteration

Functions

func AddLogObserver

func AddLogObserver(w io.Writer, formatter Formatter) error

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 ClearLogObservers

func ClearLogObservers()

ClearLogObservers clears the observers lists

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

func RemoveLogObserver(w io.Writer) error

RemoveLogObserver removes an exiting observer by providing the writer pointer.

func SetDisplayByteSlice

func SetDisplayByteSlice(f func(slice []byte) string) error

SetDisplayByteSlice sets the converter function from byte slice to string default, this will call hex.EncodeToString

func SetLogLevel

func SetLogLevel(logLevelAndPattern string) error

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

func GetLogLevel(logLevelAsString string) (LogLevel, error)

GetLogLevel gets the corresponding log level from provided string. The search is case insensitive.

func ParseLogLevelAndMatchingString

func ParseLogLevelAndMatchingString(logLevelAndPatterns string) ([]LogLevel, []string, error)

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

func (LogLevel) String

func (level LogLevel) String() string

type LogLine

type LogLine struct {
	Message   string
	LogLevel  LogLevel
	Args      []interface{}
	Timestamp time.Time
}

LogLine is the structure used to hold a log line

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

func (*LogLineWrapper) Load

func (llw *LogLineWrapper) Load(r io.Reader) error

Load loads the data from the stream into a log line message object through Capnp protocol

func (*LogLineWrapper) Save

func (llw *LogLineWrapper) Save(w io.Writer) error

Save saves the serialized data of a log line message into a stream through Capnp protocol

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL