全部產品
Search
文件中心

Simple Log Service:使用GetLogs介面查詢日誌

更新時間:Aug 08, 2025

完成日誌採集後,您可以調用GetLogs介面查詢採集到的日誌。本文介紹GetLogs介面樣本。

前提條件

您已完成以下操作:

注意事項

  • 本樣本以華東1(杭州)的公網Endpoint為例,其公網Endpoint為https://cn-hangzhou.log.aliyuncs.com

    如果您通過與Project同地區的其他阿里雲產品訪問Log Service,請使用內網Endpointhttps://cn-hangzhou-intranet.log.aliyuncs.com

    關於Log Service支援的地區與Endpoint的對應關係,請參見服務入口

  • 您可以在SDK代碼的響應對象中調用IsCompleted()方法,用於判斷本次查詢是否精確。

    • 如果IsCompleted()方法的返回結果為true,表示本次查詢已完成且查詢精確,返回的查詢結果是完整的。

    • 如果IsCompleted()方法的返回結果為 false,表示本次查詢已完成但查詢不精確,返回的查詢結果是不完整的。您需要重複請求,擷取完整的查詢結果。關於查詢不精確的更多資訊,請參見查詢不精確可能原因

參數說明

請求參數

名稱

類型

是否必填

說明

project

String

Project名稱:專案(Project)是Log Service的資源嵌入式管理單元,是進行多使用者隔離與存取控制的主要邊界。更多資訊,請參見管理Project

logstore

String

Logstore名稱:Logstore是Log Service中日誌資料的採集、儲存和查詢單元。更多資訊,請參見管理Logstore

from

int

查詢開始的時間點,使用Unix時間戳記格式。

說明
  • 該時間為日誌到達Logstore的時間。更多資訊,請參見保留欄位__tag__:__receive_time__

  • 開始時間點和結束時間點定義的時間區間。遵循左閉右開原則,即該時間區間包括區間開始時間點,但不包括區間結束時間點。如果開始時間點和結束時間點相同,則為無效區間,函數直接返回錯誤。

  • 如果您要確保不漏查資料,請將查詢時間對齊到分鐘層級。如果您在分析語句中設定了時間範圍,則查詢分析時以該時間範圍為準。

  • 如果您需要在分析語句中指定時間範圍並精確到秒時,可使用日期和時間函數或日期和時間函數轉換下時間格式。例如:

    • * | SELECT * FROM log WHERE from_unixtime(__time__) > from_unixtime(1664186624) AND from_unixtime(__time__) < now()

    • * | SELECT * FROM log WHERE __time__ > to_unixtime(date_parse('2022-10-19 15:46:05', '%Y-%m-%d %H:%i:%s')) AND __time__ < to_unixtime(now())

to

int

查詢結束的時間點,使用Unix時間戳記格式。

說明
  • 該時間為日誌到達Logstore的時間。更多資訊,請參見保留欄位__tag__:__receive_time__

  • 開始時間點和結束時間點定義的時間區間。遵循左閉右開原則,即該時間區間包括區間開始時間點,但不包括區間結束時間點。如果開始時間點和結束時間點相同,則為無效區間,函數直接返回錯誤。

  • 如果您要確保不漏查資料,請將查詢時間對齊到分鐘層級。如果您在分析語句中設定了時間範圍,則查詢分析時以該時間範圍為準。

  • 如果您需要在分析語句中指定時間範圍並精確到秒時,可使用日期和時間函數或日期和時間函數轉換下時間格式。例如:

    • * | SELECT * FROM log WHERE from_unixtime(__time__) > from_unixtime(1664186624) AND from_unixtime(__time__) < now()

    • * | SELECT * FROM log WHERE __time__ > to_unixtime(date_parse('2022-10-19 15:46:05', '%Y-%m-%d %H:%i:%s')) AND __time__ < to_unixtime(now())

topic

String

日誌主題。預設值為空白字串。更多資訊,請參見日誌主題(Topic)

query

String

查詢語句或分析語句。更多資訊,請參見查詢與分析概述。 在query參數的分析語句中加上set session parallel_sql=true;,表示使用 SQL 獨享版。例如* | set session parallel_sql=true; select count(*) as pv。常見查詢與分析問題,請參見查詢與分析日誌的常見報錯

說明

query參數中有分析語句(SQL 陳述式)時,該介面的line參數和offset參數無效。建議設定該介面的參數為0,需通過SQL語句的LIMIT文法實現翻頁。更多資訊,請參見分頁顯示查詢分析結果

line

int

僅當query參數為查詢語句時,該參數有效。表示請求返回的最大日誌條數,最小值為 0,最大值為 100,預設值為 100。

