github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/log/context/context.go (about) 1 package context 2 3 import ( 4 "github.com/sirupsen/logrus" 5 ) 6 7 func NewLogIDHook() *LogIDHook { 8 return &LogIDHook{} 9 } 10 11 type LogIDHook struct { 12 } 13 14 func (hook *LogIDHook) Fire(entry *logrus.Entry) error { 15 entry.Data["log_id"] = GetLogID() 16 return nil 17 } 18 19 func (hook *LogIDHook) Levels() []logrus.Level { 20 return logrus.AllLevels 21 }