Log Service provides the SDK in various languages, such as Java, Python, and Go. You can use the SDK to call Log Service API operations to consume logs.

Use the SDK to consume logs

The following example shows how to use the Java SDK to consume log data in a shard named ShardId. For more information about the Java SDK, visit Java SDK. For more information about the Log Service SDK, see SDK Reference.
Client client = new Client(host, accessId, accessKey);

    String cursor = client.GetCursor(project, logStore, shardId, CursorMode.END).GetCursor();
    System.out.println("cursor = " +cursor);
    try {
      while (true) {
        PullLogsRequest request = new PullLogsRequest(project, logStore, shardId, 1000, cursor);
        PullLogsResponse response = client.pullLogs(request);
        System.out.println(response.getCount());
        System.out.println("cursor = " + cursor + " next_cursor = " + response.getNextCursor());
        if (cursor.equals(response.getNextCursor())) {
            break;
                }
        cursor = response.getNextCursor();
        Thread.sleep(200);
      }
    }
    catch(LogException e) {
      System.out.println(e.GetRequestId() + e.GetErrorMessage());
    }

Preview logs in the Log Service console

Log preview also consumes logs. To preview logs stored in a Logstore in the Log Service console, follow these steps:
  1. Log on to the Log Service console, and then click the target project name.
  2. In the Logstore list, find the Logstore, click the Log preview icon next to the Logstore, and then select Consumption Preview.
  3. In the Consumption Preview dialog box, select a shard and a time range, and then click Preview.
    The log preview page displays the log data of the first 10 packets in the specified time range.