log

package
v5.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// Format is the fmt format code for common logs
	Format string = "%s %s %s [%s] \"%s %s %s\" %d %d"

	// TimestampFormat is the time format used in common logs
	TimestampFormat string = "02/Jan/2006:15:04:05 -0700"
)

Variables

This section is empty.

Functions

func CombinedLogFormatter

func CombinedLogFormatter(ctx *Context) (string, []slog.Attr)

CombinedLogFormatter build a log entry using the Combined Log Format.

func CombinedLogMiddleware

func CombinedLogMiddleware() goyave.Middleware

CombinedLogMiddleware captures response data and outputs it to the default logger using the combined log format.

func CommonLogFormatter

func CommonLogFormatter(ctx *Context) (string, []slog.Attr)

CommonLogFormatter build a log entry using the Common Log Format.

func CommonLogMiddleware

func CommonLogMiddleware() goyave.Middleware

CommonLogMiddleware captures response data and outputs it to the default logger using the common log format.

Types

type AccessMiddleware

type AccessMiddleware struct {
	goyave.Component
	Formatter Formatter
}

AccessMiddleware captures response data and outputs it to the logger at the INFO level. The message and attributes logged are defined by the `Formatter`.

func (*AccessMiddleware) Handle

func (m *AccessMiddleware) Handle(next goyave.Handler) goyave.Handler

Handle adds the access logging chained writer to the response.

type Context

type Context struct {
	goyave.Component
	Request *goyave.Request
	Status  int
	Length  int
}

Context contains all information needed for a `Formatter`.

type Formatter

type Formatter func(ctx *Context) (message string, attributes []slog.Attr)

Formatter is a function that builds a log entry. As logs are written at the end of the request's lifecycle, all the data is available to formatters at the time they are called, and all modifications will have no effect.

The first returned value is the message, usually formatted using a standard like Common Log Format or Combined Log Format. The second returned value is a slice of structured logging attributes. These attributes are ignored in dev mode (`app.debug = true`) to avoid clutter.

type Writer

type Writer struct {
	goyave.CommonWriter
	// contains filtered or unexported fields
}

Writer chained writer keeping response body in memory. Used for loggin in common format.

func NewWriter

func NewWriter(server *goyave.Server, response *goyave.Response, request *goyave.Request, formatter Formatter) *Writer

NewWriter create a new log writer. The given Request and Response will be used and passed to the given formatter.

func (*Writer) Close

func (w *Writer) Close() error

Close the writer and its child ResponseWriter, flushing response output to the logs.

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

Write writes the data as a response and keeps its length in memory for later logging.

Jump to

Keyboard shortcuts

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