logger

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NumMessages   = 10 * 1024 // number of allowed log messages
	STDOUT_FORMAT = "2006-01-02T15:04:05.000 "

	LOG_INFO    = 2
	LOG_DEBUG   = 1
	LOG_ERR     = 4
	LOG_WARNING = 3
)

Variables

View Source
var (
	// offLogger is a dummy no-op logger.
	OffLogger = New(Levels.Off)

	// Levels is a singleton that represents possible log levels.
	Levels = struct {
		Off    Level
		Panic  Level
		Error  Level
		Warn   Level
		Info   Level
		Debug  Level
		Access Level
	}{
		Access: (-1),
		Off:    (0),
		Panic:  (1),
		Error:  (2),
		Warn:   (3),
		Info:   (4),
		Debug:  (5),
	}

	// CfgLevels maps strings to Level. The intent is to use this during config
	// time.
	CfgLevels = map[string]Level{
		"access": Levels.Access,
		"off":    Levels.Off,
		"panic":  Levels.Panic,
		"error":  Levels.Error,
		"warn":   Levels.Warn,
		"info":   Levels.Info,
		"debug":  Levels.Debug,
	}
)
View Source
var (
	ErrLogFullBuf           = errors.New("Log message queue is full")
	ErrFreeMessageOverflow  = errors.New("Too many free messages. Overflow of fixed	set.")
	ErrFreeMessageUnderflow = errors.New("Too few free messages. Underflow of fixed	set.")
)

Functions

func Close

func Close(ctx context.Context) error

Close shuts down the logger system. After Close is called, any additional logs will panic. Only call this if you are completely done.

func Drain

func Drain()

Drain is like DrainContext, but you didn't want to write context.Background(). Outside of tests, you want to use DrainContext.

func DrainContext

func DrainContext(ctx context.Context) error

DrainContext blocks until it sees no pending messages or the context is canceled. Pending messages may never run out if another goroutine is constantly writing.

func SetLogName

func SetLogName(p string) (err error)

SetLogName sets the indentifier used by syslog for this program

func SetStdErr

func SetStdErr()

func SetStdOut

func SetStdOut()

func SetTee

func SetTee(tee chan string)

func Stats

func Stats() (logs, pending, drop, errs uint64)

Stats returns the current status of the logger. It reports: * logs: number of logs attempted to be written since startup * pending: number of logs queued to be written * drop: numer of logs that have been dropped, because the write queue is full, since startup * errs: number of errors seen while trying to write logs since startup

Types

type Level

type Level int

func (Level) String

func (level Level) String() string

type Logger

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

func New

func New(level Level) (l *Logger)

func (*Logger) Debug

func (l *Logger) Debug(prefix, format string, v ...interface{})

Debug logs a printf-style debug message (deprecated, please use Debugf)

func (*Logger) Debugf

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

Debugf logs a printf-style debug message

func (*Logger) Error

func (l *Logger) Error(prefix, format string, v ...interface{})

Error logs a printf-style error message (deprecated, please use Errorf)

func (*Logger) Errorf

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

Errorf logs a printf-style error message

func (*Logger) Info

func (l *Logger) Info(prefix, format string, v ...interface{})

Info logs a printf-style info message (deprecated, please use Infof)

func (*Logger) Infof

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

Infof logs a printf-style info message

func (*Logger) Level

func (l *Logger) Level() Level

func (*Logger) Panic

func (l *Logger) Panic(prefix, format string, v ...interface{})

Panic logs a printf-style panic message (deprecated, please use Panicf)

func (*Logger) Panicf

func (l *Logger) Panicf(prefix, format string, v ...interface{})

Panicf logs a printf-style panic message

func (*Logger) Printf

func (l *Logger) Printf(level Level, prefix, format string, v ...interface{})

func (*Logger) SetAccessLogSample

func (l *Logger) SetAccessLogSample(sample uint64)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

func (*Logger) Warn

func (l *Logger) Warn(prefix, format string, v ...interface{})

Warn logs a printf-style warn message (deprecated, please use Warnf)

func (*Logger) Warnf

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

Warnf logs a printf-style warn message

func (*Logger) Write

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

Jump to

Keyboard shortcuts

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