Improve logging

- Actually log useful information at their respective log level.
- Add logs in hot-paths to be able to deep-dive and debug specific
requests (see server/handler.go)
- Remove zerologger and instead use custom logger that doesn't log
JSON (directly inspired by https://codeberg.org/Codeberg/moderation/pulls/7).
- Add more information to existing fields(e.g. the host that the user is
visiting, this was noted by @fnetX).
This commit is contained in:
Gusted 2022-07-24 06:22:52 +02:00
parent 00e8a41c89
commit 1e183d7249
No known key found for this signature in database
GPG key ID: FD821B732837125F
13 changed files with 318 additions and 110 deletions

View file

@ -5,12 +5,6 @@ import (
)
var ServeFlags = []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
// TODO: Usage
EnvVars: []string{"DEBUG"},
},
// MainDomainSuffix specifies the main domain (starting with a dot) for which subdomains shall be served as static
// pages, or used for comparison in CNAME lookups. Static pages can be accessed through
// https://{owner}.{MainDomain}[/{repo}], with repo defaulting to "pages".
@ -69,6 +63,24 @@ var ServeFlags = []cli.Flag{
// TODO: desc
EnvVars: []string{"ENABLE_HTTP_SERVER"},
},
&cli.StringSliceFlag{
Name: "log-output",
Value: cli.NewStringSlice("console"),
Usage: "specify where the log will be outputed. Multiple options can be chosen, possible options: console, file",
EnvVars: []string{"LOG_OUTPUT"},
},
&cli.StringFlag{
Name: "log-level",
Value: "warn",
Usage: "specify at which log level should be logged. Possible options: info, warn, error, fatal",
EnvVars: []string{"LOG_LEVEL"},
},
&cli.StringFlag{
Name: "log-file",
Value: "pages-server.log",
Usage: "specify the log file. Only applies when file logging is enabled",
EnvVars: []string{"LOG_FILE"},
},
// ACME
&cli.StringFlag{