log

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2019 License: MIT Imports: 8 Imported by: 88

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HookedLogger

type HookedLogger struct {

	// satisfy the log.FieldLogger interface
	*log.Logger
	// contains filtered or unexported fields
}

Implements the Logger interface It's a logrus logger wrapper that contains an instance of our LoggerHook

func (*HookedLogger) AddHook

func (l *HookedLogger) AddHook(h log.Hook)

AddHook adds a new logrus hook

func (*HookedLogger) GetLevel

func (l *HookedLogger) GetLevel() string

GetLevel gets the current log level

func (*HookedLogger) GetLogDest

func (l *HookedLogger) GetLogDest() string

GetLogDest Gets the file name

func (*HookedLogger) IsDebug

func (l *HookedLogger) IsDebug() bool

func (*HookedLogger) Reopen

func (l *HookedLogger) Reopen() error

Reopen closes the log file and re-opens it

func (*HookedLogger) SetLevel

func (l *HookedLogger) SetLevel(level string)

SetLevel sets a log level, one of the LogLevels

func (*HookedLogger) WithConn

func (l *HookedLogger) WithConn(conn net.Conn) *log.Entry

WithConn extends logrus to be able to log with a net.Conn

type Level

type Level uint8
const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel Level = iota
	// FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
)

The following are taken from logrus

func (Level) String

func (level Level) String() string

Convert the Level to a string. E.g. PanicLevel becomes "panic".

type Logger

type Logger interface {
	log.FieldLogger
	WithConn(conn net.Conn) *log.Entry
	Reopen() error
	GetLogDest() string
	SetLevel(level string)
	GetLevel() string
	IsDebug() bool
	AddHook(h log.Hook)
}

func GetLogger

func GetLogger(dest string, level string) (Logger, error)

type LoggerHook

type LoggerHook interface {
	log.Hook
	Reopen() error
}

LoggerHook extends the log.Hook interface by adding Reopen() and Rename()

func NewLogrusHook

func NewLogrusHook(dest string) (LoggerHook, error)

newLogrusHook creates a new hook. dest can be a file name or one of the following strings: "stderr" - log to stderr, lines will be written to os.Stdout "stdout" - log to stdout, lines will be written to os.Stdout "off" - no log, lines will be written to ioutil.Discard

type LogrusHook

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

func (*LogrusHook) Fire

func (hook *LogrusHook) Fire(entry *log.Entry) error

Fire implements the logrus Hook interface. It disables color text formatting if writing to a file

func (*LogrusHook) Levels

func (hook *LogrusHook) Levels() []log.Level

Levels implements the logrus Hook interface

func (*LogrusHook) Reopen

func (hook *LogrusHook) Reopen() error

Reopen closes and re-open log file descriptor, which is a special feature of this hook

type OutputOption

type OutputOption int
const (
	OutputStderr OutputOption = 1 + iota
	OutputStdout
	OutputOff
	OutputNull
	OutputFile
)

func (OutputOption) String

func (o OutputOption) String() string

Jump to

Keyboard shortcuts

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