|
@@ -41,6 +41,7 @@ type JSONFileLogger struct {
|
|
ctx logger.Context
|
|
ctx logger.Context
|
|
readers map[*logger.LogWatcher]struct{} // stores the active log followers
|
|
readers map[*logger.LogWatcher]struct{} // stores the active log followers
|
|
notifyRotate *pubsub.Publisher
|
|
notifyRotate *pubsub.Publisher
|
|
|
|
+ extra []byte // json-encoded extra attributes
|
|
}
|
|
}
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
@@ -77,6 +78,16 @@ func New(ctx logger.Context) (logger.Logger, error) {
|
|
return nil, fmt.Errorf("max-file cannot be less than 1")
|
|
return nil, fmt.Errorf("max-file cannot be less than 1")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ var extra []byte
|
|
|
|
+ if attrs := ctx.ExtraAttributes(nil); len(attrs) > 0 {
|
|
|
|
+ var err error
|
|
|
|
+ extra, err = json.Marshal(attrs)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
return &JSONFileLogger{
|
|
return &JSONFileLogger{
|
|
f: log,
|
|
f: log,
|
|
buf: bytes.NewBuffer(nil),
|
|
buf: bytes.NewBuffer(nil),
|
|
@@ -85,6 +96,7 @@ func New(ctx logger.Context) (logger.Logger, error) {
|
|
n: maxFiles,
|
|
n: maxFiles,
|
|
readers: make(map[*logger.LogWatcher]struct{}),
|
|
readers: make(map[*logger.LogWatcher]struct{}),
|
|
notifyRotate: pubsub.NewPublisher(0, 1),
|
|
notifyRotate: pubsub.NewPublisher(0, 1),
|
|
|
|
+ extra: extra,
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -97,7 +109,12 @@ func (l *JSONFileLogger) Log(msg *logger.Message) error {
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- err = (&jsonlog.JSONLogs{Log: append(msg.Line, '\n'), Stream: msg.Source, Created: timestamp}).MarshalJSONBuf(l.buf)
|
|
|
|
|
|
+ err = (&jsonlog.JSONLogs{
|
|
|
|
+ Log: append(msg.Line, '\n'),
|
|
|
|
+ Stream: msg.Source,
|
|
|
|
+ Created: timestamp,
|
|
|
|
+ RawAttrs: l.extra,
|
|
|
|
+ }).MarshalJSONBuf(l.buf)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -181,6 +198,8 @@ func ValidateLogOpt(cfg map[string]string) error {
|
|
switch key {
|
|
switch key {
|
|
case "max-file":
|
|
case "max-file":
|
|
case "max-size":
|
|
case "max-size":
|
|
|
|
+ case "labels":
|
|
|
|
+ case "env":
|
|
default:
|
|
default:
|
|
return fmt.Errorf("unknown log opt '%s' for json-file log driver", key)
|
|
return fmt.Errorf("unknown log opt '%s' for json-file log driver", key)
|
|
}
|
|
}
|