@@ -568,34 +568,36 @@ func getMemlogMsg(logChan chan inputEntry, panicFileChan chan []byte) {
568568 continue
569569 }
570570 var pidStr string
571- var logInfo agentlog.Loginfo
572571 // Everything is json, in some cases with an embedded json Msg
573572 logEntry , jsonOK := ParseMemlogLogEntry (string (bytes ))
574573 if ! jsonOK {
575574 log .Warnf ("Received non-json from memlogd: %s\n " ,
576575 string (bytes ))
577576 continue
578577 }
579- // Start with the envelope
580- logInfo .Source = logEntry .Source
581- logInfo .Time = logEntry .Time
582- logInfo .Msg = logEntry .Msg
583578
584579 // Is the Msg itself json?
585- logInfo2 , ok := agentlog .ParseLoginfo (logInfo .Msg )
586- if ok {
587- // If the inner has Time or Source set they take
588- // precedence over the envelope
589- if logInfo2 .Time == "" {
590- logInfo2 .Time = logInfo .Time
580+ logInfo , ok := agentlog .ParseLoginfo (logEntry .Msg )
581+ if ok { // Use the inner JSON struct
582+ // Go back to the envelope for anything not in the inner JSON
583+ if logInfo .Time == "" {
584+ logInfo .Time = logEntry .Time
591585 }
592- if logInfo2 .Source == "" {
593- logInfo2 .Source = logInfo .Source
586+ if logInfo .Source == "" {
587+ logInfo .Source = logEntry .Source
594588 }
595- logInfo = logInfo2
589+ // and keep the original message text and fields
590+ logInfo .Msg = logEntry .Msg
596591 } else {
592+ // Start with the envelope
593+ logInfo .Source = logEntry .Source
594+ logInfo .Time = logEntry .Time
595+ logInfo .Msg = logEntry .Msg
596+
597597 // Some messages have attr=val syntax
598- level , timeStr , msg := parseLevelTimeMsg (logInfo .Msg )
598+ // If the inner message has Level, Time or Msg set they take
599+ // precedence over the envelope
600+ level , timeStr , msg := parseLevelTimeMsg (logEntry .Msg )
599601 if level != "" {
600602 logInfo .Level = level
601603 }
@@ -606,16 +608,19 @@ func getMemlogMsg(logChan chan inputEntry, panicFileChan chan []byte) {
606608 logInfo .Msg = msg
607609 }
608610 }
611+
609612 if strings .Contains (logInfo .Source , "guest_vm" ) {
610613 logmetrics .AppMetrics .NumInputEvent ++
611614 } else if logInfo .Containername != "" {
612615 logmetrics .AppMetrics .NumInputEvent ++
613616 } else {
614617 logmetrics .DevMetrics .NumInputEvent ++
615618 }
619+
616620 if logInfo .Pid != 0 {
617621 pidStr = strconv .Itoa (logInfo .Pid )
618622 }
623+
619624 entry := inputEntry {
620625 source : logInfo .Source ,
621626 content : logInfo .Msg ,
0 commit comments