mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix logs, so now, old and followed logs has same format without []
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
parent
17e840a47a
commit
e16bcc3928
3 changed files with 5 additions and 3 deletions
|
@ -99,7 +99,8 @@ func (daemon *Daemon) ContainerLogs(job *engine.Job) engine.Status {
|
||||||
}
|
}
|
||||||
logLine := l.Log
|
logLine := l.Log
|
||||||
if times {
|
if times {
|
||||||
logLine = fmt.Sprintf("%s %s", l.Created.Format(format), logLine)
|
// format can be "" or time format, so here can't be error
|
||||||
|
logLine, _ = l.Format(format)
|
||||||
}
|
}
|
||||||
if l.Stream == "stdout" && stdout {
|
if l.Stream == "stdout" && stdout {
|
||||||
io.WriteString(job.Stdout, logLine)
|
io.WriteString(job.Stdout, logLine)
|
||||||
|
|
|
@ -23,7 +23,7 @@ func (jl *JSONLog) Format(format string) (string, error) {
|
||||||
m, err := json.Marshal(jl)
|
m, err := json.Marshal(jl)
|
||||||
return string(m), err
|
return string(m), err
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("[%s] %s", jl.Created.Format(format), jl.Log), nil
|
return fmt.Sprintf("%s %s", jl.Created.Format(format), jl.Log), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jl *JSONLog) Reset() {
|
func (jl *JSONLog) Reset() {
|
||||||
|
|
|
@ -30,7 +30,8 @@ func TestWriteLog(t *testing.T) {
|
||||||
if len(lines) != 30 {
|
if len(lines) != 30 {
|
||||||
t.Fatalf("Must be 30 lines but got %d", len(lines))
|
t.Fatalf("Must be 30 lines but got %d", len(lines))
|
||||||
}
|
}
|
||||||
logRe := regexp.MustCompile(`\[.*\] Line that thinks that it is log line from docker`)
|
// 30+ symbols, five more can come from system timezone
|
||||||
|
logRe := regexp.MustCompile(`.{30,} Line that thinks that it is log line from docker`)
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
if !logRe.MatchString(l) {
|
if !logRe.MatchString(l) {
|
||||||
t.Fatalf("Log line not in expected format: %q", l)
|
t.Fatalf("Log line not in expected format: %q", l)
|
||||||
|
|
Loading…
Reference in a new issue