log

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package log contains the logging functions used by protosync.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Levels of logging.
	Levels = []Level{LevelTrace, LevelDebug, LevelInfo, LevelWarn, LevelError}
	// MinLevel of displayed logs.
	MinLevel = LevelWarn
	// LogOutput is the stdout for logs.
	LogOutput WriterFlusher = os.Stdout
	// LogError is the stderr for logs and where error+fatal logs are sent.
	LogError WriterFlusher = os.Stderr
	// Root logger.
	Root = &Logger{}
)

Functions

func Configure

func Configure(config Config) error

Configure global logging.

func Debugf

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

Debugf logs a debug message.

func Elapsed

func Elapsed(log *Logger, message string, args ...interface{}) func()

Elapsed logs the duration of a function call. Use with defer:

defer Elapsed(log, "something")()

func Errorf

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

Errorf logs an error.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf logs an error and terminates the process.

func Infof

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

Infof logs an informational message.

func Logf

func Logf(level Level, format string, args ...interface{})

Logf logs at the given level.

func Tracef

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

Tracef logs a trace message.

func Warnf

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

Warnf logs a warning.

Types

type Config

type Config struct {
	Level Level `help:"Minimum log level." default:"info"`
}

Config for logger.

type Level

type Level int

Level for a log message.

const (
	LevelTrace Level = iota // trace
	LevelDebug              // debug
	LevelInfo               // info
	LevelWarn               // warn
	LevelError              // error
	LevelFatal              // fatal
)

Log levels.

func LevelFromString

func LevelFromString(s string) (Level, error)

LevelFromString maps a level to a string.

func (Level) String

func (i Level) String() string

func (*Level) UnmarshalText

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

type Logger

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

Logger is a scoped logging object.

func (*Logger) Debugf

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

Debugf logs a debug message.

func (*Logger) Errorf

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

Errorf logs an error.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

Fatalf logs an error and terminates the process.

func (*Logger) Infof

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

Infof logs an informational message.

func (*Logger) Logf

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

Logf logs at the given level.

func (*Logger) SubLogger

func (l *Logger) SubLogger(id string) *Logger

SubLogger creates a new sub-logger from a string prefix (or Builder).

func (*Logger) Tracef

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

Tracef logs a trace message.

func (*Logger) Warnf

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

Warnf logs a warning.

func (*Logger) Write

func (l *Logger) Write(b []byte) (int, error)

Write to the logger. Each line will have the logger prefix prepended.

type WriterFlusher

type WriterFlusher interface {
	io.Writer
	Sync() error
}

WriterFlusher is used to flush log output after each line.

Jump to

Keyboard shortcuts

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