зеркало из https://github.com/microsoft/docker.git
Merge pull request #11994 from unclejack/jsonfilelog_allocations
daemon/logger/jsonfilelog: avoid some allocations
This commit is contained in:
Коммит
5c83dfe670
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/logger"
|
"github.com/docker/docker/daemon/logger"
|
||||||
"github.com/docker/docker/pkg/jsonlog"
|
"github.com/docker/docker/pkg/jsonlog"
|
||||||
|
"github.com/docker/docker/pkg/timeutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// JSONFileLogger is Logger implementation for default docker logging:
|
// JSONFileLogger is Logger implementation for default docker logging:
|
||||||
|
@ -33,7 +34,11 @@ func New(filename string) (logger.Logger, error) {
|
||||||
func (l *JSONFileLogger) Log(msg *logger.Message) error {
|
func (l *JSONFileLogger) Log(msg *logger.Message) error {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
err := (&jsonlog.JSONLog{Log: string(msg.Line) + "\n", Stream: msg.Source, Created: msg.Timestamp}).MarshalJSONBuf(l.buf)
|
timestamp, err := timeutils.FastMarshalJSON(msg.Timestamp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = (&jsonlog.JSONLogBytes{Log: append(msg.Line, '\n'), Stream: msg.Source, Created: timestamp}).MarshalJSONBuf(l.buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче