github.com/sereiner/library@v0.0.0-20200518095232-1fa3e640cc5f/log/event.go (about) 1 package log 2 3 import "time" 4 import "sync" 5 6 var eventPool *sync.Pool 7 8 func init() { 9 eventPool = &sync.Pool{ 10 New: func() interface{} { 11 return &LogEvent{} 12 }, 13 } 14 } 15 16 type LogEvent struct { 17 Level string 18 Now time.Time 19 Name string 20 Session string 21 Content string 22 Output string 23 Index int64 24 Tags map[string]string 25 } 26 27 func NewLogEvent(name string, level string, session string, content string, tags map[string]string, index int64) *LogEvent { 28 e := eventPool.Get().(*LogEvent) 29 e.Now = time.Now() 30 e.Level = level 31 e.Name = name 32 e.Session = session 33 e.Content = content 34 e.Tags = tags 35 e.Index = index 36 return e 37 } 38 func (l *LogEvent) Close() { 39 eventPool.Put(l) 40 }