File: logging.go

package info (click to toggle)
golang-github-alexliesenfeld-health 0.0~git20220920.973f6339-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 228 kB
  • sloc: makefile: 3
file content (21 lines) | stat: -rw-r--r-- 525 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package middleware

import (
	"github.com/alexliesenfeld/health"
	"log"
	"net/http"
	"time"
)

// BasicLogger is a basic logger that is mostly used to showcase this library.
func BasicLogger() health.Middleware {
	return func(next health.MiddlewareFunc) health.MiddlewareFunc {
		return func(r *http.Request) health.CheckerResult {
			now := time.Now()
			result := next(r)
			log.Printf("processed health check request in %f seconds (result: %s)",
				time.Now().Sub(now).Seconds(), result.Status)
			return result
		}
	}
}