log

package
v4.25.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	LogOff   int = 0
	LogFatal int = 1
	LogError int = 2
	LogWarn  int = 3
	LogInfo  int = 4
	LogDebug int = 5
	LogTrace int = 6
	LogAll   int = 7
)

Logger level constants.

Variables

This section is empty.

Functions

func DocsMarkdown added in v4.2.0

func DocsMarkdown() ([]byte, error)

DocsMarkdown returns a markdown document for the logger documentation.

func NewBenthosLogAdapter added in v4.20.0

func NewBenthosLogAdapter(l *slog.Logger) *logHandler

func Spec

func Spec() docs.FieldSpecs

Spec returns a field spec for the logger configuration fields.

Types

type Config

type Config struct {
	LogLevel      string            `yaml:"level"`
	Format        string            `yaml:"format"`
	AddTimeStamp  bool              `yaml:"add_timestamp"`
	LevelName     string            `yaml:"level_name"`
	MessageName   string            `yaml:"message_name"`
	TimestampName string            `yaml:"timestamp_name"`
	StaticFields  map[string]string `yaml:"static_fields"`
	File          File              `yaml:"file"`
}

Config holds configuration options for a logger object.

func FromParsed added in v4.25.0

func FromParsed(pConf *docs.ParsedConfig) (conf Config, err error)

func NewConfig

func NewConfig() Config

NewConfig returns a config struct with the default values for each field.

func (*Config) UnmarshalYAML

func (conf *Config) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML ensures that when parsing configs that are in a slice the default values are still applied.

type File added in v4.2.0

type File struct {
	Path         string `yaml:"path"`
	Rotate       bool   `yaml:"rotate"`
	RotateMaxAge int    `yaml:"rotate_max_age_days"`
}

File contains configuration for file based logging.

type Logger

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

Logger is an object with support for levelled logging and modular components.

func (*Logger) Debug added in v4.25.0

func (l *Logger) Debug(format string, v ...any)

Debug prints a debug message to the console.

func (*Logger) Debugln

func (l *Logger) Debugln(message string)

Debugln prints a debug message to the console.

func (*Logger) Error added in v4.25.0

func (l *Logger) Error(format string, v ...any)

Error prints an error message to the console.

func (*Logger) Errorln

func (l *Logger) Errorln(message string)

Errorln prints an error message to the console.

func (*Logger) Fatal added in v4.25.0

func (l *Logger) Fatal(format string, v ...any)

Fatal prints a fatal message to the console. Does NOT cause panic.

func (*Logger) Fatalln

func (l *Logger) Fatalln(message string)

Fatalln prints a fatal message to the console. Does NOT cause panic.

func (*Logger) Info added in v4.25.0

func (l *Logger) Info(format string, v ...any)

Info prints an information message to the console.

func (*Logger) Infoln

func (l *Logger) Infoln(message string)

Infoln prints an information message to the console.

func (*Logger) Trace added in v4.25.0

func (l *Logger) Trace(format string, v ...any)

Trace prints a trace message to the console.

func (*Logger) Traceln

func (l *Logger) Traceln(message string)

Traceln prints a trace message to the console.

func (*Logger) Warn added in v4.25.0

func (l *Logger) Warn(format string, v ...any)

Warn prints a warning message to the console.

func (*Logger) Warnln

func (l *Logger) Warnln(message string)

Warnln prints a warning message to the console.

func (*Logger) With

func (l *Logger) With(keyValues ...any) Modular

With returns a copy of the logger with new labels added to the logging context.

func (*Logger) WithFields

func (l *Logger) WithFields(inboundFields map[string]string) Modular

WithFields returns a logger with new fields added to the JSON formatted output.

type Modular

type Modular interface {
	WithFields(fields map[string]string) Modular
	With(keyValues ...any) Modular

	Fatal(format string, v ...any)
	Error(format string, v ...any)
	Warn(format string, v ...any)
	Info(format string, v ...any)
	Debug(format string, v ...any)
	Trace(format string, v ...any)
}

Modular is a log printer that allows you to branch new modules.

func New added in v4.14.0

func New(stream io.Writer, fs ifs.FS, config Config) (Modular, error)

New returns a new logger from a config, or returns an error if the config is invalid.

func Noop

func Noop() Modular

Noop creates and returns a new logger object that writes nothing.

func Wrap

func Wrap(l PrintFormatter) Modular

Wrap a PrintFormatter with a log.Modular implementation. Log level is set to INFO, use WrapAtLevel to set this explicitly.

func WrapAtLevel

func WrapAtLevel(l PrintFormatter, level int) Modular

WrapAtLevel wraps a PrintFormatter with a log.Modular implementation with an explicit log level.

type PrintFormatter

type PrintFormatter interface {
	Printf(format string, v ...any)
	Println(v ...any)
}

PrintFormatter is an interface implemented by standard loggers.

Jump to

Keyboard shortcuts

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