Skip to content

Commit a29e8b1

Browse files
fix: load log config from env and remove it from Dockerfile args (#142)
* fix: don't specify the log level as a cmd line parameter * chore: load the log level and output config values from env vars
1 parent c5893ea commit a29e8b1

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

builds/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Builder image
2-
FROM quay.io/centos/centos:stream8 as builder
2+
FROM quay.io/centos/centos:stream8 AS builder
33

44
USER root
55

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

2828
ENTRYPOINT ["./timelock-worker"]
29-
CMD ["start", "--log-level", "${LOGLEVEL:-info}"]
29+
CMD ["start"]

cmd/root.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"log"
45
"os"
56

67
"github.com/spf13/cobra"
@@ -43,11 +44,17 @@ func configureRootCmd() error {
4344
if err := viper.BindPFlag("log-level", rootCmd.PersistentFlags().Lookup("log-level")); err != nil {
4445
return err
4546
}
47+
if err := viper.BindEnv("log-level", "LOGLEVEL"); err != nil {
48+
return err
49+
}
4650

4751
rootCmd.PersistentFlags().StringVarP(&output, "output", "o", "human", "set logging output (human, json)")
4852
if err := viper.BindPFlag("output", rootCmd.PersistentFlags().Lookup("output")); err != nil {
4953
return err
5054
}
55+
if err := viper.BindEnv("output", "OUTPUT"); err != nil {
56+
return err
57+
}
5158

5259
return nil
5360
}
@@ -56,7 +63,7 @@ func initConfig() {
5663
var err error
5764
logs, err = logger.NewLogger(viper.GetString("log-level"), viper.GetString("output"))
5865
if err != nil {
59-
panic("unable to create logger")
66+
log.Fatalf("unable to create logger: %s", err)
6067
}
6168

6269
logs.Debug("initialized Logger")

0 commit comments

Comments
 (0)