If an exception occurs in your application, you can use logs to accurately identify the exception. The log analysis feature allows you to analyze logs that are collected by Log Service or Application Real-Time Monitoring Service (ARMS). This topic describes how to enable the log analysis feature and analyze logs that are collected by Log Service.

Prerequisites

  • The data of your application is imported to ARMS Application Monitoring. For more information, see Overview.
  • Log Service is activated. If Log Service is not activated, log on to the Log Service console and activate Log Service by following the on-screen instructions.
  • A Log Service project is created. For more information, see Create a project.
  • A Log Service Logstore is created. For more information, see Create a Logstore.

Log sources

The log analysis feature supports logs that are collected by Log Service or ARMS. This topic describes how to query and analyze logs that are collected by Log Service. For more information about how to analyze logs that are collected by ARMS, see Analyze logs collected by ARMS.

  • Analyze logs collected by ARMS: You can use the ARMS agent to collect the output of the log framework and push the collected logs to the log analysis center of ARMS. After you enable the log analysis feature, you can query and analyze the logs of your application in the ARMS console without the need to perform other operations.
    Note If you analyze logs collected by ARMS, you must upgrade the ARMS agent to V2.7.1.4 or later.
  • Analyze logs collected by Log Service:

    You must make sure that the logs of your application are collected to Log Service. Then, you must specify the project and Logstore that store the logs on the Application Settings page of the ARMS console. To help you analyze logs, the console pages of Log Service are embedded in ARMS.

Step 1: Associate logs with trace IDs

  1. Log on to the ARMS console. In the left-side navigation pane, choose Application Monitoring > Applications.
  2. On the Applications page, select a region in the top navigation bar and click the name of the application that you want to manage.
    Note If the Java icon icon is displayed in the Language column, the application is connected to Application Monitoring. If a hyphen (-) is displayed, the application is connected to Tracing Analysis.
  3. In the left-side navigation pane, click Application Settings. On the page that appears, click the Custom Configuration tab.
  4. In the Business log Association settings section of the Custom Configuration tab, set the log source to Log Service, turn on Link Business Logs with TraceId, select the region where Log Service resources are deployed, and then select the project and Logstore that you created.
    Link Business Logs with TraceId
  5. On the Custom Configuration tab, click Save in the lower-left corner.

Step 2: Query and analyze logs

  1. Log on to the ARMS console. In the left-side navigation pane, choose Application Monitoring > Applications.
  2. On the Applications page, select a region in the top navigation bar and click the name of the application that you want to manage.
    Note If the Java icon icon is displayed in the Language column, the application is connected to Application Monitoring. If a hyphen (-) is displayed, the application is connected to Tracing Analysis.
  3. In the left-side navigation pane, choose Application Diagnosis > Log Analysis.
  4. On the Log Analysis page, perform the following operations:
    1. Enter a query statement in the search box.
      A query statement consists of a search statement and an analytic statement in the Search statement|Analytic statement format. For more information, see Search syntax and SQL syntax and functions.
    2. Specify the time range for query and analysis.
      You can set a custom time range by specifying the start time and end time. The start time and end time can be in hours or accurate to seconds. You can also set a time length without specifying the start time or end time.
      Note The query results may contain logs that are generated 1 minute earlier than the specified start time or 1 minute later than the specified end time.
    3. Click Search & Analyze to view the query and analysis results.
    Log analysis