summaryrefslogtreecommitdiffstats
path: root/sms-service
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-03-09 14:23:09 -0800
committerKiran Kamineni <kiran.k.kamineni@intel.com>2018-03-13 19:33:13 +0000
commit2d5cceffb52baabe08c1e293531ba42c3a9b550a (patch)
treee9633d5e7050aa79fad7f83602c72e1dc5cda95f /sms-service
parent6915d039b71df5aafd2746f933bffbd824343382 (diff)
Fixing the logger initialization to sms.go
Using golang init is creating log files in various folders when tests are run. Moved to Init which is called my server initialization. Issue-ID: AAF-148 Change-Id: Ia05fa1ed1841fd6a98852329ab031372f6489ad6 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'sms-service')
-rw-r--r--sms-service/src/sms/log/logger.go17
-rw-r--r--sms-service/src/sms/sms.go4
2 files changed, 13 insertions, 8 deletions
diff --git a/sms-service/src/sms/log/logger.go b/sms-service/src/sms/log/logger.go
index ad7d388..8d116dd 100644
--- a/sms-service/src/sms/log/logger.go
+++ b/sms-service/src/sms/log/logger.go
@@ -25,18 +25,19 @@ var errLogger *log.Logger
var warnLogger *log.Logger
var infoLogger *log.Logger
-func init() {
- f, err := os.OpenFile("sms.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
+// Init will be called by sms.go before any other packages use it
+func Init(filePath string) {
+ f, err := os.Create(filePath)
if err != nil {
log.Println("Unable to create a log file")
log.Println(err)
- errLogger = log.New(os.Stderr, "ERROR: ", log.Lshortfile)
- warnLogger = log.New(os.Stdout, "WARNING: ", log.Lshortfile)
- infoLogger = log.New(os.Stdout, "INFO: ", log.Lshortfile)
+ errLogger = log.New(os.Stderr, "ERROR: ", log.Lshortfile|log.LstdFlags)
+ warnLogger = log.New(os.Stdout, "WARNING: ", log.Lshortfile|log.LstdFlags)
+ infoLogger = log.New(os.Stdout, "INFO: ", log.Lshortfile|log.LstdFlags)
} else {
- errLogger = log.New(f, "ERROR: ", log.Lshortfile)
- warnLogger = log.New(f, "WARNING: ", log.Lshortfile)
- infoLogger = log.New(f, "INFO: ", log.Lshortfile)
+ errLogger = log.New(f, "ERROR: ", log.Lshortfile|log.LstdFlags)
+ warnLogger = log.New(f, "WARNING: ", log.Lshortfile|log.LstdFlags)
+ infoLogger = log.New(f, "INFO: ", log.Lshortfile|log.LstdFlags)
}
}
diff --git a/sms-service/src/sms/sms.go b/sms-service/src/sms/sms.go
index b117bbc..eb0bebc 100644
--- a/sms-service/src/sms/sms.go
+++ b/sms-service/src/sms/sms.go
@@ -24,9 +24,13 @@ import (
smsbackend "sms/backend"
smsconfig "sms/config"
smshandler "sms/handler"
+ smslogger "sms/log"
)
func main() {
+ // Initialize logger
+ smslogger.Init("sms.log")
+
// Read Configuration File
smsConf, err := smsconfig.ReadConfigFile("smsconfig.json")
if err != nil {