debuglog

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 5 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextField

type ContextField func(Event) Event

func Bool

func Bool(key string, b bool) ContextField

func Int

func Int(key string, i int) ContextField

func Str

func Str(key, val string) ContextField

func Stringer

func Stringer(key string, val fmt.Stringer) ContextField

func Uint

func Uint(key string, i uint) ContextField

type Event

type Event interface {
	// Msg sends the Event with msg added as the message field if not empty.
	Msg(msg string)
	// Str adds the field key with val as a string to the Event.
	Str(key, val string) Event
	// Err adds the field "error" with serialized err to the Event.
	// If err is nil, no field is added.
	Err(err error) Event
	// Bool adds the field key with val as a bool to the Event.
	Bool(key string, b bool) Event
	// Int adds the field key with i as a int to the Event.
	Int(key string, i int) Event
	// Uint adds the field key with i as a uint to the Event.
	Uint(key string, i uint) Event
	// Stringer adds the field key with val.String() (or null if val is nil)
	// to the Event.
	Stringer(key string, val fmt.Stringer) Event
	// IsEnabled returns true if the Event is enabled for the given log level
	// It is helpful when you want to avoid expensive operations on formatting
	// the log fields.
	IsEnabled() bool
}

Event represents a log event. It is instanced by one of the level method of Logger and finalized by the Msg method.

type Level

type Level int8

Level is the type of log level

const (
	// LevelUnknown is a default value for unknown log level
	LevelUnknown Level = iota - 1
	// LevelNoLog is the lowest level of logging, no logs are generated
	LevelNoLog
	// LevelError is the level of logging only for errors
	LevelError
	// LevelWarn is the level of logging for warnings
	LevelWarn
	// LevelInfo is the lowest of logging for informational messages
	LevelInfo
	// LevelDebug is the level of logging for debug messages
	LevelDebug

	// LevelTrace is the highest level of logging
	LevelTrace
)

func (Level) String

func (level Level) String() string

String returns the string representation of the log level

func (Level) Valid

func (level Level) Valid() bool

Valid returns true if the log level is valid

type Logger

type Logger interface {
	// WithOutput duplicates the current logger and sets w as its output.
	WithOutput(w io.Writer) Logger

	// Level creates a child logger with the minimum accepted level set to level.
	WithLevel(lvl Level) Logger

	// WithOutput duplicates the current logger and adds context fields to it.
	With(...ContextField) Logger

	// Trace starts a new message with trace level.
	// You must call Msg on the returned event in order to send the event.
	Trace() Event

	// Debug starts a new message with debug level.
	// You must call Msg on the returned event in order to send the event.
	Debug() Event

	// Info starts a new message with info level.
	// You must call Msg on the returned event in order to send the event.
	Info() Event

	// Warn starts a new message with warn level.
	// You must call Msg on the returned event in order to send the event.
	Warn() Event

	// Error starts a new message with error level.
	// You must call Msg on the returned event in order to send the event.
	Error() Event
}

Logger is used to log SecDebugLog messages This interface is highly inspired in github.com/rs/zerolog logger and the aim is to avoid allocations while logging.

func Default

func Default() Logger

Default returns a default logger that writes to stderr.

func DefaultWithPrinterFactory

func DefaultWithPrinterFactory(f PrinterFactory) Logger

DefaultWithPrinterFactory returns a default logger that writes to stderr with a given printer factory. It is useful when you need to abstract the printer.

func Noop

func Noop() Logger

Noop returns a Logger which does no logging.

type Printer

type Printer func(lvl Level, message, fields string)

type PrinterFactory

type PrinterFactory func(w io.Writer) Printer

Jump to

Keyboard shortcuts

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