Skip to content

Commit

Permalink
ws-manager: log JSON as an object instead of a string
Browse files Browse the repository at this point in the history
Signed-off-by: JenTing Hsiao <[email protected]>
  • Loading branch information
jenting authored and roboquat committed Nov 24, 2022
1 parent e363984 commit b0c039f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions components/ws-manager/pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
clog.Info("StartWorkspace")
reqs, _ := protojson.Marshal(req)
safeReqs, _ := log.RedactJSON(reqs)
clog.WithField("req", string(safeReqs)).Debug("StartWorkspace request received")
safeReqsLog := make(map[string]interface{})
_ = json.Unmarshal(safeReqs, &safeReqsLog)
clog.WithFields(safeReqsLog).Debug("StartWorkspace request received")

// Make sure the objects we're about to create do not exist already
switch req.Type {
Expand Down Expand Up @@ -1386,12 +1388,16 @@ func (m *Manager) onChange(ctx context.Context, status *api.WorkspaceStatus) {
if status.Conditions.Failed != "" {
status, _ := protojson.Marshal(status)
safeStatus, _ := log.RedactJSON(status)
clog.WithField("status", string(safeStatus)).Error("workspace failed")
safeStatusLog := make(map[string]interface{})
_ = json.Unmarshal(safeStatus, &safeStatusLog)
clog.WithFields(safeStatusLog).Error("workspace failed")
}
if status.Phase == 0 {
status, _ := protojson.Marshal(status)
safeStatus, _ := log.RedactJSON(status)
clog.WithField("status", string(safeStatus)).Error("workspace in UNKNOWN phase")
safeStatusLog := make(map[string]interface{})
_ = json.Unmarshal(safeStatus, &safeStatusLog)
clog.WithFields(safeStatusLog).Error("workspace in UNKNOWN phase")
}
}

Expand Down

0 comments on commit b0c039f

Please sign in to comment.