github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/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/pkg/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 }