@@ -56,11 +56,6 @@ type Config struct {
5656func (c * Config ) GetConfigFolder (xdgPath string ) string {
5757 configPath := xdgPath
5858
59- log .WithFields (log.Fields {
60- "prefix" : "config.Config.GetProfilesFolder" ,
61- "path" : configPath ,
62- }).Debug ("Using profiles file" )
63-
6459 if configPath == "" {
6560 home , err := homedir .Dir ()
6661 if err != nil {
@@ -71,13 +66,32 @@ func (c *Config) GetConfigFolder(xdgPath string) string {
7166 configPath = filepath .Join (home , ".config" )
7267 }
7368
69+ log .WithFields (log.Fields {
70+ "prefix" : "config.Config.GetProfilesFolder" ,
71+ "path" : configPath ,
72+ }).Debug ("Using profiles folder" )
73+
7474 return filepath .Join (configPath , "hookdeck" )
7575}
7676
7777// InitConfig reads in profiles file and ENV variables if set.
7878func (c * Config ) InitConfig () {
7979 c .Profile .Config = c
8080
81+ // Set log level
82+ switch c .LogLevel {
83+ case "debug" :
84+ log .SetLevel (log .DebugLevel )
85+ case "info" :
86+ log .SetLevel (log .InfoLevel )
87+ case "warn" :
88+ log .SetLevel (log .WarnLevel )
89+ case "error" :
90+ log .SetLevel (log .ErrorLevel )
91+ default :
92+ log .Fatalf ("Unrecognized log level value: %s. Expected one of debug, info, warn, error." , c .LogLevel )
93+ }
94+
8195 logFormatter := & prefixed.TextFormatter {
8296 FullTimestamp : true ,
8397 TimestampFormat : time .RFC1123 ,
@@ -102,7 +116,7 @@ func (c *Config) InitConfig() {
102116 log .WithFields (log.Fields {
103117 "prefix" : "config.Config.InitConfig" ,
104118 "path" : c .GlobalConfig .ConfigFileUsed (),
105- }).Debug ("Using profiles file" )
119+ }).Debug ("Using global profiles file" )
106120 }
107121
108122 // Read local config
@@ -127,7 +141,7 @@ func (c *Config) InitConfig() {
127141 log .WithFields (log.Fields {
128142 "prefix" : "config.Config.InitConfig" ,
129143 "path" : c .LocalConfig .ConfigFileUsed (),
130- }).Debug ("Using profiles file" )
144+ }).Debug ("Using local profiles file" )
131145 }
132146
133147 // Construct the config struct
@@ -155,20 +169,6 @@ func (c *Config) InitConfig() {
155169 }
156170
157171 log .SetFormatter (logFormatter )
158-
159- // Set log level
160- switch c .LogLevel {
161- case "debug" :
162- log .SetLevel (log .DebugLevel )
163- case "info" :
164- log .SetLevel (log .InfoLevel )
165- case "warn" :
166- log .SetLevel (log .WarnLevel )
167- case "error" :
168- log .SetLevel (log .ErrorLevel )
169- default :
170- log .Fatalf ("Unrecognized log level value: %s. Expected one of debug, info, warn, error." , c .LogLevel )
171- }
172172}
173173
174174// EditConfig opens the configuration file in the default editor.
@@ -250,6 +250,12 @@ func (c *Config) WriteGlobalConfig() error {
250250 if err := makePath (c .GlobalConfig .ConfigFileUsed ()); err != nil {
251251 return err
252252 }
253+
254+ log .WithFields (log.Fields {
255+ "prefix" : "config.Config.WriteGlobalConfig" ,
256+ "path" : c .GlobalConfig .ConfigFileUsed (),
257+ }).Debug ("Writing global config" )
258+
253259 return c .GlobalConfig .WriteConfig ()
254260}
255261
0 commit comments