slog_helpers

package
v0.0.0-...-b3a3e34 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package slog_helpers provides functionality to transform some golang types into a loggable by the package log/slog. As all this module oriented to improve error handling, I think it's right place for this package. Also, those helpers are used inside the project in domain_errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HttpReqToSlog

func HttpReqToSlog(r *http.Request, cfg RequestToSlogCfg) ([]any, error)

HttpReqToSlog converts an HTTP request (URL, Headers, Body) to the loggable by slog format TODO: Add IP logging

func MapToSlog

func MapToSlog[T any](in map[string]T) []any

MapToSlog converts map of anything with string key to a loggable by log/slog slice

Usage:

log := MapToSlog(map)
log = append(log, slog.Group("Map2", MapToSlog(map2)...))
slog.Info("Some information", log...)

Types

type RequestToSlogCfg

type RequestToSlogCfg struct {
	LogURL     bool
	LogHeaders bool
	LogBody    bool
}

Jump to

Keyboard shortcuts

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