logf

package
v0.11.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 12 Imported by: 5

Documentation

Overview

Package logf contains logging registry & extensions based on stdlib "log".

Index

Constants

This section is empty.

Variables

View Source
var Colored = true

Colored should be set if colored logging output is desired (colors are used for levels and context IDs).

Functions

func Debugf

func Debugf(ctx context.Context, pattern string, values ...any)

Debugf calls Debugf on default logger.

func Errorf

func Errorf(ctx context.Context, pattern string, values ...any)

Errorf calls Errorf on default logger.

func ForEach

func ForEach(f func(name string, logger Interface) bool)

ForEach applies f for each registered logger.

func Infof

func Infof(ctx context.Context, pattern string, values ...any)

Infof calls Infof on default logger.

func Panicf

func Panicf(ctx context.Context, pattern string, values ...any)

Panicf calls Panicf on default logger.

func Printf

func Printf(ctx context.Context, pattern string, values ...any)

Printf calls Printf on default logger.

func ResetFactory

func ResetFactory(factory Factory)

ResetFactory sets logger factory and removes all registered loggers.

func ResetLevel

func ResetLevel(level Level)

ResetLevel sets level for all registered loggers.

func Resultf

func Resultf(ctx context.Context, ok, bad Level, pattern string, values ...any)

Resultf calls Resultf on default logger.

func Tracef

func Tracef(ctx context.Context, pattern string, values ...any)

Tracef calls Tracef on default logger.

func Warnf

func Warnf(ctx context.Context, pattern string, values ...any)

Warnf calls Warnf on default logger.

Types

type Bare

type Bare interface {
	Logf(ctx context.Context, level Level, pattern string, values ...any)
}

Bare is a bare logger interface.

func NewStdLogger

func NewStdLogger(name string, flags int, writer io.Writer) Bare

NewStdLogger creates a new StdLogger instance.

type BareAdapter

type BareAdapter struct {
	Bare
	// contains filtered or unexported fields
}

BareAdapter is adapter for Bare to match Interface.

func (*BareAdapter) Debugf

func (a *BareAdapter) Debugf(ctx context.Context, pattern string, values ...any)

func (*BareAdapter) Errorf

func (a *BareAdapter) Errorf(ctx context.Context, pattern string, values ...any)

func (*BareAdapter) Infof

func (a *BareAdapter) Infof(ctx context.Context, pattern string, values ...any)

func (*BareAdapter) Level

func (a *BareAdapter) Level() Level

func (*BareAdapter) Logf

func (a *BareAdapter) Logf(ctx context.Context, level Level, pattern string, values ...any)

func (*BareAdapter) Panic

func (a *BareAdapter) Panic(ctx context.Context, value any)

func (*BareAdapter) Panicf

func (a *BareAdapter) Panicf(ctx context.Context, pattern string, values ...any)

func (*BareAdapter) Printf

func (a *BareAdapter) Printf(ctx context.Context, pattern string, values ...any)

func (*BareAdapter) Resultf

func (a *BareAdapter) Resultf(ctx context.Context, ok, bad Level, pattern string, values ...any)

func (*BareAdapter) SetLevel

func (a *BareAdapter) SetLevel(level Level)

func (*BareAdapter) Tracef

func (a *BareAdapter) Tracef(ctx context.Context, pattern string, values ...any)

func (*BareAdapter) Warnf

func (a *BareAdapter) Warnf(ctx context.Context, pattern string, values ...any)

type Factory

type Factory func(name string, defaultLogger Interface) Interface

Factory creates a logger for a provided name.

func DefaultFactory

func DefaultFactory() Factory

DefaultFactory returns default logger factory.

type Interface

type Interface interface {
	// SetLevel sets level for this logger.
	SetLevel(level Level)
	// Level returns current logging level.
	Level() Level
	// Logf logs the message with specified level.
	Logf(ctx context.Context, level Level, pattern string, values ...any)
	// Resultf uses `ok` level if the last argument is nil or `bad` level if the last argument is non-nil error.
	Resultf(ctx context.Context, ok, bad Level, pattern string, values ...any)
	// Printf prints log message with arguments.
	Printf(ctx context.Context, pattern string, values ...any)
	// Tracef prints log message with Trace level.
	Tracef(ctx context.Context, pattern string, values ...any)
	// Debugf prints log message with Debug level.
	Debugf(ctx context.Context, pattern string, values ...any)
	// Infof prints log message with Info level.
	Infof(ctx context.Context, pattern string, values ...any)
	// Warnf prints log message with Warn level.
	Warnf(ctx context.Context, pattern string, values ...any)
	// Errorf prints log message with Error level.
	Errorf(ctx context.Context, pattern string, values ...any)
	// Panicf prints log message with Panic level and panics.
	// This behavior is inherent in Resultf if `bad` == Panic.
	Panicf(ctx context.Context, pattern string, values ...any)
	// Panic prints error and panics.
	Panic(ctx context.Context, value any)
}

Interface is the main logger interface. Note that Interface instances should not be kept, but instead always got from Get.

func Default

func Default() Interface

Default returns default (no name) logger.

func Get

func Get(path ...any) Interface

Get returns a logger with name corresponding to path elements. Each path element is converted to string via flu.Readable. Level, io.Writer or Factory can also be passed and will be applied only when creating a new logger for the path.

type Level

type Level int8

Level is the logging level.

const (
	Trace Level = iota + 1
	Debug
	Info
	Warn
	Error
	Panic
	Silent
)

func ParseLevel

func ParseLevel(value string) (Level, error)

ParseLevel parses Level from string.

func (Level) MarshalJSON

func (l Level) MarshalJSON() ([]byte, error)

func (Level) MarshalYAML

func (l Level) MarshalYAML() (any, error)

func (Level) Skip

func (l Level) Skip(msgLevel Level) bool

Skip returns true if msgLevel does not match this level.

func (*Level) UnmarshalJSON

func (l *Level) UnmarshalJSON(data []byte) (err error)

func (*Level) UnmarshalYAML

func (l *Level) UnmarshalYAML(node *yaml.Node) (err error)

type OutputSetter

type OutputSetter interface {

	// SetOutput sets output for this logger.
	SetOutput(w io.Writer)
}

OutputSetter is a logger which supports resetting output.

type StdLogger

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

StdLogger is a wrapper for stdlib log.Logger with additional capabilities.

func (*StdLogger) Logf

func (l *StdLogger) Logf(ctx context.Context, level Level, pattern string, values ...any)

func (*StdLogger) SetOutput

func (l *StdLogger) SetOutput(w io.Writer)

Jump to

Keyboard shortcuts

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