logger

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MPL-2.0 Imports: 10 Imported by: 3

Documentation

Overview

Package logger allows logging HTTP requests using customized formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(h http.Handler, opts ...Option) http.Handler

Handler does HTTP request logging

Types

type Option

type Option func(*handler)

Option implements http://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html

func AppName

func AppName(name string) Option

AppName allows to set the application name to log.

func Flags

func Flags(flags int) Option

Flags allows to set logging flags using Go's standard log flags.

Example: log.LstdFlags | log.shortfile Keep in mind that log.shortfile and log.Llongfile are expensive flags

func Format

func Format(format string) Option

Format allows to set a custom log format. Although, the timestamp is always logged at the beginning. This handler is a bit opinionated.

Directives:

{remote_user} : Remote user if Basic Auth credentials were sent {remote_ip} : Remote IP address. {latency} : The time taken to serve the request, in microseconds. {latency_human} : The time taken to serve the request, human readable. {id} : The request ID. {host} : The Host header sent to the server {scheme} : The protocol scheme used, either http or https. {method} : The request method. Ex: GET, POST, DELETE, etc. {url} : The URL path requested. {query} : Request's query string {rxbytes} : Bytes received without headers {txbytes} : Bytes sent, excluding HTTP headers. {status} : Status sent to the client {useragent} : User Agent {referer} : The site from where the request came from

func Output

func Output(out io.Writer) Option

Output allows setting an output writer for logging to be written to

Jump to

Keyboard shortcuts

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