Skip to content

Commit

Permalink
refactor: improve logging in gRPC services by removing service prefixes
Browse files Browse the repository at this point in the history
- Updated log messages in NodeServiceServer and TaskServiceServer to remove the "[NodeServiceServer]" and "[TaskServiceServer]" prefixes for cleaner output.
- This change enhances log readability and maintains consistency across logging practices in the application.
  • Loading branch information
tikazyq committed Dec 31, 2024
1 parent 3786ef3 commit 25fe273
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions core/grpc/server/node_service_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (svr NodeServiceServer) Register(_ context.Context, req *grpc.NodeServiceRe
if err != nil {
return HandleError(err)
}
svr.Infof("[NodeServiceServer] updated worker[%s] in db. id: %s", req.NodeKey, node.Id.Hex())
svr.Infof("updated worker[%s] in db. id: %s", req.NodeKey, node.Id.Hex())
} else if errors2.Is(err, mongo.ErrNoDocuments) {
// register new
node = &models.Node{
Expand All @@ -69,13 +69,13 @@ func (svr NodeServiceServer) Register(_ context.Context, req *grpc.NodeServiceRe
if err != nil {
return HandleError(err)
}
svr.Infof("[NodeServiceServer] added worker[%s] in db. id: %s", req.NodeKey, node.Id.Hex())
svr.Infof("added worker[%s] in db. id: %s", req.NodeKey, node.Id.Hex())
} else {
// error
return HandleError(err)
}

svr.Infof("[NodeServiceServer] master registered worker[%s]", req.NodeKey)
svr.Infof("master registered worker[%s]", req.NodeKey)

return HandleSuccessWithData(node)
}
Expand Down Expand Up @@ -113,12 +113,12 @@ func (svr NodeServiceServer) SendHeartbeat(_ context.Context, req *grpc.NodeServ
}

func (svr NodeServiceServer) Subscribe(request *grpc.NodeServiceSubscribeRequest, stream grpc.NodeService_SubscribeServer) (err error) {
svr.Infof("[NodeServiceServer] master received subscribe request from node[%s]", request.NodeKey)
svr.Infof("master received subscribe request from node[%s]", request.NodeKey)

// find in db
node, err := service.NewModelService[models.Node]().GetOne(bson.M{"key": request.NodeKey}, nil)
if err != nil {
svr.Errorf("[NodeServiceServer] error getting node: %v", err)
svr.Errorf("error getting node: %v", err)
return err
}

Expand All @@ -136,7 +136,7 @@ func (svr NodeServiceServer) Subscribe(request *grpc.NodeServiceSubscribeRequest
nodeServiceMutex.Lock()
delete(svr.subs, node.Id)
nodeServiceMutex.Unlock()
svr.Infof("[NodeServiceServer] master unsubscribed from node[%s]", request.NodeKey)
svr.Infof("master unsubscribed from node[%s]", request.NodeKey)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/grpc/server/task_service_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (svr TaskServiceServer) Subscribe(req *grpc.TaskServiceSubscribeRequest, st
taskServiceMutex.Lock()
delete(svr.subs, taskId)
taskServiceMutex.Unlock()
svr.Infof("[TaskServiceServer] task stream closed: %s", taskId.Hex())
svr.Infof("task stream closed: %s", taskId.Hex())

return nil
}
Expand Down

0 comments on commit 25fe273

Please sign in to comment.