logx

package
v0.0.0-...-11273d6 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: MIT Imports: 9 Imported by: 10

Documentation

Index

Constants

View Source
const ErrorKey = "error"

Variables

This section is empty.

Functions

func AddHook

func AddHook(hook logrus.Hook)

export AddHook adds a hook to the standard logger hooks.

func CaptureError

func CaptureError(args ...interface{})

export

func CaptureErrorWith

func CaptureErrorWith(logger StdLog, args ...interface{})

export

func Debug

func Debug(args ...interface{})

export

func Debugf

func Debugf(format string, args ...interface{})

export

func Error

func Error(args ...interface{})

export

func Errorf

func Errorf(format string, args ...interface{})

export

func Info

func Info(args ...interface{})

export

func Infof

func Infof(format string, args ...interface{})

export

func Panic

func Panic(args ...interface{})

export

func Panicf

func Panicf(format string, args ...interface{})

export

func RotateLog

func RotateLog(filename string, maxSize int, maxBackup, maxAge int, compress bool) io.Writer

func SetFormatter

func SetFormatter(formatter Formatter)

SetFormatter sets the standard logger Formatter.

func SetLevel

func SetLevel(level Level)

export SetLevel sets the standard logger level.

func SetLogrusFormatter

func SetLogrusFormatter(formatter logrus.Formatter)

export

func SetOutput

func SetOutput(out io.Writer)

SetOutput sets the standard logger output.

func SetStandard

func SetStandard(logger *Logger)

func Warn

func Warn(args ...interface{})

export

func Warnf

func Warnf(format string, args ...interface{})

export

Types

type Entry

type Entry struct {
	*logrus.Entry
}

func NewEntry

func NewEntry(logger *Logger) *Entry

func WithError

func WithError(err error) *Entry

export WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.

func WithField

func WithField(key string, value interface{}) *Entry

export WithField creates an entry from the standard logger and adds a field to it. If you want multiple fields, use `WithFields`.

Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal or Panic on the Entry it returns.

func WithFields

func WithFields(fields Fields) *Entry

export WithFields creates an entry from the standard logger and adds multiple fields to it. This is simply a helper for `WithField`, invoking it once for each field.

Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal or Panic on the Entry it returns.

func (*Entry) Log

func (entry *Entry) Log(v ...interface{})

func (*Entry) Logf

func (entry *Entry) Logf(format string, v ...interface{})

func (*Entry) WithError

func (entry *Entry) WithError(err error) *Entry

func (*Entry) WithField

func (entry *Entry) WithField(key string, value interface{}) *Entry

func (*Entry) WithFields

func (entry *Entry) WithFields(fields Fields) *Entry

Add a map of fields to the Entry.

type Fields

type Fields logrus.Fields

type Formatter

type Formatter interface {
	Format(*Entry) ([]byte, error)
}

func ColorFormatter

func ColorFormatter(timeFormat string) Formatter

export

func JSONFormatter

func JSONFormatter(timeFormat string) Formatter

func PlainFormatter

func PlainFormatter(timeFormat string) Formatter

type Level

type Level logrus.Level
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 httprxr.
	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
)

func GetLevel

func GetLevel() Level

export GetLevel returns the standard logger level.

func ParseLevel

func ParseLevel(lvl string) (Level, error)

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

func (Level) String

func (level Level) String() string

type Logger

type Logger struct {
	*logrus.Logger
}

func New

func New() *Logger

func StandardLogger

func StandardLogger() *Logger

func (*Logger) Log

func (logger *Logger) Log(v ...interface{})

func (*Logger) Logf

func (logger *Logger) Logf(format string, v ...interface{})

func (*Logger) SetLevel

func (logger *Logger) SetLevel(level Level)

func (*Logger) WithField

func (logger *Logger) WithField(key string, value interface{}) *Entry

func (*Logger) WithFields

func (logger *Logger) WithFields(fields Fields) *Entry

Adds a struct of fields to the log entry. All it does is call `WithField` for each `Field`.

type PlainTextFormatter

type PlainTextFormatter struct {
	TimestampFormat string

	// The fields are sorted by default for a consistent output. For applications
	// that log extremely frequently and don't use the JSON Formatter this may not
	// be desired.
	DisableSorting bool

	// QuoteEmptyFields will wrap empty fields in quotes if true
	QuoteEmptyFields bool

	sync.Once
}

PlainTextFormatter formats logs into text

func (*PlainTextFormatter) Format

func (f *PlainTextFormatter) Format(entry *Entry) ([]byte, error)

Format renders a single log entry

type StdLog

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

Jump to

Keyboard shortcuts

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