lg

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2018 License: BSD-3-Clause Imports: 10 Imported by: 57

README

Lg

The lg ("log") package is a context-based application logger built on the Logrus package (https://github.com/sirupsen/logrus). It also includes a HTTP request logging middleware, lg.RequestLogger.

See the example for a sample program.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LoggerCtxKey   = &contextKey{"Logger"}
	LogEntryCtxKey = &contextKey{"LogEntry"}
)
View Source
var (
	DefaultLogger *logrus.Logger = logrus.New()
	AlertFn       func(level logrus.Level, msg string)
)

Functions

func Alert

func Alert(args ...interface{})

func Alertf

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

func Alertln

func Alertln(args ...interface{})

func Debug

func Debug(args ...interface{})

func Debugf

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

func Debugln

func Debugln(args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

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

func Errorln

func Errorln(args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

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

func Fatalln

func Fatalln(args ...interface{})

func Info

func Info(args ...interface{})

func Infof

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

func Infoln

func Infoln(args ...interface{})

func Log

func Panic

func Panic(args ...interface{})

func Panicf

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

func Panicln

func Panicln(args ...interface{})

func Print

func Print(args ...interface{})

func PrintPanics

func PrintPanics(next http.Handler) http.Handler

PrintPanics is a development middleware that preempts the request logger and prints a panic message and stack trace to stdout.

func Printf

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

func Println

func Println(args ...interface{})

func RedirectStdlogOutput

func RedirectStdlogOutput(logger *logrus.Logger)

func RequestLog

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

func RequestLogger

func RequestLogger(logger *logrus.Logger) func(next http.Handler) http.Handler

RequestLogger is a middleware for the github.com/sirupsen/logrus to log requests. It is equipt to handle recovery in case of panics and record the stack trace with a panic log-level.

func SanitizingRequestLogger added in v1.0.1

func SanitizingRequestLogger(logger *logrus.Logger, rules map[string]string) func(next http.Handler) http.Handler

SanitizingRequestLogger is a middleware for the github.com/sirupsen/logrus to log requests. It is equipt to handle recovery in case of panics and record the stack trace with a panic log-level. It's second parameter is a map[string]string of replacements for parameters to be sanitized before logging Example:

map[string]string{
	"token": "[redacted]",
	"session": "removed-sesion-id",
}

func SetEntryField

func SetEntryField(ctx context.Context, key string, value interface{})

func SetEntryFields

func SetEntryFields(ctx context.Context, fields map[string]interface{})

func SetRequestEntryField

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

func SetRequestEntryFields

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

func Warn

func Warn(args ...interface{})

func Warnf

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

func Warnln

func Warnln(args ...interface{})

func WithError

func WithError(err error) *logrus.Entry

func WithField

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

func WithFields

func WithFields(fields logrus.Fields) *logrus.Entry

func WithLogEntry

func WithLogEntry(parent context.Context, logEntry *HTTPLoggerEntry) context.Context

func WithLoggerContext

func WithLoggerContext(parent context.Context, logger *logrus.Logger) context.Context

Types

type HTTPLogger

type HTTPLogger struct {
	Logger *logrus.Logger
}

func (*HTTPLogger) NewLogEntry

func (l *HTTPLogger) NewLogEntry(r *http.Request) *HTTPLoggerEntry

type HTTPLoggerEntry

type HTTPLoggerEntry struct {
	Logger logrus.FieldLogger // field logger interface, created by RequestLogger
	Level  *logrus.Level      // intended log level to write when request finishes
}

func (*HTTPLoggerEntry) Panic

func (l *HTTPLoggerEntry) Panic(rec interface{}, stack []byte)

func (*HTTPLoggerEntry) Write

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

type SanitizingHTTPLogger added in v1.0.1

type SanitizingHTTPLogger struct {
	Logger *logrus.Logger
	Rules  map[string]string
}

func (*SanitizingHTTPLogger) NewLogEntry added in v1.0.1

func (l *SanitizingHTTPLogger) NewLogEntry(r *http.Request) *HTTPLoggerEntry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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