github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/daemon/logger/loggerutils/log_tag.go (about)

     1  package loggerutils // import "github.com/demonoid81/moby/daemon/logger/loggerutils"
     2  
     3  import (
     4  	"bytes"
     5  
     6  	"github.com/demonoid81/moby/daemon/logger"
     7  	"github.com/demonoid81/moby/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  }