log

package
v3.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: BSD-2-Clause Imports: 9 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotOpen      = errors.New("Logger is not open")
	ErrInvalidLevel = errors.New("Log level is invalid")
)

Functions

This section is empty.

Types

type Level

type Level int
const (
	OFF      Level = 0
	DEBUG    Level = 1
	INFO     Level = 2
	WARN     Level = 3
	ERROR    Level = 4
	CRITICAL Level = 5
)

func LevelFromString

func LevelFromString(s string) (l Level, err error)

func (Level) String

func (l Level) String() string

func (Level) Valid

func (l Level) Valid() bool

type Logger

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

func New

func New(wtr io.WriteCloser) *Logger

New creates a new logger with the given writer at log level INFO

func NewDiscardLogger

func NewDiscardLogger() *Logger

func NewFile

func NewFile(f string) (*Logger, error)

NewFile creates a new logger with the first writer being a file The file is created if it does not exist, and is opened in append mode it is safe to use NewFile on existing logs

func (*Logger) AddWriter

func (l *Logger) AddWriter(wtr io.WriteCloser) error

Add a new writer which will get all the log lines as they are handled

func (*Logger) Close

func (l *Logger) Close() (err error)

Close closes the logger and all currently associated writers writers that have been deleted are NOT closed

func (*Logger) Critical

func (l *Logger) Critical(f string, args ...interface{}) error

Critical writes a CRITICALinfo level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) Debug

func (l *Logger) Debug(f string, args ...interface{}) error

Debug writes a DEBUG level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) DeleteWriter

func (l *Logger) DeleteWriter(wtr io.Writer) error

DeleteWriter removes a writer from the logger, it will not be closed on logging Close

func (*Logger) Error

func (l *Logger) Error(f string, args ...interface{}) error

Error writes an ERROR level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) Fatal

func (l *Logger) Fatal(f string, args ...interface{})

Fatal writes a log, closes the logger, and issues an os.Exit(-1)

func (*Logger) FatalCode

func (l *Logger) FatalCode(code int, f string, args ...interface{})

FatalCode is identical to a log.Fatal, except it allows for controlling the exit code

func (*Logger) GetLevel

func (l *Logger) GetLevel() Level

GetLevel returns the current logging level

func (*Logger) Info

func (l *Logger) Info(f string, args ...interface{}) error

Info writes an INFO level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) SetLevel

func (l *Logger) SetLevel(lvl Level) error

SetLevel sets the log level, Off disables logging and any logging call that is less than the level current level are not logged

func (*Logger) SetLevelString

func (l *Logger) SetLevelString(s string) error

SetLevelString sets the log level using a string, this is a helper function so that you can just hand the config file value directly in

func (*Logger) Warn

func (l *Logger) Warn(f string, args ...interface{}) error

Warn writes an WARN level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

Jump to

Keyboard shortcuts

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