logging

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Service = dependency.Service{
	Dependencies: fx.Provide(
		NewPrintLogger,
		fx.Annotated{
			Group:  "middleware",
			Target: NewMidlleware,
		},
	),
	ConfigFunc: func(set dependency.FlagSet) {
		set.String("app-name", filepath.Base(os.Args[0]), "The name of the application being configured")
		set.String("app-version", "dev", "The version of the application being configured")
		set.String("environment", "test", "The environment that the application is deployed in")
		set.String("logger", "development", "Whether to log in development mode.")
		set.StringSlice("excluded-headers", []string{"Authorization"}, "Which headers to hide from the request log")
	},
	Constructor: NewLoggerFactory().Logger,
}

Service is the exported variable that can be used by the framework package

Functions

func NewMidlleware

func NewMidlleware(logger *zap.Logger, config dependency.ConfigGetter) mux.MiddlewareFunc

NewMiddleware returns you a new instance of the Logger middleware

Types

type LoggerConstructor

type LoggerConstructor func(options ...zap.Option) (*zap.Logger, error)

LoggerConstructor is a type that can give you an instance of a logger

type LoggerFactory

type LoggerFactory struct {
	LoggerConstructors map[string]LoggerConstructor
}

LoggerFactory is a type that can create instances of loggers

func NewLoggerFactory

func NewLoggerFactory() LoggerFactory

NewLoggerFactory will create a new instance of a logger factory

func (LoggerFactory) Logger

func (f LoggerFactory) Logger(settings dependency.ConfigGetter) (*zap.Logger, error)

Logger creates a new instance of a *zap.Logger

type PrintLogger

type PrintLogger struct {
	Logger *zap.Logger
}

PrintLogger implements a generalised logging interface

func NewPrintLogger

func NewPrintLogger(logger *zap.Logger) PrintLogger

NewPrintLogger creates a new instance of the PrintLogger

func (PrintLogger) Println

func (p PrintLogger) Println(arguments ...interface{})

Println prints the arguments to the zap logger

type ResponseLogger

type ResponseLogger struct {
	http.ResponseWriter
	Status int
}

ResponseLogger is a ResponseWriter that is able to log the status code of the response

func NewResponseLogger

func NewResponseLogger(w http.ResponseWriter) *ResponseLogger

NewResponseLogger returns you an instance of a *ResponseLogger

func (*ResponseLogger) WriteHeader

func (l *ResponseLogger) WriteHeader(statusCode int)

WriteHeader intercepts the call to the base ResponseWriter and logs the status code sent

Jump to

Keyboard shortcuts

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