Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Logger = logrus.New()
Logger is the global Logger instance
var Logger4Gin gin.HandlerFunc
Logger4Gin is a gin middleware for Logger
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 ¶
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 ¶
ZoneLogger creates a new logger entry with field zone=name
Types ¶
type ContextValueFieldHook ¶
ContextValueFieldHook add a FieldKey=ContextValue(ContextKey) field (if exists) to the log entry
func (ContextValueFieldHook) Levels ¶
func (c ContextValueFieldHook) Levels() []logrus.Level
type Level ¶
type Level string
Level is the level of log: LevelDebug, LevelInfo, LevelWarn, LevelError
type LoggerOption ¶
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.