log

package module
v0.0.0-...-7da6dd8 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 14 Imported by: 0

README

GO logger

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownLevel unknown log level
	ErrUnknownLevel = errors.New("unknown log level")
)

Functions

This section is empty.

Types

type Fields

type Fields logrus.Fields

Fields own declaration of logrus Fields

type Level

type Level string

Level type

const (
	// LevelDebug usually only enabled when debugging
	LevelDebug Level = "debug"
	// LevelInfo general operational entries about what's going on inside the application
	LevelInfo Level = "info"
	// LevelWarn non-critical entries that deserve eyes
	LevelWarn Level = "warn"
	// LevelError used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	LevelError Level = "error"
	// LevelFatal Logs and then calls `logger.Exit(1)`
	LevelFatal Level = "fatal"
	// LevelPanic logs and then calls panic
	LevelPanic Level = "panic"
)

func ParseLevel

func ParseLevel(level string) (Level, error)

ParseLevel takes a string level and returns the Level constant

func (*Level) String

func (l *Level) String() string

String return string value of a Level constant

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Warn(args ...interface{})
	Warnf(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Panic(args ...interface{})
	Panicf(format string, args ...interface{})

	WithFields(fields map[string]interface{}) Logger
	WithPrefix(prefix string) Logger

	Level() Level
}

Logger implementation is responsible for providing structured and leveled logging functions.

func New

func New(wr io.Writer, level Level, file string) Logger

New returns a logger implemented using the logrus package.

type LogrusFileHook

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

LogrusFileHook hook for logrus to write log to file

func NewLogrusFileHook

func NewLogrusFileHook(file string, flag int, chmod os.FileMode) (*LogrusFileHook, error)

NewLogrusFileHook returns new file hook object for logrus

func (*LogrusFileHook) Fire

func (hook *LogrusFileHook) Fire(entry *logrus.Entry) error

Fire func used by logrus to write the log into a log file

func (*LogrusFileHook) Levels

func (hook *LogrusFileHook) Levels() []logrus.Level

Levels defines in which log levels the file hooks works

Jump to

Keyboard shortcuts

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