logging

package
v0.28.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorKey = logrus.ErrorKey

ErrorKey defines the key used to log errors.

Functions

func NewLoggerHandler

func NewLoggerHandler(name string, logger *Logger, next http.Handler) http.Handler

NewLoggerHandler returns the given http.Handler with the logger integrated.

Types

type CommonLogFormat

type CommonLogFormat struct{}

CommonLogFormat implements the logrus.Formatter interface it writes logrus entries using a CLF format prepended by the request-id.

func (*CommonLogFormat) Format

func (f *CommonLogFormat) Format(entry *logrus.Entry) ([]byte, error)

Format implements the logrus.Formatter interface. It returns the given logrus entry as a CLF line with the following format:

<request-id> <remote-address> <name> <user-id> <time> <duration> "<method> <path> <protocol>" <status> <size>

If a field is not known, the hyphen symbol (-) will be used.

type Logger

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

Logger is an alias of logrus.Logger.

func New

func New(name string, raw json.RawMessage) (*Logger, error)

New initializes the logger with the given options.

func (*Logger) GetImpl

func (l *Logger) GetImpl() *logrus.Logger

GetImpl returns the real implementation of the logger.

func (*Logger) GetTraceHeader

func (l *Logger) GetTraceHeader() string

GetTraceHeader returns the trace header configured

func (*Logger) Middleware

func (l *Logger) Middleware(next http.Handler) http.Handler

Middleware returns the logger middleware that will trace the request of the given handler.

type LoggerHandler

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

LoggerHandler creates a logger handler

func (*LoggerHandler) ServeHTTP

func (l *LoggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler and call to the handler to log with a custom http.ResponseWriter that records the response code and the number of bytes sent.

type ResponseLogger

type ResponseLogger interface {
	http.ResponseWriter
	Size() int
	StatusCode() int
	Fields() map[string]interface{}
	WithFields(map[string]interface{})
}

ResponseLogger defines an interface that a responseWrite can implement to support the capture of the status code, the number of bytes written and extra log entry fields.

func NewResponseLogger

func NewResponseLogger(w http.ResponseWriter) ResponseLogger

NewResponseLogger wraps the given response writer with methods to capture the status code, the number of bytes written, and methods to add new log entries. It won't wrap the response writer if it's already a ResponseLogger.

Jump to

Keyboard shortcuts

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