log

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = New()
View Source
var DefaultWriter = os.Stdout

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(msg string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(msg string, args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(msg string, args ...interface{})

func Log added in v0.5.0

func Log(level Level, offset int, args ...interface{})

func Logf added in v0.5.0

func Logf(level Level, offset int, msg string, args ...interface{})

func NewConsoleWriter

func NewConsoleWriter(cfg ConsoleConfig, out io.Writer) io.Writer

func Trace

func Trace(args ...interface{})

func Tracef

func Tracef(msg string, args ...interface{})

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(msg string, args ...interface{})

Types

type ConsoleConfig

type ConsoleConfig struct {
	Colorful bool
}

type ConsoleWriter

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

func (*ConsoleWriter) Write

func (cw *ConsoleWriter) Write(p []byte) (n int, err error)

func (*ConsoleWriter) WriteLog

func (cw *ConsoleWriter) WriteLog(p []byte, level Level, when time.Time) (n int, err error)

type Level

type Level int8

A Level is a logging priority. Higher levels are more important.

const (
	TraceLevel Level = iota + 1
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
)

func ParseLevel

func ParseLevel(text string) (Level, error)

ParseLevel parses a level based on the lower-case or all-caps ASCII representation of the log level. If the provided ASCII representation is invalid an error is returned.

This is particularly useful when dealing with text input to configure log levels.

func (Level) Enabled

func (l Level) Enabled(lvl Level) bool

Enabled returns true if the given level is at or above this level.

func (Level) LogPrefix

func (l Level) LogPrefix() string

func (Level) MarshalText

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

MarshalText marshals the Level to text. Note that the text representation drops the -Level suffix (see example).

func (Level) String

func (l Level) String() string

String returns a lower-case ASCII representation of the log level.

func (*Level) UnmarshalText

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

UnmarshalText unmarshals text to a level. Like MarshalText, UnmarshalText expects the text representation of a Level to drop the -Level suffix.

In particular, this makes it easy to configure logging levels using YAML, TOML, or JSON files.

type Logger

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

func New

func New(opts ...Option) *Logger

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(msg string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(msg string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(msg string, args ...interface{})

func (*Logger) Log added in v0.5.0

func (l *Logger) Log(level Level, offset int, args ...interface{})

func (*Logger) Logf added in v0.5.0

func (l *Logger) Logf(level Level, offset int, msg string, args ...interface{})

func (*Logger) Trace

func (l *Logger) Trace(args ...interface{})

func (*Logger) Tracef

func (l *Logger) Tracef(msg string, args ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(msg string, args ...interface{})

func (*Logger) WithOptions

func (l *Logger) WithOptions(opts ...Option) *Logger

WithOptions returns a new Logger with the given Options. It does not modify the original Logger.

type Option

type Option interface {
	// contains filtered or unexported methods
}

An Option configures a Logger.

func AddCallerSkip

func AddCallerSkip(skip int) Option

func WithCaller

func WithCaller(enabled bool) Option

func WithClock

func WithClock(clock clock.Clock) Option

WithClock specifies the clock used by the logger to determine the current time for logged entries. Defaults to the system clock with time.Now.

func WithLevel

func WithLevel(l Level) Option

func WithOutput

func WithOutput(w io.Writer) Option

type RotateFileConfig

type RotateFileConfig struct {
	FileName string
	Mode     RotateFileMode
	MaxDays  int

	Clock clock.Clock
}

type RotateFileMode

type RotateFileMode string
const (
	RotateFileModeNone  RotateFileMode = ""
	RotateFileModeDaily RotateFileMode = "daily"
)

type RotateFileWriter

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

func NewRotateFileWriter

func NewRotateFileWriter(cfg RotateFileConfig) *RotateFileWriter

func (*RotateFileWriter) Close

func (fw *RotateFileWriter) Close() error

func (*RotateFileWriter) Init

func (fw *RotateFileWriter) Init()

func (*RotateFileWriter) Rotate

func (fw *RotateFileWriter) Rotate() error

func (*RotateFileWriter) Write

func (fw *RotateFileWriter) Write(p []byte) (n int, err error)

func (*RotateFileWriter) WriteLog

func (fw *RotateFileWriter) WriteLog(p []byte, _ Level) (int, error)

type Writer added in v0.5.0

type Writer interface {
	WriteLog([]byte, Level, time.Time) (n int, err error)
}

Jump to

Keyboard shortcuts

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