gopkg.in/dotcloud/docker.v1@v1.13.1/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  // 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(ctx logger.Context, defaultTemplate string) (string, error) {
    16  	tagTemplate := ctx.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, &ctx); err != nil {
    27  		return "", err
    28  	}
    29  
    30  	return buf.String(), nil
    31  }