Skip to content

Commit

Permalink
fix: load log config from env and remove it from Dockerfile args (#142)
Browse files Browse the repository at this point in the history
* fix: don't specify the log level as a cmd line parameter

* chore: load the log level and output config values from env vars
  • Loading branch information
gustavogama-cll authored Feb 18, 2025
1 parent c5893ea commit a29e8b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions builds/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builder image
FROM quay.io/centos/centos:stream8 as builder
FROM quay.io/centos/centos:stream8 AS builder

USER root

Expand All @@ -26,4 +26,4 @@ COPY --from=builder /build/timelock-worker /app/
WORKDIR /app

ENTRYPOINT ["./timelock-worker"]
CMD ["start", "--log-level", "${LOGLEVEL:-info}"]
CMD ["start"]
9 changes: 8 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"log"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -43,11 +44,17 @@ func configureRootCmd() error {
if err := viper.BindPFlag("log-level", rootCmd.PersistentFlags().Lookup("log-level")); err != nil {
return err
}
if err := viper.BindEnv("log-level", "LOGLEVEL"); err != nil {
return err
}

rootCmd.PersistentFlags().StringVarP(&output, "output", "o", "human", "set logging output (human, json)")
if err := viper.BindPFlag("output", rootCmd.PersistentFlags().Lookup("output")); err != nil {
return err
}
if err := viper.BindEnv("output", "OUTPUT"); err != nil {
return err
}

return nil
}
Expand All @@ -56,7 +63,7 @@ func initConfig() {
var err error
logs, err = logger.NewLogger(viper.GetString("log-level"), viper.GetString("output"))
if err != nil {
panic("unable to create logger")
log.Fatalf("unable to create logger: %s", err)
}

logs.Debug("initialized Logger")
Expand Down

0 comments on commit a29e8b1

Please sign in to comment.