github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/daemon/logger/loggerutils/log_tag.go (about) 1 package loggerutils 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "github.com/Sirupsen/logrus" 8 "github.com/docker/docker/daemon/logger" 9 "github.com/docker/docker/utils/templates" 10 ) 11 12 // ParseLogTag generates a context aware tag for consistency across different 13 // log drivers based on the context of the running container. 14 func ParseLogTag(ctx logger.Context, defaultTemplate string) (string, error) { 15 tagTemplate := lookupTagTemplate(ctx, defaultTemplate) 16 17 tmpl, err := templates.NewParse("log-tag", tagTemplate) 18 if err != nil { 19 return "", err 20 } 21 buf := new(bytes.Buffer) 22 if err := tmpl.Execute(buf, &ctx); err != nil { 23 return "", err 24 } 25 26 return buf.String(), nil 27 } 28 29 func lookupTagTemplate(ctx logger.Context, defaultTemplate string) string { 30 tagTemplate := ctx.Config["tag"] 31 32 deprecatedConfigs := []string{"syslog-tag", "gelf-tag", "fluentd-tag"} 33 for i := 0; tagTemplate == "" && i < len(deprecatedConfigs); i++ { 34 cfg := deprecatedConfigs[i] 35 if ctx.Config[cfg] != "" { 36 tagTemplate = ctx.Config[cfg] 37 logrus.Warn(fmt.Sprintf("Using log tag from deprecated log-opt '%s'. Please use: --log-opt tag=\"%s\"", cfg, tagTemplate)) 38 } 39 } 40 41 if tagTemplate == "" { 42 tagTemplate = defaultTemplate 43 } 44 45 return tagTemplate 46 }