logger

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: BSD-3-Clause Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoggerMiddleware = func(next http.Handler) http.Handler {
	c := alice.New(
		hlog.NewHandler(log.Logger),
		hlog.ProtoHandler("proto"),
		hlog.RequestHandler("url"),
		hlog.RemoteAddrHandler("ip"),
		hlog.UserAgentHandler("user_agent"),
		hlog.RequestIDHandler("req_id", "Request-Id"),
		hlog.AccessHandler(func(r *http.Request, status, size int, duration time.Duration) {
			hlog.FromRequest(r).Info().
				Int("status", status).
				Int("size", size).
				Dur("duration", duration).
				Send()
		}),
	)

	return c.Then(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		next.ServeHTTP(w, r)
	}))
}

Functions

func LoggerCtx_WithContex added in v0.4.2

func LoggerCtx_WithContex(ctx context.Context, logger *zerolog.Logger, handler *Handler) context.Context

Types

type CircularQueue added in v0.4.0

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

small and simple implementation of a CircularQueue not thread safe

func (*CircularQueue) InQueue added in v0.4.0

func (q *CircularQueue) InQueue() uint8

func (*CircularQueue) Space added in v0.4.0

func (q *CircularQueue) Space() uint8

func (*CircularQueue) Write added in v0.4.0

func (q *CircularQueue) Write(p []byte) (int, error)

type CtxExpired added in v0.4.0

type CtxExpired string

func (CtxExpired) Error added in v0.4.0

func (CtxExpired) Error() string

type Handler added in v0.4.0

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

func LoggerCtx_FromContext added in v0.4.2

func LoggerCtx_FromContext(ctx context.Context) (*zerolog.Logger, *Handler)

func New

func New(logger zerolog.Logger, r *http.Request, w http.ResponseWriter) (handler *Handler, l *zerolog.Logger, err error)

func NewHandler added in v0.4.0

func NewHandler(w http.ResponseWriter, r *http.Request) *Handler

func (*Handler) End added in v0.4.0

func (h *Handler) End()

func (*Handler) FileName added in v0.4.0

func (h *Handler) FileName() string

func (*Handler) Handle added in v0.4.0

func (h *Handler) Handle()

func (*Handler) SendAll added in v0.4.0

func (h *Handler) SendAll(timeout *time.Timer)

func (*Handler) Write added in v0.4.0

func (h *Handler) Write(p []byte) (int, error)

type LoggerCtx added in v0.4.2

type LoggerCtx func(next http.Handler) http.Handler
var ResponseWithLogger LoggerCtx = func(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		handler, logger, err := New(log.Logger, r, w)
		utils.Assert(err == nil, "could not create logger %s", err)

		r = r.WithContext(LoggerCtx_WithContex(r.Context(), logger, handler))
		next.ServeHTTP(w, r)
	})
}

Jump to

Keyboard shortcuts

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