Enable logging

Updated at:

This topic describes how to enable logging to push operational logs from Message Service (MNS) to Log Service (SLS).

Prerequisites

  • Create a Log Service (SLS) project and a Logstore. For more information, see Manage projects and Create a basic Logstore.

    Message Service (MNS) can push operational logs only to a Log Service (SLS) project in the same region.

  • Authorize Message Service (MNS) to use the AliyunMNSLoggingRole RAM role to export logs.

    Click Cloud Resource Access Authorization and follow the on-screen instructions to complete the authorization.

    Warning

    Do not revoke the authorization or delete the RAM role. Otherwise, Message Service (MNS) cannot push logs to Log Service (SLS).

  • If you use a RAM user to enable logging, grant the required permissions to the user. For more information, see RAM user authorization.

Configure log delivery

Important

If you use a RAM user to enable logging, grant the required permissions to the user. For more information, see RAM user authorization.

  1. Log on to the Message Service (MNS) console.

  2. In the left-side navigation pane, click log management.

  3. In the top navigation bar, select a region.

  4. On the log management page, click Log Service (SLS).

  5. Select a project and a Logstore, and then click Enable.

    Note

    It takes about 3 minutes for Message Service (MNS) to push logs to the specified Logstore.

Enable logging for queues and topics

Enable logging for a queue

  1. Log on to the Message Service (MNS) console.

  2. In the left-side navigation pane, click queue list.

  3. In the top navigation bar, select a region.

  4. On the queue list page, find the target queue. In the Actions column, choose More > Edit.

  5. In the Edit Queue Parameters panel, set Enable Logging to Yes.

    On the queue list page, the Logging column for the target queue displays Enabled.

Enable logging for a topic

  1. Log on to the Message Service (MNS) console.

  2. In the left-side navigation pane, click topic list.

  3. In the top navigation bar, select a region.

  4. On the topic list page, find the target topic. In the Actions column, click Edit.

  5. In the Edit Topic Parameters panel, set Enable Logging to Yes.

    On the topic list page, the Logging column for the target topic displays Enabled.

View logs

  1. Log on to the Simple Log Service console.

  2. In the Projects section, click the one you want.

    image

  3. On the Log Storage > Logstores tab, click the logstore you want.

    image

  4. Enter a query statement, and then click Last 15 Minutes to set the query time range. For more information, see Query and analysis quick start.

    • To query the trace of a message in a queue, use the format $QueueName and $MessageId. For example: log and EED287A265726135146E6A9CADC8XXXX.

      The result shows the message lifecycle from sending to receiving.

      image

    • To query the trace of a message in a topic, use the format $TopicName and $MessageId. For example: logtest and 8798453B65727FC6433E6AB4F746XXXX.

      The result shows the message lifecycle from publication to delivery.

      image

    • To query the number of messages sent to a queue, use the format $QueueName and (SendMessage or BatchSendMessage). For example: log and (SendMessage or BatchSendMessage).

      The result shows that the producer sent three messages to the log queue within the specified time range.查看队列消息写入量

    • To query the number of messages published to a topic, use the format $TopicName and PublishMessage. For example: logtest and PublishMessage.

      The result shows that the producer sent three messages to the logtest topic within the specified time range.查看主题消息发布量

    • To query the number of messages consumed from a queue, use the format $QueueName and (ReceiveMessage or BatchReceiveMessage). For example: log and (ReceiveMessage or BatchReceiveMessage).

      The result shows that 12 messages were consumed from the log queue within the specified time range.查看队列消息消费量

    • To query the number of messages deleted from a queue, use the format $QueueName and (DeleteMessage or BatchDeleteMessage). For example: log and (DeleteMessage or BatchDeleteMessage).

      The result shows that 61 messages were deleted from the log queue within the specified time range.查看队列消息删除量

    • In this example, to query the message processing volume for a specific client, enter the client IP address. The format of the query statement is $ClientIP. For example, 10.10.10.0.

      To query logs for specific operations performed by a client, combine multiple keywords. For example: $ClientIP and (SendMessage or BatchSendMessage).

      The result shows that the client processed 66 messages within the specified time range.查看某个客户端消息处理量