log

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: MIT Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = logrus.New()

Logger is the global Logger instance

View Source
var Logger4Gin gin.HandlerFunc

Logger4Gin is a gin middleware for Logger

View Source
var Logger4Gorm *gormlogrus.Logger

Logger4Gorm is the wrapped Logger instance for Gorm

Functions

func NewLogger

func NewLogger(options ...LoggerOption) *logrus.Logger

NewLogger creates and use a new logrus.Logger instance

func RequestIDHook

func RequestIDHook() logrus.Hook

RequestIDHook add a context="request_id" field to the log entry

func UseLogger

func UseLogger(logger *logrus.Logger, options ...LoggerOption)

UseLogger use given logger instance to initializes global Logger. The Logger instance will be shared by the whole crud package (and the underlying GORM, Gin included)

func ZoneLogger

func ZoneLogger(name string) *logrus.Entry

ZoneLogger creates a new logger entry with field zone=name

Types

type ContextValueFieldHook

type ContextValueFieldHook struct {
	FieldKey   string // default: "context"
	ContextKey string
}

ContextValueFieldHook add a FieldKey=ContextValue(ContextKey) field (if exists) to the log entry

func (ContextValueFieldHook) Fire

func (c ContextValueFieldHook) Fire(entry *logrus.Entry) error

func (ContextValueFieldHook) Levels

func (c ContextValueFieldHook) Levels() []logrus.Level

type Level

type Level string

Level is the level of log: LevelDebug, LevelInfo, LevelWarn, LevelError

const (
	LevelTrace Level = "trace"
	LevelDebug Level = "debug"
	LevelInfo  Level = "info"
	LevelWarn  Level = "warn"
	LevelError Level = "error"
)

Log levels.

type LoggerOption

type LoggerOption func(logger *logrus.Logger)

LoggerOption is a function that can be used to configure the global Logger

func DefaultLoggerOptions

func DefaultLoggerOptions() []LoggerOption

DefaultLoggerOptions = WithLevel(LevelDebug) + WithReportCaller(false)

  • WithHook(RequestIDHook())

func WithHook

func WithHook(hook logrus.Hook) LoggerOption

func WithLevel

func WithLevel(level Level) LoggerOption

WithLevel sets the Logger level.

The level can be one of the following: LevelDebug, LevelInfo, LevelWarn, LevelError. If the level is not valid, it will use Debug by default.

Note: this option will affect the log level of given logger instance when it is used by UseLogger(logger, WithLevel(...)).

func WithReportCaller

func WithReportCaller(reportCaller bool) LoggerOption

WithReportCaller sets the Logger to report the calling function.

Jump to

Keyboard shortcuts

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