logger

package
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogDebug   = "DEBUG"
	LogInfo    = "INFO"
	LogWarning = "WARNING"
	LogError   = "ERROR"
	LogPanic   = "PANIC"
)

These constants are the string representation of the package logging levels.

Variables

View Source
var ErrNilFile = errors.New("can not use nil file")

ErrNilFile signals that the provided file is nil

Functions

This section is empty.

Types

type LogFileWriter

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

LogFileWriter is a custom io.Writer implementation suited for our application. While a writer is not provided, it will write to standard output and record all entries in a slice. After the writer will be provided, the buffer slice will be set to nil and the provided writer will be called from this point on.

func (*LogFileWriter) SetWriter

func (lfw *LogFileWriter) SetWriter(writer io.Writer)

SetWriter will set the writer

func (*LogFileWriter) Write

func (lfw *LogFileWriter) Write(p []byte) (n int, err error)

Write handles the output of this writer

func (*LogFileWriter) Writer

func (lfw *LogFileWriter) Writer() io.Writer

Writer will return the current writer

type Logger

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

Logger represents the application logger.

func DefaultLogger

func DefaultLogger() *Logger

DefaultLogger is a shorthand for instantiating a new logger with default settings. If it fails to open the default log file it will return a logger with os.Stdout output.

func NewElrondLogger

func NewElrondLogger(opts ...Option) *Logger

NewElrondLogger will setup the defaults of the application logger. If the requested log file is writable it will setup a MultiWriter on both the file

and the standard output. Also sets up the level and the format for the logger.

func (*Logger) ApplyOptions

func (el *Logger) ApplyOptions(opts ...Option) error

ApplyOptions can set up different configurable options of a Logger instance

func (*Logger) ChangePrinterHookWriter added in v1.0.12

func (el *Logger) ChangePrinterHookWriter(wr io.Writer) error

ChangePrinterHookWriter will change io writer of the hook

func (*Logger) Debug

func (el *Logger) Debug(message string, extra ...interface{})

Debug is an alias for Logrus.Debug, adding some default useful fields.

func (*Logger) Error

func (el *Logger) Error(message string, extra ...interface{})

Error is an alias for Logrus.Error, adding some default useful fields.

func (*Logger) File

func (el *Logger) File() io.Writer

File returns the current Logger file

func (*Logger) Headline

func (el *Logger) Headline(message string, timestamp string, delimiter string) string

Headline will build a headline message given a delimiter string

timestamp parameter will be printed before the repeating delimiter

func (*Logger) Info

func (el *Logger) Info(message string, extra ...interface{})

Info is an alias for Logrus.Info, adding some default useful fields.

func (*Logger) LogIfError

func (el *Logger) LogIfError(err error)

LogIfError will log if the provided error different than nil

func (*Logger) Panic

func (el *Logger) Panic(message string, extra ...interface{})

Panic is an alias for Logrus.Panic, adding some default useful fields.

func (*Logger) SetLevel

func (el *Logger) SetLevel(level string)

SetLevel sets the log level according to this package's defined levels.

func (*Logger) SetOutput

func (el *Logger) SetOutput(out io.Writer)

SetOutput enables the possibility to change the output of the logger on demand.

func (*Logger) StackTraceDepth

func (el *Logger) StackTraceDepth() int

StackTraceDepth returns the current Logger stackTraceDepth

func (*Logger) Warn

func (el *Logger) Warn(message string, extra ...interface{})

Warn is an alias for Logrus.Warn, adding some default useful fields.

type Option

type Option func(*Logger) error

Option represents a functional configuration parameter that can operate

over the Logger struct

func WithFile

func WithFile(file io.Writer) Option

WithFile sets up the file option for the Logger

func WithFileRotation added in v1.0.11

func WithFileRotation(prefix string, subfolder string, fileExtension string) Option

WithFileRotation sets up the option to roll log files

func WithStackTraceDepth

func WithStackTraceDepth(depth int) Option

WithStackTraceDepth sets up the stackTraceDepth option for the Logger

func WithStderrRedirect added in v1.0.11

func WithStderrRedirect() Option

WithStderrRedirect sets up the option to redirect stderr to file

Jump to

Keyboard shortcuts

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