simplifies calls to log functions.
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
l "log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
l "example.com/golang-base/internal/log"
|
||||
"example.com/golang-base/internal/log"
|
||||
)
|
||||
|
||||
func Init() Config {
|
||||
@ -14,22 +14,22 @@ func Init() Config {
|
||||
// parse config structure
|
||||
cfgInfo, err := getStructInfo(&cfg)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to initialize program: %v", err)
|
||||
l.Fatalf("Unable to initialize program: %v", err)
|
||||
}
|
||||
|
||||
// get command line flags
|
||||
if err := cfg.parseFlags(cfgInfo); err != nil {
|
||||
log.Fatalf("Unable to initialize program: %v", err)
|
||||
l.Fatalf("Unable to initialize program: %v", err)
|
||||
}
|
||||
|
||||
// set logging Level
|
||||
l.SetNumericLevel(cfg.LogLevel)
|
||||
log.SetNumericLevel(cfg.LogLevel)
|
||||
|
||||
// set timezone & time format
|
||||
cfg.TZUTC, _ = time.LoadLocation("UTC")
|
||||
cfg.TZLocal, err = time.LoadLocation(cfg.TimeZoneLocal)
|
||||
if err != nil {
|
||||
l.L.Error("Unable to parse timezone string", "error", err)
|
||||
log.Error("Unable to parse timezone string", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -36,18 +36,18 @@ func printRunningConfig(cfg *Config, cfgInfo []structInfo) {
|
||||
|
||||
for _, info := range cfgInfo {
|
||||
if info.Secret {
|
||||
log.L.Debug(logRunningConfiguration, info.Name, "REDACTED")
|
||||
log.Debug(logRunningConfiguration, info.Name, "REDACTED")
|
||||
} else {
|
||||
switch info.Type.String() {
|
||||
case "string":
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*string)
|
||||
log.L.Debug(logRunningConfiguration, info.Alt, *p)
|
||||
log.Debug(logRunningConfiguration, info.Alt, *p)
|
||||
case "bool":
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*bool)
|
||||
log.L.Log.Debug(logRunningConfiguration, info.Alt, strconv.FormatBool(*p))
|
||||
log.Debug(logRunningConfiguration, info.Alt, strconv.FormatBool(*p))
|
||||
case "int":
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*int)
|
||||
log.L.Log.Debug(logRunningConfiguration, info.Alt, strconv.FormatInt(int64(*p), 10))
|
||||
log.Debug(logRunningConfiguration, info.Alt, strconv.FormatInt(int64(*p), 10))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user