Skip to content

Commit

Permalink
env and log
Browse files Browse the repository at this point in the history
  • Loading branch information
XFFFCCCC committed Aug 21, 2023
1 parent 0750287 commit 7c6187a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/constant/config/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Configure Consul address, the default address is `localhost:8500`
# TIPS: If you provide `CONSUL_ANONYMITY_NAME`, all services will register with `CONSUL_ANONYMITY_NAME` as prefix
CONSUL_ADDR=localhost:8500
CONSUL_ANONYMITY_NAME=
CONSUL_ANONYMITY_NAME=paraparty.
# Configure logger level, support: DEBUG, INFO, WARN (WARNING), ERROR, FATAL
LOGGER_LEVEL=INFO
# Cofigure logger integrated with otel, support: enable, disable
Expand Down
10 changes: 5 additions & 5 deletions src/services/message/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c MessageServiceImpl) ChatAction(ctx context.Context, request *chat.Action
logger := logging.LogService("ChatService.ActionMessage").WithContext(ctx)

logger.WithFields(logrus.Fields{
"actor_id": request.ActorId,
"ActorId": request.ActorId,
"user_id": request.UserId,
"action_type": request.ActionType,
"content_text": request.Content,
Expand All @@ -61,8 +61,8 @@ func (c MessageServiceImpl) ChatAction(ctx context.Context, request *chat.Action
res, err = addMessage(ctx, logger, span, request.ActorId, request.UserId, request.Content)
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
"Actor_id": request.ActorId,
"err": err,
"ActorId": request.ActorId,
}).Errorf("User service error")
logging.SetSpanError(span, err)
return res, err
Expand All @@ -82,7 +82,7 @@ func (c MessageServiceImpl) Chat(ctx context.Context, request *chat.ChatRequest)
logger := logging.LogService("ChatService.chat").WithContext(ctx)
logger.WithFields(logrus.Fields{
"user_id": request.UserId,
"from_id": request.ActorId,
"ActorId": request.ActorId,
}).Debugf("Process start")
toUserId := request.UserId
fromUserId := request.ActorId
Expand Down Expand Up @@ -146,7 +146,7 @@ func addMessage(ctx context.Context, logger *logrus.Entry, span trace.Span, from
logger.WithFields(logrus.Fields{
"err": result.Error,
"id": message.ID,
"from_id": message.FromUserId,
"ActorId": message.FromUserId,
"to_id": message.ToUserId,
}).Errorf("send message failed when insert to database")

Expand Down
18 changes: 9 additions & 9 deletions src/web/message/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ActionMessageHandler(c *gin.Context) {
if err := c.ShouldBindQuery(&req); err != nil {
logger.WithFields(logrus.Fields{
//"CreateTime": req.Create_time,
"user_id": req.ActorId,
"ActorId": req.ActorId,
"from_id": req.UserId,
"err": err,
}).Errorf("Error when trying to bind query")
Expand All @@ -55,16 +55,16 @@ func ActionMessageHandler(c *gin.Context) {

if err != nil {
logger.WithFields(logrus.Fields{
"actor_id": req.ActorId,
"content": req.Content,
"ActorId": req.ActorId,
"content": req.Content,
}).Error("Error when trying to connect with ActionMessageHandler")

c.JSON(http.StatusBadRequest, res)
return
}
logger.WithFields(logrus.Fields{
"actor_id": req.ActorId,
"content": req.Content,
"ActorId": req.ActorId,
"content": req.Content,
}).Infof("Action send message success")

c.JSON(http.StatusOK, res)
Expand Down Expand Up @@ -92,16 +92,16 @@ func ListMessageHandler(c *gin.Context) {

if err != nil {
logger.WithFields(logrus.Fields{
"actor_id": req.ActorId,
"user_id": req.UserId,
"ActorId": req.ActorId,
"user_id": req.UserId,
}).Error("Error when trying to connect with ListMessageHandler")
c.JSON(http.StatusOK, res)
return
}

logger.WithFields(logrus.Fields{
"actor_id": req.ActorId,
"user_id": req.UserId,
"ActorId": req.ActorId,
"user_id": req.UserId,
}).Infof("List comment success")

c.JSON(http.StatusOK, res)
Expand Down

0 comments on commit 7c6187a

Please sign in to comment.