-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_tag.go
31 lines (25 loc) · 834 Bytes
/
log_tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package loggerutils // import "github.com/docker/docker/daemon/logger/loggerutils"
import (
"bytes"
"github.com/docker/docker/daemon/logger"
"github.com/docker/docker/daemon/logger/templates"
)
// DefaultTemplate defines the defaults template logger should use.
const DefaultTemplate = "{{.ID}}"
// ParseLogTag generates a context aware tag for consistency across different
// log drivers based on the context of the running container.
func ParseLogTag(info logger.Info, defaultTemplate string) (string, error) {
tagTemplate := info.Config["tag"]
if tagTemplate == "" {
tagTemplate = defaultTemplate
}
tmpl, err := templates.NewParse("log-tag", tagTemplate)
if err != nil {
return "", err
}
buf := new(bytes.Buffer)
if err := tmpl.Execute(buf, &info); err != nil {
return "", err
}
return buf.String(), nil
}