@@ -10,7 +10,6 @@ import (
10
10
"path/filepath"
11
11
"sync"
12
12
"sync/atomic"
13
- "time"
14
13
"unsafe"
15
14
16
15
"github.com/kpango/fastime"
@@ -20,7 +19,6 @@ import (
20
19
type Glg struct {
21
20
logger sync.Map // map[uint8]*logger
22
21
timer * atomic.Value // []byte
23
- mu sync.Mutex
24
22
levelCounter * uint32
25
23
levelMap sync.Map
26
24
buffer sync.Pool
@@ -84,6 +82,8 @@ const (
84
82
85
83
// Default Format
86
84
df = "%v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v %v "
85
+
86
+ timeFormat = "2006-01-02 15:04:05"
87
87
)
88
88
89
89
var (
@@ -224,7 +224,8 @@ func New() *Glg {
224
224
g .logger .Store (k , v )
225
225
}
226
226
227
- return g .startTimerD ()
227
+ // return g.startTimerD()
228
+ return g
228
229
}
229
230
230
231
// Get returns singleton glg instance
@@ -235,36 +236,36 @@ func Get() *Glg {
235
236
return glg
236
237
}
237
238
238
- func (g * Glg ) startTimerD () * Glg {
239
- g .timer = new (atomic.Value )
240
- timeFormat := "2006-01-02 15:04:05"
241
-
242
- g .storeTime (timeFormat )
243
-
244
- var ctx context.Context
245
- ctx , g .cancel = context .WithCancel (context .Background ())
246
-
247
- go func () {
248
- ticker := time .NewTicker (time .Millisecond * 500 )
249
- for {
250
- select {
251
- case <- ctx .Done ():
252
- ticker .Stop ()
253
- return
254
- case <- ticker .C :
255
- g .storeTime (timeFormat )
256
- }
257
- }
258
- }()
259
-
260
- return g
261
- }
262
-
263
- func (g * Glg ) storeTime (format string ) {
264
- buf := g .buffer .Get ().([]byte )
265
- g .timer .Store (fastime .Now ().AppendFormat (buf [:0 ], format ))
266
- g .buffer .Put (buf [:0 ])
267
- }
239
+ // func (g *Glg) startTimerD() *Glg {
240
+ // g.timer = new(atomic.Value)
241
+ // timeFormat := "2006-01-02 15:04:05"
242
+ //
243
+ // g.storeTime(timeFormat)
244
+ //
245
+ // var ctx context.Context
246
+ // ctx, g.cancel = context.WithCancel(context.Background())
247
+ //
248
+ // go func() {
249
+ // ticker := time.NewTicker(time.Millisecond * 500)
250
+ // for {
251
+ // select {
252
+ // case <-ctx.Done():
253
+ // ticker.Stop()
254
+ // return
255
+ // case <-ticker.C:
256
+ // g.storeTime(timeFormat)
257
+ // }
258
+ // }
259
+ // }()
260
+ //
261
+ // return g
262
+ // }
263
+ //
264
+ // func (g *Glg) storeTime(format string) {
265
+ // buf := g.buffer.Get().([]byte)
266
+ // g.timer.Store(fastime.Now().AppendFormat(buf[:0], format))
267
+ // g.buffer.Put(buf[:0])
268
+ // }
268
269
269
270
// Stop stops glg timer daemon
270
271
func (g * Glg ) Stop () * Glg {
@@ -688,31 +689,21 @@ func (g *Glg) out(level LEVEL, format string, val ...interface{}) error {
688
689
689
690
switch log .writeMode {
690
691
case writeColorStd :
691
- g .mu .Lock ()
692
- buf = append (append (append (append (append (buf [:0 ], g .timer .Load ().([]byte )... ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... )
693
- g .mu .Unlock ()
692
+ buf = append (append (append (append (fastime .Now ().AppendFormat (buf [:0 ], timeFormat ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... )
694
693
_ , err = fmt .Fprintf (log .std , log .color (* (* string )(unsafe .Pointer (& buf )))+ "\n " , val ... )
695
694
case writeStd :
696
- g .mu .Lock ()
697
- buf = append (append (append (append (append (append (buf [:0 ], g .timer .Load ().([]byte )... ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... ), "\n " ... )
698
- g .mu .Unlock ()
695
+ buf = append (append (append (append (append (fastime .Now ().AppendFormat (buf [:0 ], timeFormat ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... ), "\n " ... )
699
696
_ , err = fmt .Fprintf (log .std , * (* string )(unsafe .Pointer (& buf )), val ... )
700
697
case writeWriter :
701
- g .mu .Lock ()
702
- buf = append (append (append (append (append (append (buf [:0 ], g .timer .Load ().([]byte )... ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... ), "\n " ... )
703
- g .mu .Unlock ()
698
+ buf = append (append (append (append (append (fastime .Now ().AppendFormat (buf [:0 ], timeFormat ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... ), "\n " ... )
704
699
_ , err = fmt .Fprintf (log .writer , * (* string )(unsafe .Pointer (& buf )), val ... )
705
700
case writeColorBoth :
706
- g .mu .Lock ()
707
- buf = append (append (append (append (append (buf [:0 ], g .timer .Load ().([]byte )... ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... )
708
- g .mu .Unlock ()
701
+ buf = append (append (append (append (fastime .Now ().AppendFormat (buf [:0 ], timeFormat ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... )
709
702
var str = * (* string )(unsafe .Pointer (& buf ))
710
703
_ , err = fmt .Fprintf (log .std , log .color (str )+ "\n " , val ... )
711
704
_ , err = fmt .Fprintf (log .writer , str + "\n " , val ... )
712
705
case writeBoth :
713
- g .mu .Lock ()
714
- buf = append (append (append (append (append (append (buf [:0 ], g .timer .Load ().([]byte )... ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... ), "\n " ... )
715
- g .mu .Unlock ()
706
+ buf = append (append (append (append (append (fastime .Now ().AppendFormat (buf [:0 ], timeFormat ), "\t [" ... ), log .tag ... ), "]:\t " ... ), format ... ), "\n " ... )
716
707
_ , err = fmt .Fprintf (io .MultiWriter (log .std , log .writer ), * (* string )(unsafe .Pointer (& buf )), val ... )
717
708
}
718
709
g .buffer .Put (buf [:0 ])
0 commit comments