Browse code

daemon/logger/jsonfilelog: avoid some allocations

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>

unclejack authored on 2015/04/02 02:15:50
Showing 1 changed files
... ...
@@ -7,6 +7,7 @@ import (
7 7
 
8 8
 	"github.com/docker/docker/daemon/logger"
9 9
 	"github.com/docker/docker/pkg/jsonlog"
10
+	"github.com/docker/docker/pkg/timeutils"
10 11
 )
11 12
 
12 13
 // JSONFileLogger is Logger implementation for default docker logging:
... ...
@@ -33,7 +34,11 @@ func New(filename string) (logger.Logger, error) {
33 33
 func (l *JSONFileLogger) Log(msg *logger.Message) error {
34 34
 	l.mu.Lock()
35 35
 	defer l.mu.Unlock()
36
-	err := (&jsonlog.JSONLog{Log: string(msg.Line) + "\n", Stream: msg.Source, Created: msg.Timestamp}).MarshalJSONBuf(l.buf)
36
+	timestamp, err := timeutils.FastMarshalJSON(msg.Timestamp)
37
+	if err != nil {
38
+		return err
39
+	}
40
+	err = (&jsonlog.JSONLogBytes{Log: append(msg.Line, '\n'), Stream: msg.Source, Created: timestamp}).MarshalJSONBuf(l.buf)
37 41
 	if err != nil {
38 42
 		return err
39 43
 	}