logging

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: BSD-3-Clause Imports: 11 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextKey

type ContextKey struct{}

type CreateOptions

type CreateOptions func(c *createOpts)

functional options for creating a logger.

func OptColor

func OptColor() CreateOptions

option to enable color output.

func OptExit

func OptExit(exit func(code int)) CreateOptions

option to set the exit function for the logger. useful for testing.

func OptFlags

func OptFlags(flags int) CreateOptions

option to set flags for the logger.

func OptLevel

func OptLevel(level Level) CreateOptions

option to set the log level for the logger.

func OptWriter

func OptWriter(w io.Writer) CreateOptions

option to set the writer for the logger.

type Level

type Level uint8

Setting a level prevents messages with a lower level from being logged. The default level is LInfo, suppressing debug messages.

const (
	// lowest level.
	LDebug Level = iota + 1
	// default level.
	LInfo
	LWarn
	LError
	LFatal
	// highest level.
	LNone
)

type Logger

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

logger wraps log.Logger.

func Create

func Create(options ...CreateOptions) *Logger

creates a new logger with the given options.

func FromContext

func FromContext(ctx context.Context) *Logger

retrieves a logger from a context, see Logger.WithContext.

func (*Logger) Debug

func (logger *Logger) Debug(msg ...any)

sends a message with level debug.

func (*Logger) DebugData

func (logger *Logger) DebugData(data map[string]any, msg ...any)

sends a message with level debug and data. Note data ordering is not stable.

func (*Logger) Debugf

func (logger *Logger) Debugf(format string, args ...any)

sends a formatted message with level debug.

func (*Logger) Error

func (logger *Logger) Error(msg ...any)

sends a message with level error.

func (*Logger) ErrorData

func (logger *Logger) ErrorData(data map[string]any, msg ...any)

sends a message with level error and data. Note data ordering is not stable.

func (*Logger) Errorf

func (logger *Logger) Errorf(format string, args ...any)

sends a formatted message with level error.

func (*Logger) Fatal

func (logger *Logger) Fatal(msg ...any)

sends a message with level fatal and calls the logger exit function.

func (*Logger) FatalData

func (logger *Logger) FatalData(data map[string]any, msg ...any)

sends a message with level fatal, data, and calls the logger exit function.

func (*Logger) Fatalf

func (logger *Logger) Fatalf(format string, args ...any)

sends a formatted message with level fatal and calls the logger exit function.

func (*Logger) Info

func (logger *Logger) Info(msg ...any)

sends a message with level info.

func (*Logger) InfoData

func (logger *Logger) InfoData(data map[string]any, msg ...any)

sends a message with level info and data. Note data ordering is not stable.

func (*Logger) Infof

func (logger *Logger) Infof(format string, args ...any)

sends a formatted message with level info.

func (*Logger) SetLevel

func (logger *Logger) SetLevel(level Level)

set the level of the logger, lesser messages will be ignored.

func (*Logger) Stacktrace

func (logger *Logger) Stacktrace(level Level, allGoroutines bool)

prints a stacktrace as a log message with customizable level.

func (*Logger) Warn

func (logger *Logger) Warn(msg ...any)

sends a message with level warn.

func (*Logger) WarnData

func (logger *Logger) WarnData(data map[string]any, msg ...any)

sends a message with level warn and data. Note data ordering is not stable.

func (*Logger) Warnf

func (logger *Logger) Warnf(format string, args ...any)

sends a formatted message with level warn.

func (*Logger) WithContext

func (logger *Logger) WithContext(ctx context.Context) context.Context

set a logger in this context, retrieve it with FromContext.

Jump to

Keyboard shortcuts

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