update loglevel to str env var

This commit is contained in:
onyx-and-iris 2025-04-06 00:01:36 +01:00
parent 16e5e9c010
commit fd51761ab5
2 changed files with 20 additions and 8 deletions

View File

@ -22,9 +22,19 @@ Then just run the binary which you can compile yourself, download from `Releases
### Logging
Set the log level with environment variable `Q3RCON_LOGLEVEL`:
Set the log level with environment variable `Q3RCON_LOGLEVEL`.
`0 = Panic, 1 = Fatal, 2 = Error, 3 = Warning, 4 = Info, 5 = Debug, 6 = Trace`
Acceptable values are:
- `trace`
- `debug`
- `info`
- `warn`
- `error`
- `fatal`
- `panic`
If not set it will default to `info`.
### Special Thanks

View File

@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"slices"
"strings"
"time"
@ -13,13 +12,16 @@ import (
)
func main() {
logLevel, err := getEnvInt("Q3RCON_LOGLEVEL")
loglevel := os.Getenv("Q3RCON_LOGLEVEL")
if loglevel == "" {
loglevel = "info"
}
level, err := log.ParseLevel(loglevel)
if err != nil {
log.Fatalf("unable to parse Q3RCON_LEVEL: %s", err.Error())
}
if slices.Contains(log.AllLevels, log.Level(logLevel)) {
log.SetLevel(log.Level(logLevel))
fmt.Fprintf(os.Stderr, "Invalid log level: %s\n", loglevel)
os.Exit(1)
}
log.SetLevel(level)
proxyHost := os.Getenv("Q3RCON_PROXY_HOST")
if proxyHost == "" {