devforth / spa-to-http

Lightweight zero-configuration SPA HTTP server. Serves SPA bundle on HTTP port so it plays well with Traefik out of the box. Compatible with Vue.js, React and Angular
MIT License
110 stars 8 forks source link

add Requests logger #9

Closed panz3r closed 1 year ago

panz3r commented 1 year ago

This PR adds a Requests logger handler to the main http.Handler that can be enabled using a new logger option.

The logger handler implementation is based upon rs/zerolog logging library and supports printing log events as either JSON or pretty text (enabled via another option: log-pretty).

Example JSON log output

{
  "level": "info",
  "method": "GET",
  "path": "/",
  "code": 200,
  "size": 449,
  "duration": 4.654542,
  "ipAddress": "127.0.0.1",
  "userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0",
  "referer": "",
  "time": "2023-07-06T12:34:56+00:00"
}
ivictbor commented 1 year ago

@panz3r looks awesome! @MultiFox200 @LbP22 could you please someone take a look and merge once you have a time?

LbP22 commented 1 year ago

Thanks for your work! Your changes released as version 1.0.5!