offset

int

僅當query參數為查詢語句時,該參數有效。表示查詢開始行。預設值為 0。

reverse

boolean

用於指定返回結果是否按日誌時間戳記降序返回日誌,精確到分鐘層級。

  • true:按照日誌時間戳記降序返回日誌。

  • false(預設值):按照日誌時間戳記升序返回日誌。

重要
  • query參數為查詢語句時,參數reverse有效,用於指定返回日誌排序方式。

  • query參數為查詢和分析語句時,參數reverse無效,由SQL分析語句中order by指定排序方式。

powerSql

boolean

是否使用SQL獨享版。更多資訊,請參見高效能完全精確查詢與分析(SQL獨享版)

  • true:使用SQL獨享版。

  • false(預設值):使用SQL普通版。

除通過powerSql參數配置SQL獨享版外,您還可以使用query參數。

scan

boolean

如果scan設定為true,則查詢將使用掃描模式。

forward

boolean

僅對於掃描查詢,如果forward設定為true,查詢將擷取下一頁,否則擷取上一頁。

返回參數

返回參數請參見:GetLogs - 查詢日誌庫日誌

原始日誌範例

body_bytes_sent:1750
host:www.example.com
http_referer:www.example.com
http_user_agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; it-it) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
http_x_forwarded_for:203.0.XX.XX
remote_addr:203.0.XX.XX
remote_user:p288
request_length:13741
request_method:GET
request_time:71
request_uri:/request/path-1/file-1
http_code:200
time_local:11/Aug/2021:06:52:27
upstream_response_time:0.66

查詢和分析日誌樣本

您可以參考以下程式碼範例,對日誌進行查詢和分析。

重要

在JAVA SDK中調用GetLogs介面的相關限制說明如下:

  • 當設定query僅為查詢語句(例如request_method:POST)時,可通過line參數控制返回日誌的條數,最大值為100。如果您需要返回更多的日誌,需使用SQL Limit文法。更多資訊,請參見LIMIT子句

  • 當設定query為查詢和分析語句(request_method:POST | SELECT host, COUNT(*) AS pv GROUP BY host LIMIT 5)時,line參數無效,需使用SQL Limit文法控制返回結果行數。更多資訊,請參見LIMIT子句

關於查詢和分析語句的更多資訊,請參見基本文法

樣本1:使用關鍵字查詢日誌

本樣本中將展示如何建立一個GetLogsTest.java檔案,並使用關鍵字path-0/file-5查詢日誌。為控制返回日誌條數,設定line參數為3。樣本如下:

import com.aliyun.openservices.log.Client;
import com.aliyun.openservices.log.common.LogItem;
import com.aliyun.openservices.log.common.QueriedLog;
import com.aliyun.openservices.log.exception.LogException;
import com.aliyun.openservices.log.request.GetLogsRequest;
import com.aliyun.openservices.log.response.GetLogsResponse;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本樣本從環境變數中擷取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱。
        String project = "your-project-name";
        // 設定Log Service的服務存取點。此處以杭州為例,其它地區請根據實際情況填寫。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱。
        String logStore = "your-logstore-name";

        // 建立Log ServiceClient。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內執行查詢。
        try {
            // 使用關鍵字path-0/file-5查詢日誌。
            String query = "path-0/file-5";

            int from = 1754449503;
            int to = 1754449510;

            // 本樣本中,query參數用於設定查詢語句;line參數用於控制返回日誌條數,取值為3,最大值為100。
            GetLogsRequest request = new GetLogsRequest(project, logStore, from, to, "", query);
            GetLogsResponse logsResponse = client.GetLogs(request);
            System.out.println("-------------Query is started.-------------");
            System.out.println("Returned query result count :" + logsResponse.GetCount());
            System.out.println("from time is :" + from);
            System.out.println("to time is :" + to);
            for (QueriedLog log : logsResponse.getLogs()) {
                LogItem item = log.GetLogItem();
                System.out.println("log time : " + item.mLogTime);
                System.out.println("Jsonstring : " + item.ToJsonString());
            }
            System.out.println("-------------Query is finished.-------------");

        } catch (LogException e) {
            System.out.println("LogException e :" + e.toString());
            System.out.println("error code :" + e.GetErrorCode());
            System.out.println("error message :" + e.GetErrorMessage());
            throw e;
        }
    }
}

返回結果樣本如下:

