log

package
v0.0.0-...-d078b10 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 10 Imported by: 114

Documentation

Index

Constants

View Source
const (
	LevelPanic = Level(logrus.PanicLevel)
	LevelFatal = Level(logrus.FatalLevel)
	LevelError = Level(logrus.ErrorLevel)
	LevelWarn  = Level(logrus.WarnLevel)
	LevelInfo  = Level(logrus.InfoLevel)
	LevelDebug = Level(logrus.DebugLevel)
	LevelTrace = Level(logrus.TraceLevel)
)

Variables

View Source
var (
	// log is a global logger instance
	Log = logrus.New()
)

Functions

func Configure

func Configure(opts Options)

func FmtCaller

func FmtCaller(caller runtime.Frame) string

func Setup

func Setup(debug bool)

Setup allows to override the global logger setup.

func WithContext

func WithContext(ctx context.Context, log *Logger) context.Context

WithContext adds logger to context `ctx` and returns the resulting context.

Types

type ContextHook

type ContextHook struct {
}

func (ContextHook) Fire

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

func (ContextHook) Levels

func (hook ContextHook) Levels() []logrus.Level

type ContextLogger

type ContextLogger interface {
	UseLog(l *Logger)
}

ContextLogger interface for components which support logging with context, via setting a logger to an exisiting one, thereby inheriting its context.

type Ctx

type Ctx map[string]interface{}

Ctx short for log context, alias for the more verbose logrus.Fields.

type Format

type Format int
const (
	FormatConsole Format = iota
	FormatJSON
)

type Level

type Level logrus.Level

type Logger

type Logger struct {
	*logrus.Entry
}

Logger is a wrapper for logrus.Entry.

func FromContext

func FromContext(ctx context.Context) *Logger

Grab an instance of Logger that may have been passed in context.Context. Returns the logger or creates a new instance if none was found in ctx. Since Logger is based on logrus.Entry, if logger instance from context is any of logrus.Logger, logrus.Entry, necessary adaption will be applied.

func New

func New(ctx Ctx) *Logger

New returns a new Logger with a given context, derived from the global Log.

func NewEmpty

func NewEmpty() *Logger

NewEmpty returns a new logger with empty context

func NewFromEntry

func NewFromEntry(log *logrus.Entry, ctx Ctx) *Logger

NewFromLogger returns a new Logger derived from a given logrus.Logger, instead of the global one.

func NewFromLogger

func NewFromLogger(log *logrus.Logger, ctx Ctx) *Logger

NewFromLogger returns a new Logger derived from a given logrus.Logger, instead of the global one.

func (*Logger) F

func (l *Logger) F(ctx Ctx) *Logger

F returns a new Logger enriched with new context fields. It's a less verbose wrapper over logrus.WithFields.

func (*Logger) Level

func (l *Logger) Level() logrus.Level

func (*Logger) WithCallerContext

func (l *Logger) WithCallerContext(skipParents int) *Logger

WithCallerContext returns a new logger with caller set to the parent caller context. The skipParents select how many caller contexts to skip, a value of 0 sets the context to the caller of this function.

type Options

type Options struct {
	TimestampFormat string

	Level Level

	DisableCaller bool

	Format Format

	Output io.Writer
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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