Skip to content

Commit 2344946

Browse files
author
Jenny
committed
Additional logging
1 parent b3a3f3a commit 2344946

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

config/config.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package config
22

33
import (
44
"errors"
5-
"log"
65
"os"
76
"regexp"
87
"strings"
98

109
enc "github.com/scrambledeggs/booky-go-common/encryption"
10+
log "github.com/sirupsen/logrus"
1111
"github.com/spf13/viper"
1212
)
1313

@@ -17,6 +17,8 @@ const (
1717
ENV_STAGING string = "staging"
1818
ENV_TEST string = "test"
1919
ENV_PROD string = "production"
20+
21+
LOG_SECTION string = "COMMON/CONFIG"
2022
)
2123

2224
type Config interface {
@@ -80,6 +82,7 @@ func (c *config) ApplyEnvConfig() error {
8082
for k, v := range *c.configMap {
8183
err := c.setKeyVarEnv(k, viper.GetString(prefix+v))
8284
if err != nil {
85+
log.WithFields(log.Fields{"-section": LOG_SECTION, "field": k}).Warn("Issue encountered while trying to set env variable.")
8386
return err
8487
}
8588
}
@@ -100,6 +103,10 @@ func (c *config) setKeyVarEnv(key string, val string) error {
100103
trimmed := strings.TrimSuffix(strings.TrimPrefix(val, "ENC("), ")")
101104
temp, err := enc.DecryptB64(trimmed, *c.cipherpass)
102105
if err != nil {
106+
log.WithFields(log.Fields{
107+
"-section": LOG_SECTION,
108+
"value": trimmed,
109+
}).Info("Issue encountered while trying to decrypt a value.")
103110
return err
104111
}
105112

@@ -125,7 +132,7 @@ func (c *config) checkEnvValidity() bool {
125132
}
126133
}
127134

128-
log.Print("Could not detect valid environment. Setting Config ENVIRONMENT to 'development'.")
135+
log.WithFields(log.Fields{"-section": LOG_SECTION}).Info("Could not detect valid environment. Setting Config ENVIRONMENT to 'development'.")
129136
defaultEnv := ENV_DEV
130137
c.environment = &defaultEnv
131138
return false
@@ -140,6 +147,11 @@ func setViperConfig(configFile string, configPath string, configType string) err
140147

141148
err := viper.ReadInConfig()
142149
if err != nil {
150+
log.WithFields(log.Fields{"-section": LOG_SECTION,
151+
"config_file": configFile,
152+
"config_path": configPath,
153+
"config_type": configType,
154+
}).Warn("Unable to read config file properly.")
143155
return err
144156
}
145157

config/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.12
44

55
require (
66
github.com/scrambledeggs/booky-go-common/encryption v0.0.0-20190913074022-cfd0ef746a40
7+
github.com/sirupsen/logrus v1.2.0
78
github.com/spf13/viper v1.4.0
89
github.com/stretchr/testify v1.4.0
910
)

config/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22
4444
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
4545
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
4646
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
47+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
4748
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
4849
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
4950
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -73,6 +74,7 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
7374
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
7475
github.com/scrambledeggs/booky-go-common/encryption v0.0.0-20190913074022-cfd0ef746a40 h1:/QHqHjI/AtdVvZ1/yFgRbRxeCvzoImQIPvnU/XJVOoQ=
7576
github.com/scrambledeggs/booky-go-common/encryption v0.0.0-20190913074022-cfd0ef746a40/go.mod h1:5hz/zbUnPOoXJyvxiZh6L3MdI1817XAfVTYp8zYj6Mk=
77+
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
7678
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
7779
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
7880
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22
4545
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
4646
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
4747
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
48+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
4849
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
4950
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
5051
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -74,6 +75,7 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
7475
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
7576
github.com/scrambledeggs/booky-go-common/encryption v0.0.0-20190913074022-cfd0ef746a40 h1:/QHqHjI/AtdVvZ1/yFgRbRxeCvzoImQIPvnU/XJVOoQ=
7677
github.com/scrambledeggs/booky-go-common/encryption v0.0.0-20190913074022-cfd0ef746a40/go.mod h1:5hz/zbUnPOoXJyvxiZh6L3MdI1817XAfVTYp8zYj6Mk=
78+
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
7779
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
7880
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
7981
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=

0 commit comments

Comments
 (0)