log/logid+glslogid.go
2022-12-05 10:55:24 +08:00

39 lines
579 B
Go

// +build glslogid
package log
import (
"fmt"
"github.com/tylerb/gls"
)
type glsLogidCreator struct {
idkey string
}
func (creator *glsLogidCreator) GetLogid() string {
id := gls.Get(creator.idkey)
if id == nil {
return ""
}
if logid, ok := id.(string); ok {
return logid
} else {
return fmt.Sprintf("%s", id)
}
}
func (creator *glsLogidCreator) SetLogid(logid string) {
gls.Set(creator.idkey, logid)
}
func (creator *glsLogidCreator) Cleanup() {
gls.Cleanup()
}
func init() {
idc := &glsLogidCreator{
idkey: "logidkey",
}
RegisterLogidCreator(idc)
}