github.com/dpiddy/docker@v1.12.2-rc1/daemon/logger/loggerutils/log_tag.go (about) 1 package loggerutils 2 3 import ( 4 "bytes" 5 6 "github.com/docker/docker/daemon/logger" 7 "github.com/docker/docker/utils/templates" 8 ) 9 10 // ParseLogTag generates a context aware tag for consistency across different 11 // log drivers based on the context of the running container. 12 func ParseLogTag(ctx logger.Context, defaultTemplate string) (string, error) { 13 tagTemplate := ctx.Config["tag"] 14 if tagTemplate == "" { 15 tagTemplate = defaultTemplate 16 } 17 18 tmpl, err := templates.NewParse("log-tag", tagTemplate) 19 if err != nil { 20 return "", err 21 } 22 buf := new(bytes.Buffer) 23 if err := tmpl.Execute(buf, &ctx); err != nil { 24 return "", err 25 } 26 27 return buf.String(), nil 28 }