Skip to content

Commit 98d862d

Browse files
committed
fix: initialize log level manually from envs
1 parent e6071d7 commit 98d862d

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*
22
!*.go
3-
!go.*
3+
!go.mod
4+
!go.sum
45
!LICENSE
56
!cmd

cmd/cmd.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ func createLogger(cfg *config.Config) *logging.Logger {
3535
return &logger
3636
}
3737

38-
func (a *app) updateLogger() {
39-
a.Logger = createLogger(a.Config)
40-
}
41-
4238
func (a *app) CreateCommand(version, commit, date, builtBy string) *cli.Command {
4339
cli.VersionPrinter = func(c *cli.Command) {
4440
fmt.Printf("Version: %s\n", version)
@@ -123,8 +119,6 @@ func (a *app) rootAction(ctx context.Context, c *cli.Command) error {
123119
return err
124120
}
125121

126-
a.updateLogger()
127-
128122
if c.NArg() == 0 {
129123
var availableCommands []string
130124
for _, subcommand := range c.Commands {

cmd/config/config.go

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

33
import (
44
"fmt"
5+
"os"
56
"strings"
67

78
"github.com/meysam81/x/logging"
@@ -16,8 +17,13 @@ type Config struct {
1617
}
1718

1819
func New() *Config {
20+
logLevel := "info"
21+
if level, ok := os.LookupEnv("LOG_LEVEL"); ok {
22+
logLevel = level
23+
}
24+
1925
return &Config{
20-
LogLevel: "info",
26+
LogLevel: logLevel,
2127
Timeout: 5,
2228
StatusCode: 200,
2329
}

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func main() {
2323
app := cmd.NewApp()
2424
command := app.CreateCommand(version, commit, date, builtBy)
2525

26+
app.Logger.Debug().Msg("Starting the app...")
27+
2628
if err := command.Run(ctx, os.Args); err != nil {
2729
app.Logger.Fatal().Err(err).Msg("good bye till next time.")
2830
}

0 commit comments

Comments
 (0)