log

package module
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: MIT Imports: 3 Imported by: 32

README

log

Go GitHub tag (latest SemVer) Sourcegraph GoDoc go.dev Go Report Card

LICENSE

MIT

Documentation

Overview

Package log provide the standard interface of logging for what any go libraries want strip off the direct dependency from a known logging library.

Index

Constants

This section is empty.

Variables

AllLevels is a constant exposing all logging levels

Functions

This section is empty.

Types

type Level

type Level uint32

Level type

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 `logger.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
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
	// OffLevel level. The logger will be shutdown.
	OffLevel
)

These are the different logging levels. You can set the logging level to log on your instance of logger, obtained with `logrus.New()`.

func ParseLevel

func ParseLevel(lvl string) (Level, error)

ParseLevel takes a string level and returns the Logrus log level constant.

func (Level) MarshalText

func (level Level) MarshalText() ([]byte, error)

MarshalText convert Level to string and []byte

func (Level) String

func (level Level) String() string

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

func (*Level) UnmarshalText

func (level *Level) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Logger

type Logger interface {
	Tracef(msg string, args ...interface{})
	Debugf(msg string, args ...interface{})
	Infof(msg string, args ...interface{})
	Warnf(msg string, args ...interface{})
	Errorf(msg string, args ...interface{})
	Fatalf(msg string, args ...interface{})
	Printf(msg string, args ...interface{})

	SetLevel(lvl Level)
	GetLevel() Level

	// Setup will be invoked once an instance created
	Setup()
}

Logger is a minimal logger with no more dependencies

func NewDummyLogger added in v0.1.5

func NewDummyLogger() Logger

NewDummyLogger return a dummy logger

func NewStdLogger added in v0.1.7

func NewStdLogger() Logger

NewStdLogger return a stdlib `log` logger

type LoggerConfig

type LoggerConfig struct {
	Enabled   bool
	Backend   string // zap, sugar, logrus
	Level     string
	Format    string // text, json, ...
	Target    string // console, file, console+file
	Directory string
	DebugMode bool `json:"-" yaml:"-"`
	TraceMode bool `json:"-" yaml:"-"`

	// MaxSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 100 megabytes.
	MaxSize int `json:"maxsize" yaml:"maxsize"`

	// MaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename.  Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is not to remove old log files
	// based on age.
	MaxAge int `json:"maxage" yaml:"maxage"`

	// MaxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int `json:"maxbackups" yaml:"maxbackups"`

	// LocalTime determines if the time used for formatting the timestamps in
	// backup files is the computer's local time.  The default is to use UTC
	// time.
	LocalTime bool `json:"localtime" yaml:"localtime"`

	// Compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool `json:"compress" yaml:"compress"`
}

LoggerConfig is used for creating a minimal logger with no more dependencies

func NewLoggerConfig

func NewLoggerConfig() *LoggerConfig

NewLoggerConfig returns a default LoggerConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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