@@ -20,6 +20,7 @@ import (
20
20
type Glg struct {
21
21
logger sync.Map // map[uint8]*logger
22
22
timer * atomic.Value // []byte
23
+ mu sync.Mutex
23
24
levelCounter * uint32
24
25
levelMap sync.Map
25
26
buffer sync.Pool
@@ -687,21 +688,31 @@ func (g *Glg) out(level LEVEL, format string, val ...interface{}) error {
687
688
688
689
switch log .writeMode {
689
690
case writeColorStd :
691
+ g .mu .Lock ()
690
692
buf = append (append (append (append (append (buf [:0 ], g .timer .Load ().([]byte )... ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... )
693
+ g .mu .Unlock ()
691
694
_ , err = fmt .Fprintf (log .std , log .color (* (* string )(unsafe .Pointer (& buf )))+ "\n " , val ... )
692
695
case writeStd :
696
+ g .mu .Lock ()
693
697
buf = append (append (append (append (append (append (buf [:0 ], g .timer .Load ().([]byte )... ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... ), "\n " ... )
698
+ g .mu .Unlock ()
694
699
_ , err = fmt .Fprintf (log .std , * (* string )(unsafe .Pointer (& buf )), val ... )
695
700
case writeWriter :
701
+ g .mu .Lock ()
696
702
buf = append (append (append (append (append (append (buf [:0 ], g .timer .Load ().([]byte )... ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... ), "\n " ... )
703
+ g .mu .Unlock ()
697
704
_ , err = fmt .Fprintf (log .writer , * (* string )(unsafe .Pointer (& buf )), val ... )
698
705
case writeColorBoth :
706
+ g .mu .Lock ()
699
707
buf = append (append (append (append (append (buf [:0 ], g .timer .Load ().([]byte )... ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... )
708
+ g .mu .Unlock ()
700
709
var str = * (* string )(unsafe .Pointer (& buf ))
701
710
_ , err = fmt .Fprintf (log .std , log .color (str )+ "\n " , val ... )
702
711
_ , err = fmt .Fprintf (log .writer , str + "\n " , val ... )
703
712
case writeBoth :
713
+ g .mu .Lock ()
704
714
buf = append (append (append (append (append (append (buf [:0 ], g .timer .Load ().([]byte )... ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... ), "\n " ... )
715
+ g .mu .Unlock ()
705
716
_ , err = fmt .Fprintf (io .MultiWriter (log .std , log .writer ), * (* string )(unsafe .Pointer (& buf )), val ... )
706
717
}
707
718
g .buffer .Put (buf [:0 ])
0 commit comments