-------------Query is started.-------------
Returned query result count :3
from time is :1644573549
to time is :1644573849
log time : 1644573808
Jsonstring : {"remote_addr":"203.0.XX.XX","__topic__":"nginx_access_log","request_uri":"/request/path-0/file-5"...}
log time : 1644573808
Jsonstring : {"remote_addr":"203.0.XX.XX","__topic__":"nginx_access_log","request_uri":"/request/path-0/file-5"...}
log time : 1644573788
Jsonstring : {"remote_addr":"203.0.XX.XX","__topic__":"nginx_access_log","request_uri":"/request/path-0/file-5"...}
-------------Query is finished.-------------

Process finished with exit code 0

樣本2:指定特定欄位查詢日誌

本樣本中將展示如何建立一個GetLogsTest.java檔案,並查詢要求方法為POST的日誌。為控制返回日誌條數,設定line參數為3。樣本如下:

import com.aliyun.openservices.log.Client;
import com.aliyun.openservices.log.common.LogItem;
import com.aliyun.openservices.log.common.QueriedLog;
import com.aliyun.openservices.log.exception.LogException;
import com.aliyun.openservices.log.request.GetLogsRequest;
import com.aliyun.openservices.log.response.GetLogsResponse;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本樣本從環境變數中擷取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱。
        String project = "your-project-name";
        // 設定Log Service的服務存取點。此處以杭州為例,其它地區請根據實際情況填寫。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱。
        String logStore = "your-logstore-name";

        // 建立Log ServiceClient。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內執行查詢。
        try {
            // 統計要求方法為POST的日誌。
            String query = "request_method:POST";
            // 設定查詢語句執行時間範圍。
            int from = 1754449503;
            int to = 1754449510;

            // 本樣本中,query參數用於設定查詢語句;line參數用於控制返回日誌條數,取值為3,最大值為100。
            GetLogsRequest request = new GetLogsRequest(project, logStore, from, to, "", query);
            GetLogsResponse logsResponse = client.GetLogs(request);
            System.out.println("-------------Query is started.-------------");
            System.out.println("Returned query result count :" + logsResponse.GetCount());
            System.out.println("from time is :" + from);
            System.out.println("to time is :" + to);
            for (QueriedLog log : logsResponse.getLogs()) {
                LogItem item = log.GetLogItem();
                System.out.println("log time : " + item.mLogTime);
                System.out.println("Jsonstring : " + item.ToJsonString());
            }
            System.out.println("-------------Query is finished.-------------");

        } catch (LogException e) {
            System.out.println("LogException e :" + e.toString());
            System.out.println("error code :" + e.GetErrorCode());
            System.out.println("error message :" + e.GetErrorMessage());
            throw e;
        }
    }
}

返回結果樣本如下:

-------------Query is started.-------------
Returned query result count :3
from time is :1644574151
to time is :1644574451
log time : 1644574438
Jsonstring : {"remote_addr":"203.0.XX.XX","__topic__":"nginx_access_log","body_bytes_sent":"3604","request_method":"POST"...}
log time : 1644574438
Jsonstring : {"remote_addr":"203.0.XX.XX","__topic__":"nginx_access_log","body_bytes_sent":"3369","request_method":"POST"...}
log time : 1644574438
Jsonstring : {"remote_addr":"203.0.XX.XX","__topic__":"nginx_access_log","body_bytes_sent":"12714","request_method":"POST"...}
-------------Query is finished.-------------

Process finished with exit code 0

樣本3:使用SQL語句分析日誌

本樣本中將展示如何建立一個GetLogsTest.java檔案,查詢要求方法為POST的日誌,並統計POST請求的PV數量。樣本如下:

import com.aliyun.openservices.log.Client;
import com.aliyun.openservices.log.common.LogItem;
import com.aliyun.openservices.log.common.QueriedLog;
import com.aliyun.openservices.log.exception.LogException;
import com.aliyun.openservices.log.request.GetLogsRequest;
import com.aliyun.openservices.log.response.GetLogsResponse;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本樣本從環境變數中擷取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱。
        String project = "your-project-name";
        // 設定Log Service的服務存取點。此處以杭州為例,其它地區請根據實際情況填寫。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱。
        String logStore = "your-logstore-name";

        // 建立Log ServiceClient。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內執行查詢。
        try {
            // 查詢要求方法為POST的日誌,並統計POST請求的PV數量。
            String query = "request_method:POST|select COUNT(*) as pv";
            // 設定查詢語句執行時間範圍。
            int from = 1754449503;
            int to = 1754449510;

            // 本樣本中,query參數用於設定查詢語句;line參數用於控制返回日誌條數,取值為3,最大值為100。
            GetLogsRequest request = new GetLogsRequest(project, logStore, from, to, "", query);
            GetLogsResponse logsResponse = client.GetLogs(request);
            System.out.println("-------------Query is started.-------------");
            System.out.println("Returned query result count :" + logsResponse.GetCount());
            System.out.println("from time is :" + from);
            System.out.println("to time is :" + to);
            for (QueriedLog log : logsResponse.getLogs()) {
                LogItem item = log.GetLogItem();
                System.out.println("log time : " + item.mLogTime);
                System.out.println("Jsonstring : " + item.ToJsonString());
            }
            System.out.println("-------------Query is finished.-------------");

        } catch (LogException e) {
            System.out.println("LogException e :" + e.toString());
            System.out.println("error code :" + e.GetErrorCode());
            System.out.println("error message :" + e.GetErrorMessage());
            throw e;
        }
    }
}

