logging

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogBuffer

type LogBuffer struct {
	// contains filtered or unexported fields
}

LogBuffer is a helper object that can be used to buffer log messages. A log buffer is effectively a list of arguments of any type. This object is especially useful when attempting to log complex objects (e.g. execution trace) that have complex coloring schemes and formatting. The LogBuffer can then be passed on to a Logger object to then log the buffer to console and any other writers (e.g. file).

func NewLogBuffer

func NewLogBuffer() *LogBuffer

NewLogBuffer creates a new LogBuffer object

func (*LogBuffer) Append

func (l *LogBuffer) Append(newElements ...any)

Append appends a variadic set of elements to the list of elements

func (*LogBuffer) Elements

func (l *LogBuffer) Elements() []any

Elements returns the list of elements stored in this LogBuffer

func (LogBuffer) String

func (l LogBuffer) String() string

String provides the non-colorized string representation of the LogBuffer

type LogFormat

type LogFormat string

LogFormat describes what format to log in

const (
	// STRUCTURED describes that logging should be done in structured JSON format
	STRUCTURED LogFormat = "structured"
	// UNSTRUCTRED describes that logging should be done in an unstructured format
	UNSTRUCTURED LogFormat = "unstructured"
)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger describes a custom logging object that can log events to any arbitrary channel in structured, unstructured with colors, and unstructured formats.

var GlobalLogger *Logger

GlobalLogger describes a Logger that is disabled by default and is instantiated when the fuzzer is created. Each module/package should create its own sub-logger. This allows to create unique logging instances depending on the use case.

func NewLogger

func NewLogger(level zerolog.Level) *Logger

NewLogger will create a new Logger object with a specific log level. By default, a logger that is instantiated with this function is not usable until a log channel is added. To add or remove channels that the logger streams logs to, call the Logger.AddWriter and Logger.RemoveWriter functions.

func (*Logger) AddWriter

func (l *Logger) AddWriter(writer io.Writer, format LogFormat, colored bool)

AddWriter will add a writer to which log output will go to. If the format is structured then the writer will get structured output. If the writer is unstructured, then the writer has the choice to either receive colored or un-colored output. Note that unstructured writers will be converted into a zerolog.ConsoleWriter to maintain the same format across all unstructured output streams.

func (*Logger) Debug

func (l *Logger) Debug(args ...any)

Debug is a wrapper function that will log a debug event

func (*Logger) Error

func (l *Logger) Error(args ...any)

Error is a wrapper function that will log an error event.

func (*Logger) Info

func (l *Logger) Info(args ...any)

Info is a wrapper function that will log an info event

func (*Logger) Level

func (l *Logger) Level() zerolog.Level

Level will get the log level of the Logger

func (*Logger) NewSubLogger

func (l *Logger) NewSubLogger(key string, value string) *Logger

NewSubLogger will create a new Logger with unique context in the form of a key-value pair. The expected use of this is for each module or component of the system to create their own contextualized logs. The key can be used to search for logs from a specific module or component.

func (*Logger) Panic

func (l *Logger) Panic(args ...any)

Panic is a wrapper function that will log a panic event

func (*Logger) RemoveWriter

func (l *Logger) RemoveWriter(writer io.Writer, format LogFormat, colored bool)

RemoveWriter will remove a writer from the list of writers that the logger manages. The writer will be either removed from the list of structured, unstructured and colored, or unstructured and un-colored writers. If the same writer is receiving multiple types of log output (e.g. structured and unstructured with color) then this function must be called multiple times. If the writer does not exist in any list, then this function is a no-op.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level zerolog.Level)

SetLevel will update the log level of the Logger

func (*Logger) Trace

func (l *Logger) Trace(args ...any)

Trace is a wrapper function that will log a trace event

func (*Logger) Warn

func (l *Logger) Warn(args ...any)

Warn is a wrapper function that will log a warning event both on console

type StructuredLogInfo

type StructuredLogInfo map[string]any

StructuredLogInfo describes a key-value mapping that can be used to log structured data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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