Skip to content

Commit

Permalink
Fixed a race condition
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
pieterclaerhout committed May 23, 2020
1 parent 4b4cee9 commit badf63b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions logger_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"runtime"
"strings"
"sync"
"time"

"github.com/fatih/color"
Expand All @@ -19,6 +20,8 @@ var colors = map[string]*color.Color{
"FATAL": color.New(color.FgHiRed),
}

var mutex sync.Mutex

func init() {

TimeZone, _ = time.LoadLocation("Europe/Brussels")
Expand Down Expand Up @@ -73,6 +76,8 @@ func printNonColoredMessage(level string, message string) {
func printColoredMessage(level string, message string) {
w := writerForLevel(level)
if c, ok := colors[level]; ok {
mutex.Lock()
defer mutex.Unlock()
c.EnableColor()
c.Fprint(w, message)
w.Write([]byte("\n"))
Expand Down

0 comments on commit badf63b

Please sign in to comment.