From 21fc1775514586a796e1a4f4ded8c567c442a605 Mon Sep 17 00:00:00 2001 From: Faissal Elamraoui Date: Tue, 15 Nov 2016 12:25:37 +0100 Subject: [PATCH] Acquire lock when logging --- apiapp.go | 3 +-- logger.go | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apiapp.go b/apiapp.go index a1442d7..ca8cf22 100644 --- a/apiapp.go +++ b/apiapp.go @@ -558,8 +558,7 @@ func createapi(cmd *Command, args []string) int { apppath, packpath, err := checkEnv(args[0]) if err != nil { - fmt.Println(err) - os.Exit(2) + logger.Fatalf("%s", err) } if driver == "" { driver = "mysql" diff --git a/logger.go b/logger.go index ded3e9e..8189a52 100644 --- a/logger.go +++ b/logger.go @@ -61,7 +61,6 @@ type LogRecord struct { var ( logRecordTemplate *template.Template debugLogRecordTemplate *template.Template - debugLogFormat string ) func init() { @@ -141,6 +140,10 @@ func (l *BeeLogger) getColorLevel(level int) string { // mustLog logs the message according to the specified level and arguments. // It panics in case of an error. func (l *BeeLogger) mustLog(level int, message string, args ...interface{}) { + // Acquire the lock + l.mu.Lock() + defer l.mu.Unlock() + // Create the logging record and pass into the output record := LogRecord{ ID: fmt.Sprintf("%04d", atomic.AddUint64(&sequenceNo, 1)),