返回結果樣本如下:

-------------Query is started.-------------
Returned query result count :1
from time is :1644574354
to time is :1644574654
log time : 1644574354
Jsonstring : {"pv":"162","logtime":1644574354}
-------------Query is finished.-------------

Process finished with exit code 0

樣本4:使用SQL分組分析日誌

本樣本中將展示如何建立一個GetLogsTest.java檔案,查詢要求方法為POST的日誌並且按照host進行分組。樣本如下:

import com.aliyun.openservices.log.Client;
import com.aliyun.openservices.log.common.LogItem;
import com.aliyun.openservices.log.common.QueriedLog;
import com.aliyun.openservices.log.exception.LogException;
import com.aliyun.openservices.log.request.GetLogsRequest;
import com.aliyun.openservices.log.response.GetLogsResponse;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本樣本從環境變數中擷取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱。
        String project = "your-project-name";
        // 設定Log Service的服務存取點。此處以杭州為例,其它地區請根據實際情況填寫。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱。
        String logStore = "your-logstore-name";

        // 建立Log ServiceClient。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內執行查詢。
        try {
            // 統計要求方法為POST的日誌並且按照host進行分組。
            // 使用SQL文法中的limit語句限制條數為5。
            String query = "request_method:POST|select host, COUNT(*) as pv group by host limit 5";
            // 設定查詢語句執行時間範圍。
            int from = 1754449503;
            int to = 1754449510;

            // 本樣本中,query參數用於設定查詢語句;line參數用於控制返回日誌條數,取值為3,最大值為100。
            GetLogsRequest request = new GetLogsRequest(project, logStore, from, to, "", query);
            GetLogsResponse logsResponse = client.GetLogs(request);
            System.out.println("-------------Query is started.-------------");
            System.out.println("Returned query result count :" + logsResponse.GetCount());
            System.out.println("from time is :" + from);
            System.out.println("to time is :" + to);
            for (QueriedLog log : logsResponse.getLogs()) {
                LogItem item = log.GetLogItem();
                System.out.println("log time : " + item.mLogTime);
                System.out.println("Jsonstring : " + item.ToJsonString());
            }
            System.out.println("-------------Query is finished.-------------");

        } catch (LogException e) {
            System.out.println("LogException e :" + e.toString());
            System.out.println("error code :" + e.GetErrorCode());
            System.out.println("error message :" + e.GetErrorMessage());
            throw e;
        }
    }
}

返回結果樣本如下:

-------------Query is started.-------------
Returned query result count :5
from time is :1644574445
to time is :1644574745
log time : 1644574445
Jsonstring : {"pv":"1","host":"www.example1.com","logtime":1644574445}
log time : 1644574445
Jsonstring : {"pv":"1","host":"www.example.org","logtime":1644574445}
log time : 1644574445
Jsonstring : {"pv":"1","host":"www.example.net","logtime":1644574445}
log time : 1644574445
Jsonstring : {"pv":"1","host":"www.example.edu","logtime":1644574445}
log time : 1644574445
Jsonstring : {"pv":"1","host":"www.aliyundoc.com","logtime":1644574445}
-------------Query is finished.-------------

Process finished with exit code 0

樣本5:使用SQL分組分析日誌(返回200條)

本樣本中將展示如何建立一個GetLogsTest.java檔案,查詢要求方法為POST的日誌並且按照host進行分組,返回200條日誌。樣本如下:

