Browse code

Fix logs, so now, old and followed logs has same format without []

Signed-off-by: Alexander Morozov <lk4d4@docker.com>

Alexander Morozov authored on 2015/01/29 07:33:15
Showing 3 changed files
... ...
@@ -99,7 +99,8 @@ func (daemon *Daemon) ContainerLogs(job *engine.Job) engine.Status {
99 99
 				}
100 100
 				logLine := l.Log
101 101
 				if times {
102
-					logLine = fmt.Sprintf("%s %s", l.Created.Format(format), logLine)
102
+					// format can be "" or time format, so here can't be error
103
+					logLine, _ = l.Format(format)
103 104
 				}
104 105
 				if l.Stream == "stdout" && stdout {
105 106
 					io.WriteString(job.Stdout, logLine)
... ...
@@ -23,7 +23,7 @@ func (jl *JSONLog) Format(format string) (string, error) {
23 23
 		m, err := json.Marshal(jl)
24 24
 		return string(m), err
25 25
 	}
26
-	return fmt.Sprintf("[%s] %s", jl.Created.Format(format), jl.Log), nil
26
+	return fmt.Sprintf("%s %s", jl.Created.Format(format), jl.Log), nil
27 27
 }
28 28
 
29 29
 func (jl *JSONLog) Reset() {
... ...
@@ -30,7 +30,8 @@ func TestWriteLog(t *testing.T) {
30 30
 	if len(lines) != 30 {
31 31
 		t.Fatalf("Must be 30 lines but got %d", len(lines))
32 32
 	}
33
-	logRe := regexp.MustCompile(`\[.*\] Line that thinks that it is log line from docker`)
33
+	// 30+ symbols, five more can come from system timezone
34
+	logRe := regexp.MustCompile(`.{30,} Line that thinks that it is log line from docker`)
34 35
 	for _, l := range lines {
35 36
 		if !logRe.MatchString(l) {
36 37
 			t.Fatalf("Log line not in expected format: %q", l)