Skip to content

Commit

Permalink
Merge pull request #29 from nmaggioni/nm_logging_level_from_env_var
Browse files Browse the repository at this point in the history
Get logging level from environment
  • Loading branch information
scross01 authored Jun 25, 2024
2 parents 99ee2cc + 86727ee commit 3e9f6a8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ Command line options
`Warning`, `Error`, `Fatal` and `Panic`. Default level is `Info` which will
log anything that is info level or above (warning, error, fatal, panic).

Logging level can also be set using the `LOGGING_LEVEL` environment variable. The
command line option takes precedence over the environment setting.

`-moonraker.apikey <string>`

Set the API Key to authenticate with the Klipper APIs.
Expand Down
1 change: 1 addition & 0 deletions klipper-exporter.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ StartLimitIntervalSec=5
[Service]
User=pi
WorkingDirectory=/home/pi/klipper-exporter
EnvironmentFile=/home/pi/klipper-exporter/prometheus-klipper-exporter.env
ExecStart=/home/pi/klipper-exporter/prometheus-klipper-exporter
Restart=always
RestartSec=1s
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func handler(w http.ResponseWriter, r *http.Request) {
}

func main() {

if loggingLevelEnv, loggingLevelEnvSet := os.LookupEnv("LOGGING_LEVEL"); loggingLevelEnvSet {
*loggingLevel = loggingLevelEnv
}

flag.Parse()

level, err := log.ParseLevel(strings.ToLower(*loggingLevel))
Expand Down

0 comments on commit 3e9f6a8

Please sign in to comment.