import com.aliyun.openservices.log.Client;
import com.aliyun.openservices.log.common.LogItem;
import com.aliyun.openservices.log.common.QueriedLog;
import com.aliyun.openservices.log.exception.LogException;
import com.aliyun.openservices.log.request.GetLogsRequest;
import com.aliyun.openservices.log.response.GetLogsResponse;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本樣本從環境變數中擷取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱。
        String project = "your-project-name";
        // 設定Log Service的服務存取點。此處以杭州為例,其它地區請根據實際情況填寫。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱。
        String logStore = "your-logstore-name";

        // 建立Log ServiceClient。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內執行查詢。
        try {
            //統計要求方法為POST的日誌並且按照host進行分組。
            //使用SQL文法中的limit語句控制返回條數。
            String old_query = "request_method:POST|select host, COUNT(*) as pv group by host limit 0,200";
            // 設定查詢語句執行時間範圍。
            int from = 1754449503;
            int to = 1754449510;

            // 本樣本中,query參數用於設定查詢語句;line參數用於控制返回日誌條數,取值為3,最大值為100。
            GetLogsRequest request = new GetLogsRequest(project, logStore, from, to, "", query);
            GetLogsResponse logsResponse = client.GetLogs(request);
            System.out.println("-------------Query is started.-------------");
            System.out.println("Returned query result count :" + logsResponse.GetCount());
            System.out.println("from time is :" + from);
            System.out.println("to time is :" + to);
            for (QueriedLog log : logsResponse.getLogs()) {
                LogItem item = log.GetLogItem();
                System.out.println("log time : " + item.mLogTime);
                System.out.println("Jsonstring : " + item.ToJsonString());
            }
            System.out.println("-------------Query is finished.-------------");

        } catch (LogException e) {
            System.out.println("LogException e :" + e.toString());
            System.out.println("error code :" + e.GetErrorCode());
            System.out.println("error message :" + e.GetErrorMessage());
            throw e;
        }
    }
}

返回結果樣本如下:

-------------Query is started.-------------
Returned query result count :200
from time is :1644574445
to time is :1644574745
log time : 1644574445
Jsonstring : {"pv":"1","host":"www.example1.com","logtime":1644574445}
log time : 1644574445
Jsonstring : {"pv":"1","host":"www.example.org","logtime":1644574445}
log time : 1644574445
Jsonstring : {"pv":"1","host":"www.example.net","logtime":1644574445}
log time : 1644574445
Jsonstring : {"pv":"1","host":"www.example.edu","logtime":1644574445}
log time : 1644574445
Jsonstring : {"pv":"1","host":"www.aliyundoc.com","logtime":1644574445}
......
-------------Query is finished.-------------

Process finished with exit code 0

樣本6:使用SQL統計過去一小時內的日誌總條數

本樣本中將展示如何建立一個GetLogsTest.java檔案,並使用SQL語句*|select count(*) as count查詢過去一小時內的日誌總條數。樣本如下:

import com.aliyun.openservices.log.Client;
import com.aliyun.openservices.log.common.LogItem;
import com.aliyun.openservices.log.common.QueriedLog;
import com.aliyun.openservices.log.exception.LogException;
import com.aliyun.openservices.log.request.GetLogsRequest;
import com.aliyun.openservices.log.response.GetLogsResponse;

import java.util.Date;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本樣本從環境變數中擷取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱。
        String project = "your-project-name";
        // 設定Log Service的服務存取點。此處以杭州為例,其它地區請根據實際情況填寫。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱。
        String logStore = "your-logstore-name";

        // 建立Log ServiceClient。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內執行查詢。
        try {
            // 查詢日誌總條數。
            String query = "*|select count(*) as count";
            // 查詢時間區間為1小時(3600秒)。
            int from = (int) (new Date().getTime() / 1000 - 3600);
            int to = (int) (new Date().getTime() / 1000);
            int offset = 0;
            int line = 200;
            // 本樣本中,query參數用於設定查詢語句;line參數用於控制返回日誌條數,取值為3,最大值為100。
            GetLogsRequest request = new GetLogsRequest(project, logStore, from, to, "", query,line,offset,true);
            GetLogsResponse logsResponse = client.GetLogs(request);
            System.out.println("-------------Query is started.-------------");
            System.out.println("Returned query result count :" + logsResponse.GetCount());
            System.out.println("from time is :" + from);
            System.out.println("to time is :" + to);
            for (QueriedLog log : logsResponse.getLogs()) {
                LogItem item = log.GetLogItem();
                System.out.println("log time : " + item.mLogTime);
                System.out.println("Jsonstring : " + item.ToJsonString());
            }
            System.out.println("-------------Query is finished.-------------");

        } catch (LogException e) {
            System.out.println("LogException e :" + e.toString());
            System.out.println("error code :" + e.GetErrorCode());
            System.out.println("error message :" + e.GetErrorMessage());
            throw e;
        }
    }
}

從返回結果可以看出,過去一小時內的日誌總條數為19051條。返回結果樣本如下:

from time is :1675041679
to time is :1675045279
Returned sql result count :1
Jsonstring : {"count":"19051","logtime":1675041679}
-------------Query is finished.-------------

相關文檔