Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

main

v4.0.2+incompatible
github.com/drish/chi/_examples/logging

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

11 matches

Top ↑

Custom Structured Logger ======================== This example demonstrates how to use middleware.RequestLogger, middleware.LogFormatter and middleware.LogEntry to build a structured logger using the amazing sirupsen/logrus package as the logging backend.

Also: check out https://github.com/pressly/lg for an improved context logger with support for HTTP request logging, based on the example below.

Functions

GetLogEntry

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

LogEntrySetField

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

LogEntrySetFields

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

NewStructuredLogger

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

Types

StructuredLogger

type StructuredLogger struct {
	Logger *logrus.Logger
}

StructuredLogger.NewLogEntry

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

StructuredLoggerEntry

type StructuredLoggerEntry struct {
	Logger logrus.FieldLogger
}

StructuredLoggerEntry.Panic

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

StructuredLoggerEntry.Write

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

Dependency graph