diff options
-rw-r--r-- | sms-service/src/sms/log/logger.go | 17 | ||||
-rw-r--r-- | sms-service/src/sms/sms.go | 4 |
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 { |