logutil

package
v0.0.0-...-baf4ea5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package logutil provides logging utilities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetReqID

func GetReqID(ctx context.Context) string

GetReqID piggybacks chi/middleware's GetReqID by obtaining the request ID of the request (if present) and strips away the machine name part of the string.

The Request ID is initially set by the chi middleware.RequestID middleware function, this function merely picks up on it. If middleware.RequestID was not called prior to this, GetReqID will simply return an empty string

Types

type Logger

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

A Logger represents an active logging object that generates lines of output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.

func NewLogger

func NewLogger(w io.Writer) *Logger

NewLogger returns a new Logger.

func (*Logger) Output

func (l *Logger) Output(calldepth int, s string) error

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

Printf is a wrapper around log.Logger.Printf. It will print nothing if the output is set to ioutil.Discard, allowing for levelled logging. https://stackoverflow.com/a/42762815

func (*Logger) Println

func (l *Logger) Println(v ...interface{})

Println is a wrapper around log.Logger.Println. It will print nothing if the output is set to ioutil.Discard, allowing for levelled logging.

func (*Logger) RequestPrintf

func (l *Logger) RequestPrintf(r *http.Request, format string, v ...interface{})

RequestPrintf is like Printf, but it will also print out the request ID of the current request.

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

SetOutput sets the output destination for the logger.

func (*Logger) StartRequest

func (l *Logger) StartRequest(r *http.Request)

StartRequest should be called in the middleware at the very start of the request, so that it cleanly delineates between inidividual requests.

func (*Logger) TraceFunc

func (l *Logger) TraceFunc()

TraceFunc is like TraceRequest, except it is for functions that don't take in a *http.Request. This means it will not print the request ID, only the function, file and line number of where TraceFunc was called.

func (*Logger) TraceRequest

func (l *Logger) TraceRequest(r *http.Request)

TraceRequest should be called at the start of every handler function that accepts a *http.Request. It will print the function, file and line number of where the TraceRequest call was called, allowing the user to trace the chain functions being called in a request.

It will also print out the any request ID found in the request context.

func (*Logger) Writer

func (l *Logger) Writer() io.Writer

Writer returns the output destination of the Logger.

Jump to

Keyboard shortcuts

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