qoobing.com/gomod/log@v1.2.8/logid+glslogid.go (about) 1 // +build glslogid 2 package log 3 4 import ( 5 "fmt" 6 "github.com/tylerb/gls" 7 ) 8 9 type glsLogidCreator struct { 10 idkey string 11 } 12 13 func (creator *glsLogidCreator) GetLogid() string { 14 id := gls.Get(creator.idkey) 15 if id == nil { 16 return "" 17 } 18 if logid, ok := id.(string); ok { 19 return logid 20 } else { 21 return fmt.Sprintf("%s", id) 22 } 23 } 24 25 func (creator *glsLogidCreator) SetLogid(logid string) { 26 gls.Set(creator.idkey, logid) 27 } 28 29 func (creator *glsLogidCreator) Cleanup() { 30 gls.Cleanup() 31 } 32 33 func init() { 34 idc := &glsLogidCreator{ 35 idkey: "logidkey", 36 } 37 RegisterLogidCreator(idc) 38 }