Documentation ¶
Index ¶
- func Columnize(nowFormatted string, latency time.Duration, status, ip, method, path string, ...) string
- func NewLimiter() func(freedom.Worker)
- func NewRecover() context.Handler
- func NewRequest(cfg ...Config) context.Handler
- func NewRequestLogger(traceIDName string, body bool) func(context.Context)
- func NewTrace(traceIDName string) func(context.Context)
- type Config
- type SkipperFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Columnize ¶ added in v1.1.0
func Columnize(nowFormatted string, latency time.Duration, status, ip, method, path string, message interface{}, headerMessage interface{}) string
Columnize formats the given arguments as columns and returns the formatted output, note that it appends a new line to the end.
func NewRequest ¶ added in v1.1.0
func NewRequestLogger ¶ added in v1.6.9
NewRequestLogger .
Types ¶
type Config ¶ added in v1.1.0
type Config struct { // Status displays status code (bool). // // Defaults to true. Status bool // IP displays request's remote address (bool). // // Defaults to true. IP bool // Method displays the http method (bool). // // Defaults to true. Method bool // Path displays the request path (bool). // // Defaults to true. Path bool // Query will append the URL Query to the Path. // Path should be true too. // // Defaults to false. Query bool // Columns will display the logs as a formatted columns-rows text (bool). // If custom `LogFunc` has been provided then this field is useless and users should // use the `Columinize` function of the logger to get the output result as columns. // // Defaults to false. Columns bool // MessageContextKeys if not empty, // the middleware will try to fetch // the contents with `ctx.Values().Get(MessageContextKey)` // and if available then these contents will be // appended as part of the logs (with `%v`, in order to be able to set a struct too), // if Columns field was set to true then // a new column will be added named 'Message'. // // Defaults to empty. MessageContextKeys []string // MessageHeaderKeys if not empty, // the middleware will try to fetch // the contents with `ctx.Values().Get(MessageHeaderKey)` // and if available then these contents will be // appended as part of the logs (with `%v`, in order to be able to set a struct too), // if Columns field was set to true then // a new column will be added named 'HeaderMessage'. // // Defaults to empty. MessageHeaderKeys []string // LogFunc is the writer which logs are written to, // if missing the logger middleware uses the app.Logger().Infof instead. // Note that message argument can be empty. LogFunc func(endTime time.Time, latency time.Duration, status, ip, method, path string, message interface{}, headerMessage interface{}) // LogFuncCtx can be used instead of `LogFunc` if handlers need to customize the output based on // custom request-time information that the LogFunc isn't aware of. LogFuncCtx func(ctx context.Context, latency time.Duration) // Skippers used to skip the logging i.e by `ctx.Path()` and serve // the next/main handler immediately. Skippers []SkipperFunc TraceName string // contains filtered or unexported fields }
Config contains the options for the logger middleware can be optionally be passed to the `New`.
func DefaultConfig ¶ added in v1.1.0
func DefaultConfig() Config
DefaultConfig returns a default config that have all boolean fields to true except `Columns`, all strings are empty, LogFunc and Skippers to nil as well.
func (*Config) AddSkipper ¶ added in v1.1.0
func (c *Config) AddSkipper(sk SkipperFunc)
AddSkipper adds a skipper to the configuration.
type SkipperFunc ¶ added in v1.1.0
The SkipperFunc signature, used to serve the main request without logs. See `Configuration` too.
Click to show internal directories.
Click to hide internal directories.