Skip to content

Commit 1b776c3

Browse files
author
kpango
committed
fix
1 parent 950eaac commit 1b776c3

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

glg.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ func (g *Glg) startTimerD() *Glg {
233233
g.timer = new(atomic.Value)
234234
timeFormat := "2006-01-02 15:04:05"
235235

236-
buf := g.buffer.Get().([]byte)
237-
g.timer.Store(time.Now().AppendFormat(buf[:0], timeFormat))
238-
g.buffer.Put(buf[:0])
236+
g.storeTime(timeFormat)
239237

240238
var ctx context.Context
241239
ctx, g.cancel = context.WithCancel(context.Background())
@@ -248,16 +246,20 @@ func (g *Glg) startTimerD() *Glg {
248246
ticker.Stop()
249247
return
250248
case <-ticker.C:
251-
buf := g.buffer.Get().([]byte)
252-
g.timer.Store(time.Now().AppendFormat(buf[:0], timeFormat))
253-
g.buffer.Put(buf[:0])
249+
g.storeTime(timeFormat)
254250
}
255251
}
256252
}()
257253

258254
return g
259255
}
260256

257+
func (g *Glg) storeTime(format string) {
258+
buf := g.buffer.Get().([]byte)
259+
g.timer.Store(time.Now().AppendFormat(buf[:0], format))
260+
g.buffer.Put(buf[:0])
261+
}
262+
261263
// Stop stops glg timer daemon
262264
func (g *Glg) Stop() *Glg {
263265
g.cancel()
@@ -644,10 +646,13 @@ func (g *Glg) out(level LEVEL, format string, val ...interface{}) error {
644646
if !ok {
645647
return fmt.Errorf("Log Level %s Not Found", level)
646648
}
647-
log := l.(*logger)
648649

649-
var err error
650-
var buf = g.buffer.Get().([]byte)
650+
var (
651+
err error
652+
buf = g.buffer.Get().([]byte)
653+
log = l.(*logger)
654+
)
655+
651656
switch log.writeMode {
652657
case writeColorStd:
653658
buf = append(append(append(append(g.timer.Load().([]byte), "\t["...), log.tag...), "]:\t"...), format...)

0 commit comments

Comments
 (0)