Skip to content

Commit

Permalink
logging: Add agent source log field
Browse files Browse the repository at this point in the history
Add a new "source" log field to allow logs coming from the agent to be
distinguished from logs coming direct from the proxy.

Fixes kata-containers#51.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
  • Loading branch information
jodh-intel committed Feb 28, 2018
1 parent cfc47c7 commit 2f913f5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ func unixAddr(uri string) (string, error) {

func logger() *logrus.Entry {
return proxyLog.WithFields(logrus.Fields{
"name": proxyName,
"pid": os.Getpid(),
"name": proxyName,
"pid": os.Getpid(),
"source": "proxy",
})
}

Expand Down Expand Up @@ -168,10 +169,16 @@ func printAgentLogs(sock string) error {
return err
}

// Allow log messages coming from the agent to be distinguished from
// messages originating from the proxy itself.
agentLogger := logger().WithFields(logrus.Fields{
"source": "agent",
})

go func() {
scanner := bufio.NewScanner(conn)
for scanner.Scan() {
logger().Infof("%s\n", scanner.Text())
agentLogger.Infof("%s\n", scanner.Text())
}

if err := scanner.Err(); err != nil {
Expand Down

0 comments on commit 2f913f5

Please sign in to comment.