logging

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package logging provides utilities for logging.

Index

Constants

This section is empty.

Variables

View Source
var SharedLogger = createLogger()

SharedLogger is the global scope logger It should not be used directly by other packages (except for testing) which should prefer shorthands functions.

Functions

func Debug

func Debug(args ...interface{})

Debug logs a message at level Debug on the shared logger.

func Debugf

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

Debugf logs a message at level Debug on the shared logger.

func Error

func Error(args ...interface{})

Error logs a message at level Error on the shared logger.

func Errorf

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

Errorf logs a message at level Error on the shared logger.

func Fatal

func Fatal(args ...interface{})

Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.

func Fatalf

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

Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.

func GetLogEntry

func GetLogEntry(r *http.Request) logrus.FieldLogger

GetLogEntry return the request scoped logrus.FieldLogger. noinspection GoUnusedExportedFunction.

func Info

func Info(args ...interface{})

Info logs a message at level Info on the shared logger.

func Infof

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

Infof logs a message at level Info on the shared logger.

func LogEntrySetField

func LogEntrySetField(r *http.Request, key string, value interface{})

LogEntrySetField adds a field to the request scoped logrus.FieldLogger. noinspection GoUnusedExportedFunction.

func LogEntrySetFields

func LogEntrySetFields(r *http.Request, fields map[string]interface{})

LogEntrySetFields adds multiple fields to the request scoped logrus.FieldLogger. noinspection GoUnusedExportedFunction.

func MockSharedLoggerHook

func MockSharedLoggerHook() (hook *test.Hook, restoreFunc func())

MockSharedLoggerHook set a null/mock logger as shared and return the hook and the function restoring the initial logger.

func NewRawDBLogger

func NewRawDBLogger(logger DBLogger, rawLogMode bool) instrumentedsql.Logger

NewRawDBLogger returns a logger for raw database actions using an existing dblogger and rawLogMode setting.

func NewStructuredLogger

func NewStructuredLogger() func(next http.Handler) http.Handler

NewStructuredLogger implements a custom structured logger using the global one.

func Panic

func Panic(args ...interface{})

Panic logs a message at level Panic on the shared logger.

func Panicf

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

Panicf logs a message at level Panic on the shared logger.

func ResetShared

func ResetShared()

ResetShared reset the global logger to its default settings before its configuration.

func Warn

func Warn(args ...interface{})

Warn logs a message at level Warn on the shared logger.

func Warnf

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

Warnf logs a message at level Warn on the shared logger.

func WithField

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

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 map[string]interface{}) *logrus.Entry

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.

Types

type DBLogger

type DBLogger interface {
	Print(v ...interface{})
}

DBLogger is the logger interface for the DB logs.

type Logger

type Logger struct {
	*logrus.Logger
	// contains filtered or unexported fields
}

Logger is wrapper around a logger and keeping the logging config so that it can be reused by other loggers.

func NewMockLogger

func NewMockLogger() (*Logger, *test.Hook)

NewMockLogger creates a null/mock logger and return the logger and the hook.

func (*Logger) Configure

func (l *Logger) Configure(config *viper.Viper)

Configure applies the given logging configuration to the logger (may panic if the configuration is invalid).

func (*Logger) NewDBLogger

func (l *Logger) NewDBLogger() (DBLogger, bool, bool)

NewDBLogger returns a logger for the database and the `logMode` as well as the 'rawLogMode', according to the config.

type StructuredDBLogger

type StructuredDBLogger struct {
	// contains filtered or unexported fields
}

StructuredDBLogger is a database structured logger.

func NewStructuredDBLogger

func NewStructuredDBLogger(logger *logrus.Logger) *StructuredDBLogger

NewStructuredDBLogger created a database structured logger.

func (*StructuredDBLogger) Print

func (l *StructuredDBLogger) Print(values ...interface{})

Print defines how StructuredDBLogger print log entries. values: 0: level, 1: source file, 2: duration in ns, 3: query, 4: slice of parameters, 5: rows affected or returned

type StructuredLogger

type StructuredLogger struct {
	*logrus.Logger
}

StructuredLogger is a structured logrus Logger.

func (*StructuredLogger) NewLogEntry

func (l *StructuredLogger) NewLogEntry(r *http.Request) middleware.LogEntry

NewLogEntry sets default request log fields.

type StructuredLoggerEntry

type StructuredLoggerEntry struct {
	Logger logrus.FieldLogger
}

StructuredLoggerEntry is a logrus.FieldLogger.

func (*StructuredLoggerEntry) Panic

func (l *StructuredLoggerEntry) Panic(v interface{}, stack []byte)

Panic prints stack trace.

func (*StructuredLoggerEntry) Write

func (l *StructuredLoggerEntry) Write(status, bytes int, elapsed time.Duration)

Jump to

Keyboard shortcuts

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