logging

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Json

type Json struct {

	// Level is the log level this Text logger will include in its output.
	//
	// This defaults to Info.
	Level Level

	// Out is the stream that this Text logger will write to.
	//
	// This defaults to os.Stderr.
	Out io.Writer

	// DateTimeFormat is the format any log messages should write the date and
	// time of the format.
	//
	// This should be provided in the same format that is supported by the
	// Time.Format function: https://pkg.go.dev/time#Time.Format.
	//
	// This defaults to time.RFC3339Nano.
	DateTimeFormat string

	// AdditionalFields contains any extra fields that should be attached to the
	// written log entries.
	AdditionalFields map[string]interface{}
	// contains filtered or unexported fields
}

func JsonLogger

func JsonLogger() *Json

func (*Json) Copy

func (j *Json) Copy() *Json

func (*Json) Error

func (j *Json) Error(message string) error

func (*Json) Errorf

func (j *Json) Errorf(format string, args ...any) error

func (*Json) Info

func (j *Json) Info(message string) error

func (*Json) Infof

func (j *Json) Infof(format string, args ...any) error

func (*Json) Print

func (j *Json) Print(level Level, message string) error

func (*Json) Printf

func (j *Json) Printf(level Level, format string, args ...any) error

func (*Json) Trace

func (j *Json) Trace(message string) error

func (*Json) Tracef

func (j *Json) Tracef(format string, args ...any) error

func (*Json) Warn

func (j *Json) Warn(message string) error

func (*Json) Warnf

func (j *Json) Warnf(format string, args ...any) error

func (*Json) WithError

func (j *Json) WithError(err error) Logger

func (*Json) WithField

func (j *Json) WithField(key string, value interface{}) Logger

func (*Json) WithFields

func (j *Json) WithFields(fields map[string]interface{}) Logger

type Level

type Level int
const (
	None Level = iota
	Error
	Warn
	Info
	Trace
)

func (*Level) Set

func (level *Level) Set(value string) error

func (Level) String

func (level Level) String() string

type Logger

type Logger interface {
	Print(level Level, message string) error
	Printf(level Level, format string, args ...any) error

	Error(message string) error
	Errorf(format string, args ...any) error

	Warn(message string) error
	Warnf(format string, args ...any) error

	Info(message string) error
	Infof(format string, args ...any) error

	Trace(message string) error
	Tracef(format string, args ...any) error

	WithError(err error) Logger
	WithField(key string, value interface{}) Logger
	WithFields(fields map[string]interface{}) Logger
}

type Text

type Text struct {

	// Level is the log level this Text logger will include in its output.
	//
	// This defaults to Info.
	Level Level

	// Out is the stream that this Text logger will write to.
	//
	// This defaults to os.Stderr.
	Out io.Writer

	// Format is the format this Text logger will write log messages.
	//
	// This defaults to "[%L] %T: %e%m%f\n".
	//
	// It can be overridden to customise the format of the log messages. The
	// following elements are supported:
	//   - %m: The actual log message.
	//   - %T: The date time of the log message, this can be further customised
	//         by editing the DateTimeFormat field.
	//   - %L: The current log level.
	//   - %e: The value for any attached error, this can be further customised.
	//   - %f: The value for any additional fields, this can be further
	//         customised by editing the AdditionalFieldsFormat field.
	Format string

	// DateTimeFormat is the format any log messages should write the date and
	// time of the format.
	//
	// This should be provided in the same format that is supported by the
	// Time.Format function: https://pkg.go.dev/time#Time.Format.
	//
	// This defaults to time.RFC3339Nano.
	DateTimeFormat string

	// ErrorFormat describes how any attached error should be rendered.
	//
	// This defaults to "(%s) ", the %s is where the error will be rendered.
	ErrorFormat string

	// AdditionalFieldsFormat describes how any additional fields should be
	// rendered.
	//
	// This defaults to " [%s]", where %s is the fields joined into a writable
	// list format using the ',' character.
	AdditionalFieldsFormat string

	// AdditionalFields contains any extra fields that should be attached to the
	// written log entries.
	//
	// The key for a field can be specified in the Format preceded by a '%'
	// character in order to customise exactly where the additional fields will
	// be rendered. You can also override existing keys using the
	// AdditionalFields parameter.
	//
	// Or, you can specify %f to render all the fields using the
	// AdditionalFieldsFormat parameter.
	AdditionalFields map[string]interface{}
	// contains filtered or unexported fields
}

Text is a simple Logger that writes messages in a given format to a specified output. It is designed to write out human-readable logs.

func TextLogger

func TextLogger() *Text

func (*Text) Copy

func (text *Text) Copy() *Text

Copy creates a copy of the current Text logger.

func (*Text) Error

func (text *Text) Error(message string) error

func (*Text) Errorf

func (text *Text) Errorf(format string, args ...any) error

func (*Text) Info

func (text *Text) Info(message string) error

func (*Text) Infof

func (text *Text) Infof(format string, args ...any) error

func (*Text) Print

func (text *Text) Print(level Level, message string) error

func (*Text) Printf

func (text *Text) Printf(level Level, format string, args ...any) error

func (*Text) Trace

func (text *Text) Trace(message string) error

func (*Text) Tracef

func (text *Text) Tracef(format string, args ...any) error

func (*Text) Warn

func (text *Text) Warn(message string) error

func (*Text) Warnf

func (text *Text) Warnf(format string, args ...any) error

func (*Text) WithError

func (text *Text) WithError(err error) Logger

func (*Text) WithField

func (text *Text) WithField(key string, value interface{}) Logger

func (*Text) WithFields

func (text *Text) WithFields(fields map[string]interface{}) Logger

Jump to

Keyboard shortcuts

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