log

package
v4.5.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: MIT Imports: 9 Imported by: 0

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 Spec

func Spec() docs.FieldSpecs

Spec returns a field spec for the logger configuration fields.

Types

type Config

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

Config holds configuration options for a logger object.

func NewConfig

func NewConfig() Config

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

func (*Config) UnmarshalJSON

func (conf *Config) UnmarshalJSON(bytes []byte) error

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

func (*Config) UnmarshalYAML

func (conf *Config) UnmarshalYAML(unmarshal func(interface{}) 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 `json:"path" yaml:"path"`
	Rotate       bool   `json:"rotate" yaml:"rotate"`
	RotateMaxAge int    `json:"rotate_max_age_days" 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) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

Debugf 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) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

Errorf 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) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf 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) Infof

func (l *Logger) Infof(format string, v ...interface{})

Infof 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) Tracef

func (l *Logger) Tracef(format string, v ...interface{})

Tracef 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) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

Warnf 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 ...interface{}) 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 ...interface{}) Modular

	Fatalf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Debugf(format string, v ...interface{})
	Tracef(format string, v ...interface{})

	Fatalln(message string)
	Errorln(message string)
	Warnln(message string)
	Infoln(message string)
	Debugln(message string)
	Traceln(message string)
}

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

func NewV2

func NewV2(stream io.Writer, config Config) (Modular, error)

NewV2 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 ...interface{})
	Println(v ...interface{})
}

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