Skip to content

Commit

Permalink
Merge pull request moby#22384 from yongtang/22358-log-tag-prefix
Browse files Browse the repository at this point in the history
Remove `docker/` prefix from log messages tag.
  • Loading branch information
thaJeztah committed May 30, 2016
2 parents 34e0a01 + 38c49d9 commit f3a7abe
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func (container *Container) StartLogger(cfg containertypes.LogConfig) (logger.Lo
ContainerCreated: container.Created,
ContainerEnv: container.Config.Env,
ContainerLabels: container.Config.Labels,
DaemonName: "docker",
}

// Set logging file for "json-logger"
Expand Down
1 change: 1 addition & 0 deletions daemon/logger/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Context struct {
ContainerEnv []string
ContainerLabels map[string]string
LogPath string
DaemonName string
}

// ExtraAttributes returns the user-defined extra attributes (labels,
Expand Down
2 changes: 1 addition & 1 deletion daemon/logger/fluentd/fluentd.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func New(ctx logger.Context) (logger.Logger, error) {
return nil, err
}

tag, err := loggerutils.ParseLogTag(ctx, "docker.{{.ID}}")
tag, err := loggerutils.ParseLogTag(ctx, "{{.DaemonName}}.{{.ID}}")
if err != nil {
return nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions daemon/logger/loggerutils/log_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ func TestParseLogTag(t *testing.T) {
assertTag(t, e, tag, "test-image/test-container/container-ab")
}

func TestParseLogTagEmptyTag(t *testing.T) {
ctx := buildContext(map[string]string{})
tag, e := ParseLogTag(ctx, "{{.DaemonName}}/{{.ID}}")
assertTag(t, e, tag, "test-dockerd/container-ab")
}

// Helpers

func buildContext(cfg map[string]string) logger.Context {
Expand All @@ -27,6 +33,7 @@ func buildContext(cfg map[string]string) logger.Context {
ContainerImageID: "image-abcdefghijklmnopqrstuvwxyz01234567890",
ContainerImageName: "test-image",
Config: cfg,
DaemonName: "test-dockerd",
}
}

Expand Down
9 changes: 3 additions & 6 deletions daemon/logger/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net"
"net/url"
"os"
"path"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -91,7 +90,7 @@ func rfc5424microformatterWithAppNameAsTag(p syslog.Priority, hostname, tag, con
// the context. Supported context configuration variables are
// syslog-address, syslog-facility, syslog-format.
func New(ctx logger.Context) (logger.Logger, error) {
tag, err := loggerutils.ParseLogTag(ctx, "{{.ID}}")
tag, err := loggerutils.ParseLogTag(ctx, "{{.DaemonName}}/{{.ID}}")
if err != nil {
return nil, err
}
Expand All @@ -111,17 +110,15 @@ func New(ctx logger.Context) (logger.Logger, error) {
return nil, err
}

logTag := path.Base(os.Args[0]) + "/" + tag

var log *syslog.Writer
if proto == secureProto {
tlsConfig, tlsErr := parseTLSConfig(ctx.Config)
if tlsErr != nil {
return nil, tlsErr
}
log, err = syslog.DialWithTLSConfig(proto, address, facility, logTag, tlsConfig)
log, err = syslog.DialWithTLSConfig(proto, address, facility, tag, tlsConfig)
} else {
log, err = syslog.Dial(proto, address, facility, logTag)
log, err = syslog.Dial(proto, address, facility, tag)
}

if err != nil {
Expand Down
1 change: 1 addition & 0 deletions docs/admin/logging/log_tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Docker supports some special template markup you can use when specifying a tag's
| `{{.ImageID}}` | The first 12 characters of the container's image id. |
| `{{.ImageFullID}}` | The container's full image identifier. |
| `{{.ImageName}}` | The name of the image used by the container. |
| `{{.DaemonName}}` | The name of the docker program (`docker`). |

For example, specifying a `--log-opt tag="{{.ImageName}}/{{.Name}}/{{.ID}}"` value yields `syslog` log lines like:

Expand Down

0 comments on commit f3a7abe

Please sign in to comment.