Add support for reading logs extra attrs
The jsonlog logger currently allows specifying envs and labels that should be propagated to the log message, however there has been no way to read that back. This adds a new API option to enable inserting these attrs back to the log reader. With timestamps, this looks like so: ``` 92016-04-08T15:28:09.835913720Z foo=bar,hello=world hello ``` The extra attrs are comma separated before the log message but after timestamps. Without timestaps it looks like so: ``` foo=bar,hello=world hello ``` Signed-off-by: Brian Goff <cpuguy83@gmail.com> Upstream-commit: bd9d14a07b9f1c82625dc8483245caf3fa7fe9e6 Component: engine
This commit is contained in:
@@ -307,3 +307,16 @@ func (s *DockerSuite) TestLogsCLIContainerNotFound(c *check.C) {
|
||||
message := fmt.Sprintf("Error: No such container: %s\n", name)
|
||||
c.Assert(out, checker.Equals, message)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestLogsWithDetails(c *check.C) {
|
||||
dockerCmd(c, "run", "--name=test", "--label", "foo=bar", "-e", "baz=qux", "--log-opt", "labels=foo", "--log-opt", "env=baz", "busybox", "echo", "hello")
|
||||
out, _ := dockerCmd(c, "logs", "--details", "--timestamps", "test")
|
||||
|
||||
logFields := strings.Fields(strings.TrimSpace(out))
|
||||
c.Assert(len(logFields), checker.Equals, 3, check.Commentf(out))
|
||||
|
||||
details := strings.Split(logFields[1], ",")
|
||||
c.Assert(details, checker.HasLen, 2)
|
||||
c.Assert(details[0], checker.Equals, "baz=qux")
|
||||
c.Assert(details[1], checker.Equals, "foo=bar")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user