log

package module
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 13 Imported by: 89

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorTrace = color.FgBlue
	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, ...interface{}) {}

Functions

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(s string, v ...interface{})

func Error

func Error(v ...interface{})

func Errorf

func Errorf(s string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

func Fatalf

func Fatalf(s string, v ...interface{})

func Info

func Info(v ...interface{})

func Infof

func Infof(s string, v ...interface{})

func Init

func Init(config *Config)

func ParseFlags

func ParseFlags(flags string) int

func Trace

func Trace(v ...interface{})

package level forwarders to the real logger implementation

func Tracef

func Tracef(s string, v ...interface{})

func Warn

func Warn(v ...interface{})

func Warnf

func Warnf(s string, v ...interface{})

Types

type Backend

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

func New

func New(config *Config) *Backend

func NewSyslog

func NewSyslog(config *Config) *Backend

func (Backend) Clone

func (x Backend) Clone() Logger

func (Backend) Debug

func (x Backend) Debug(v ...interface{})

func (Backend) Debugf

func (x Backend) Debugf(f string, v ...interface{})

func (Backend) Error

func (x Backend) Error(v ...interface{})

func (Backend) Errorf

func (x Backend) Errorf(f string, v ...interface{})

func (Backend) Fatal

func (x Backend) Fatal(v ...interface{})

func (Backend) Fatalf

func (x Backend) Fatalf(f string, v ...interface{})

func (Backend) Info

func (x Backend) Info(v ...interface{})

func (Backend) Infof

func (x Backend) Infof(f string, v ...interface{})

func (Backend) Level

func (x Backend) Level() Level

func (Backend) Logger

func (x Backend) Logger() *log.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(...interface{})

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

func (Backend) Tracef

func (x Backend) Tracef(f string, v ...interface{})

func (Backend) Warn

func (x Backend) Warn(v ...interface{})

func (Backend) Warnf

func (x Backend) Warnf(f string, v ...interface{})

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) 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 Closure

type Closure func() string

Closure is a closure that can be printed with %v to be used to generate expensive-to-create data for a detailed log level and avoid doing the work if the data isn't printed.

func NewClosure

func NewClosure(c func() string) Closure

NewLogClosure returns a new closure over the passed function which allows it to be used as a parameter in a logging function that is only invoked when the logging level is such that the message will actually be logged.

func (Closure) String

func (c Closure) String() string

String invokes the log closure and returns the results string.

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 int
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(...interface{})

type LogfFn

type LogfFn func(string, ...interface{})

type Logger

type Logger interface {
	Noop(...interface{})
	Trace(v ...interface{})
	Tracef(f string, v ...interface{})
	Debug(v ...interface{})
	Debugf(f string, v ...interface{})
	Info(v ...interface{})
	Infof(f string, v ...interface{})
	Warn(v ...interface{})
	Warnf(f string, v ...interface{})
	Error(v ...interface{})
	Errorf(f string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(f string, v ...interface{})
	Level() Level
	SetLevel(Level) Logger
	SetLevelString(string) Logger
	Logger() *logpkg.Logger
	Clone() Logger
	WithTag(tag string) Logger
	WithSampler(s *Sampler) Logger
	WithColor(b bool) Logger
	WithFlags(f int) Logger
}
var (
	Log      Logger = New(NewConfig())
	Disabled Logger = &Backend{level: LevelOff, log: log.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