Skip to content

Commit

Permalink
handle update in run
Browse files Browse the repository at this point in the history
  • Loading branch information
veceraj committed Dec 12, 2024
1 parent d3388cb commit 71584c6
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions cmd/pbm-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (

const mongoConnFlag = "mongodb-uri"

var logOpts *log.Opts

func main() {
rootCmd := rootCommand()
rootCmd.AddCommand(versionCommand())
Expand All @@ -35,12 +33,6 @@ func main() {
viper.AddConfigPath(".")
viper.WatchConfig()

viper.OnConfigChange(func(e fsnotify.Event) {
fmt.Printf("Config file changed: %s\n", e.Name)
*logOpts = *buildLogOpts()
fmt.Printf("Updated log options: %+v\n", logOpts)
})

if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
Expand Down Expand Up @@ -83,7 +75,7 @@ func rootCommand() *cobra.Command {

hidecreds()

logOpts = buildLogOpts()
logOpts := buildLogOpts()

l := log.NewWithOpts(nil, "", "", logOpts).NewDefaultEvent()

Expand Down Expand Up @@ -196,6 +188,11 @@ func runAgent(
logOpts)
defer logger.Close()

viper.OnConfigChange(func(e fsnotify.Event) {
fmt.Printf("Config file changed: %s\n", e.Name)
logger.SetOpts(buildLogOpts())
})

ctx = log.SetLoggerToContext(ctx, logger)

mtLog.SetDateFormat(log.LogTimeFormat)
Expand Down

0 comments on commit 71584c6

Please sign in to comment.