github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/daemon/logger/loggerutils/log_tag.go (about) 1 package loggerutils // import "github.com/docker/docker/daemon/logger/loggerutils" 2 3 import ( 4 "bytes" 5 6 "github.com/docker/docker/daemon/logger" 7 "github.com/docker/docker/daemon/logger/templates" 8 ) 9 10 // DefaultTemplate defines the defaults template logger should use. 11 const DefaultTemplate = "{{.ID}}" 12 13 // ParseLogTag generates a context aware tag for consistency across different 14 // log drivers based on the context of the running container. 15 func ParseLogTag(info logger.Info, defaultTemplate string) (string, error) { 16 tagTemplate := info.Config["tag"] 17 if tagTemplate == "" { 18 tagTemplate = defaultTemplate 19 } 20 21 tmpl, err := templates.NewParse("log-tag", tagTemplate) 22 if err != nil { 23 return "", err 24 } 25 buf := new(bytes.Buffer) 26 if err := tmpl.Execute(buf, &info); err != nil { 27 return "", err 28 } 29 30 return buf.String(), nil 31 }