Skip to content

Commit

Permalink
NOISSUE - Format log messages from agent (ultravioletrs#244)
Browse files Browse the repository at this point in the history
* downgrade mod

Signed-off-by: Sammy Oina <[email protected]>

* add fields to logging

Signed-off-by: Sammy Oina <[email protected]>

---------

Signed-off-by: Sammy Oina <[email protected]>
  • Loading branch information
SammyOina authored Sep 19, 2024
1 parent 1546fbc commit 4c09b4b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ultravioletrs/cocos

go 1.23.0
go 1.22.5

require (
github.com/absmach/magistrala v0.14.1-0.20240709113739-04c359462746
Expand Down
22 changes: 21 additions & 1 deletion manager/agentEventsLogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package manager

import (
"fmt"
"log/slog"
"net"
"regexp"
"strconv"
Expand Down Expand Up @@ -65,7 +66,26 @@ func (ms *managerService) handleConnections(conn net.Conn) {
}
ms.eventsChan <- &message

ms.logger.WithGroup("agent-events-logs").Info(message.String())
args := []any{}

switch message.Message.(type) {
case *manager.ClientStreamMessage_AgentEvent:
args = append(args, slog.Group("agent-event",
slog.String("event-type", message.GetAgentEvent().GetEventType()),
slog.String("computation-id", message.GetAgentEvent().GetComputationId()),
slog.String("status", message.GetAgentEvent().GetStatus()),
slog.String("originator", message.GetAgentEvent().GetOriginator()),
slog.String("timestamp", message.GetAgentEvent().GetTimestamp().String()),
slog.String("details", string(message.GetAgentEvent().GetDetails()))))
case *manager.ClientStreamMessage_AgentLog:
args = append(args, slog.Group("agent-log",
slog.String("computation-id", message.GetAgentLog().GetComputationId()),
slog.String("level", message.GetAgentLog().GetLevel()),
slog.String("timestamp", message.GetAgentLog().GetTimestamp().String()),
slog.String("message", message.GetAgentLog().GetMessage())))
}

ms.logger.Info("", args...)
}
}

Expand Down

0 comments on commit 4c09b4b

Please sign in to comment.