apexlogutils

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: MIT Imports: 5 Imported by: 0

README

apexlogutils

Go packages with utilities around github.com/apex/log.

What does it do?

This code was extracted from multiple production applications for integration with HTTP request logging, DB driver logging with pgx and a custom text log handler that outputs a component field to quickly identify the source of a log message in development.

The HTTP logger is based on https://github.com/apex/httplog but is a more complete http.ResponseWriter wrapper (see https://github.com/gorilla/handlers) and includes an option to not log requests for paths with a given prefix (e.g. health checks). It also uses a log instance from context.Context if set, so it's a nice combination with middleware.RequestID to have a unique id for each request to correlate log messages.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToApexLogLevel

func ToApexLogLevel(v Verbosity) log.Level

ToApexLogLevel gets the Apex log level from Verbosity

Types

type ComponentTextHandler

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

ComponentTextHandler with additional handling of "component" field for identification of sub components

func NewComponentTextHandler

func NewComponentTextHandler(w io.Writer) *ComponentTextHandler

NewComponentTextHandler builds new handler.

func (*ComponentTextHandler) HandleLog

func (h *ComponentTextHandler) HandleLog(e *log.Entry) error

HandleLog implements log.Handler.

type Verbosity

type Verbosity int

Verbosity is a verbosity level that can be mapped to log levels. Higher numbers mean more verbose logging.

const (
	// VerbosityFatal is least verbose
	VerbosityFatal Verbosity = 0
	// VerbosityError only logs errors
	VerbosityError Verbosity = 1
	// VerbosityWarn also logs warnings
	VerbosityWarn Verbosity = 2
	// VerbosityInfo also logs informational messages
	VerbosityInfo Verbosity = 3
	// VerbosityDebug is most verbose
	VerbosityDebug Verbosity = 4
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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