log

package module
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 14 Imported by: 100

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorTrace = color.FgHiBlue
	ColorDebug = color.FgCyan
	ColorInfo  = color.FgGreen
	ColorWarn  = color.FgYellow
	ColorError = color.FgRed
	ColorFatal = color.FgMagenta
)
View Source
var (
	// Often samples log 10 events per second.
	SampleMany = &Sampler{N: 10, Period: time.Second}
	// Sometimes samples log 1 event per second.
	SampleSome = &Sampler{N: 1, Period: time.Second}
	// Rarely samples log 1 events per minute.
	SampleFew = &Sampler{N: 1, Period: time.Minute}
)
View Source
var Noop = func(string, ...any) {}

Functions

func Debug

func Debug(v ...any)

func Debugf

func Debugf(s string, v ...any)

func Error

func Error(v ...any)

func Errorf

func Errorf(s string, v ...any)

func Fatal

func Fatal(v ...any)

func Fatalf

func Fatalf(s string, v ...any)

func Info

func Info(v ...any)

func Infof

func Infof(s string, v ...any)

func Init

func Init(c *Config)

func ParseFlags

func ParseFlags(flags string) int

func Trace

func Trace(v ...any)

package level forwarders to the real logger implementation

func Tracef

func Tracef(s string, v ...any)

func Warn

func Warn(v ...any)

func Warnf

func Warnf(s string, v ...any)

Types

type Backend

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

func New

func New(c *Config) *Backend

func NewSyslog

func NewSyslog(c *Config) *Backend

func (Backend) Clone

func (x Backend) Clone() Logger

func (Backend) Debug

func (x Backend) Debug(v ...any)

func (Backend) Debugf

func (x Backend) Debugf(f string, v ...any)

func (Backend) Error

func (x Backend) Error(v ...any)

func (Backend) Errorf

func (x Backend) Errorf(f string, v ...any)

func (Backend) Fatal

func (x Backend) Fatal(v ...any)

func (Backend) Fatalf

func (x Backend) Fatalf(f string, v ...any)

func (Backend) Info

func (x Backend) Info(v ...any)

func (Backend) Infof

func (x Backend) Infof(f string, v ...any)

func (*Backend) IsColor added in v1.3.1

func (x *Backend) IsColor() bool

func (Backend) Level

func (x Backend) Level() Level

func (Backend) Logger

func (x Backend) Logger() *stdlog.Logger

func (Backend) NewLogger

func (x Backend) NewLogger(subsystem string) Logger

func (Backend) NewWriter

func (x Backend) NewWriter(l Level) io.Writer

func (Backend) Noop

func (x Backend) Noop(...any)

func (*Backend) SetLevel

func (x *Backend) SetLevel(l Level) Logger

func (*Backend) SetLevelString

func (x *Backend) SetLevelString(s string) Logger

func (Backend) Trace

func (x Backend) Trace(v ...any)

func (Backend) Tracef

func (x Backend) Tracef(f string, v ...any)

func (Backend) Warn

func (x Backend) Warn(v ...any)

func (Backend) Warnf

func (x Backend) Warnf(f string, v ...any)

func (*Backend) WithColor

func (x *Backend) WithColor(b bool) Logger

func (*Backend) WithFlags added in v1.2.4

func (x *Backend) WithFlags(f int) Logger

func (*Backend) WithLogger added in v1.3.1

func (x *Backend) WithLogger(l *stdlog.Logger) Logger

func (*Backend) WithSampler

func (x *Backend) WithSampler(s *Sampler) Logger

func (*Backend) WithTag

func (x *Backend) WithTag(tag string) Logger

func (Backend) Write

func (x Backend) Write(p []byte) (n int, err error)

type Config

type Config struct {
	Level            Level         `json:"level"`
	Flags            int           `json:"flags"`
	Backend          string        `json:"backend"`
	Addr             string        `json:"addr"`
	Facility         string        `json:"facility"`
	Ident            string        `json:"ident"`
	Filename         string        `json:"filename"`
	FileMode         os.FileMode   `json:"filemode"`
	ProgressInterval time.Duration `json:"progress"`
	NoColor          bool          `json:"nocolor"`
}

func NewConfig

func NewConfig() *Config

func (*Config) Check

func (cfg *Config) Check() error

func (*Config) ParseEnv

func (cfg *Config) ParseEnv()

type Level

type Level byte
const (
	LevelTrace Level = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
	LevelOff
	LevelInvalid
)

func ParseLevel

func ParseLevel(s string) Level

func (Level) MarshalText

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

func (Level) Prefix

func (l Level) Prefix() string

func (Level) String

func (l Level) String() string

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(data []byte) error

type LogFn

type LogFn func(...any)

type LogfFn

type LogfFn func(string, ...any)

type Logger

type Logger interface {
	Noop(...any)
	Trace(v ...any)
	Tracef(f string, v ...any)
	Debug(v ...any)
	Debugf(f string, v ...any)
	Info(v ...any)
	Infof(f string, v ...any)
	Warn(v ...any)
	Warnf(f string, v ...any)
	Error(v ...any)
	Errorf(f string, v ...any)
	Fatal(v ...any)
	Fatalf(f string, v ...any)
	Level() Level
	IsColor() bool
	SetLevel(Level) Logger
	SetLevelString(string) Logger
	Logger() *stdlog.Logger
	Clone() Logger
	WithTag(tag string) Logger
	WithSampler(s *Sampler) Logger
	WithColor(b bool) Logger
	WithFlags(f int) Logger
	WithLogger(l *stdlog.Logger) Logger
}
var (
	Log      Logger = New(NewConfig())
	Disabled Logger = &Backend{level: LevelOff, log: stdlog.Default()}
)

func NewLogger

func NewLogger(tag string) Logger

func SetLevel

func SetLevel(l Level) Logger

func SetLevelString

func SetLevelString(l string) Logger

type ProgressLogger

type ProgressLogger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewProgressLogger

func NewProgressLogger(logger Logger) *ProgressLogger

func (*ProgressLogger) Flush

func (p *ProgressLogger) Flush()

func (*ProgressLogger) Log

func (p *ProgressLogger) Log(n int, extra ...string)

func (*ProgressLogger) SetAction

func (l *ProgressLogger) SetAction(action string) *ProgressLogger

func (*ProgressLogger) SetEvent

func (l *ProgressLogger) SetEvent(event string) *ProgressLogger

func (*ProgressLogger) SetInterval

func (l *ProgressLogger) SetInterval(interval time.Duration) *ProgressLogger

type Sampler

type Sampler struct {
	// N is the maximum number of event per period allowed.
	N uint32
	// Period defines the period.
	Period time.Duration
	// contains filtered or unexported fields
}

Sampler lets a burst of N events pass per Period. If Period is0, every Nth event is allowed.

func (*Sampler) Clone

func (s *Sampler) Clone() *Sampler

func (*Sampler) Sample

func (s *Sampler) Sample() bool

Jump to

Keyboard shortcuts

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