日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

使用GetLogs接口查詢(xún)?nèi)罩?/h1>
更新時(shí)間:

完成日志采集后,您可以調(diào)用GetLogs接口查詢(xún)采集到的日志。本文介紹GetLogs接口示例。

前提條件

  • 已完成日志采集。具體操作,請(qǐng)參見(jiàn)日志采集

  • 已創(chuàng)建RAM用戶(hù)并完成授權(quán)。具體操作,請(qǐng)參見(jiàn)創(chuàng)建RAM用戶(hù)并完成授權(quán)

  • 已配置環(huán)境變量ALIBABA_CLOUD_ACCESS_KEY_IDALIBABA_CLOUD_ACCESS_KEY_SECRET。具體操作,請(qǐng)參見(jiàn)在Linux、macOS和Windows系統(tǒng)配置環(huán)境變量

    重要
    • 阿里云賬號(hào)的AccessKey擁有所有API的訪問(wèn)權(quán)限,建議您使用RAM用戶(hù)的AccessKey進(jìn)行API訪問(wèn)或日常運(yùn)維。

    • 強(qiáng)烈建議不要把AccessKey ID和AccessKey Secret保存到工程代碼里,否則可能導(dǎo)致AccessKey泄露,威脅您賬號(hào)下所有資源的安全。

  • 已安裝日志服務(wù)Java SDK。具體操作,請(qǐng)參見(jiàn)安裝Java SDK

  • 已了解GetLogs接口的各參數(shù)說(shuō)明。更多信息,請(qǐng)參見(jiàn)GetLogs - 查詢(xún)?nèi)罩編?kù)日志

  • 該文檔中示例代碼基于aliyun-log-0.6.69版本。若您在調(diào)試中出現(xiàn)沒(méi)有對(duì)應(yīng)方法的報(bào)錯(cuò)(例如無(wú)getLogs方法)或版本沖突問(wèn)題,請(qǐng)升級(jí)到最新版本或更換版本后重試。

注意事項(xiàng)

  • 本示例以華東1(杭州)的公網(wǎng)Endpoint為例,其公網(wǎng)Endpoint為https://cn-hangzhou.log.aliyuncs.com。如果您通過(guò)與Project同地域的其他阿里云產(chǎn)品訪問(wèn)日志服務(wù),請(qǐng)使用內(nèi)網(wǎng)Endpointhttps://cn-hangzhou-intranet.log.aliyuncs.com。關(guān)于日志服務(wù)支持的地域與Endpoint的對(duì)應(yīng)關(guān)系,請(qǐng)參見(jiàn)服務(wù)入口

  • 您可以在SDK代碼的響應(yīng)對(duì)象中調(diào)用IsCompleted()方法,用于判斷本次查詢(xún)是否精確。

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

    • 如果IsCompleted()方法的返回結(jié)果為 false,表示本次查詢(xún)已完成但查詢(xún)不精確,返回的查詢(xún)結(jié)果是不完整的。您需要重復(fù)請(qǐng)求,獲取完整的查詢(xún)結(jié)果。關(guān)于查詢(xún)不精確的更多信息,請(qǐng)參見(jiàn)查詢(xún)不精確可能原因

原始日志樣例

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

查詢(xún)和分析日志示例

您可以參考以下代碼示例,對(duì)日志進(jìn)行查詢(xún)和分析。

重要

在JAVA SDK中調(diào)用GetLogs接口的相關(guān)限制說(shuō)明如下:

  • 當(dāng)設(shè)置query僅為查詢(xún)語(yǔ)句(例如request_method:POST)時(shí),可通過(guò)line參數(shù)控制返回日志的條數(shù),最大值為100。如果您需要返回更多的日志,需使用SQL Limit語(yǔ)法。更多信息,請(qǐng)參見(jiàn)LIMIT子句

  • 當(dāng)設(shè)置query為查詢(xún)和分析語(yǔ)句(request_method:POST | SELECT host, COUNT(*) AS pv GROUP BY host LIMIT 5)時(shí),line參數(shù)無(wú)效,需使用SQL Limit語(yǔ)法控制返回結(jié)果行數(shù)。更多信息,請(qǐng)參見(jiàn)LIMIT子句

關(guān)于查詢(xún)和分析語(yǔ)句的更多信息,請(qǐng)參見(jiàn)基本語(yǔ)法

示例1:使用關(guān)鍵字查詢(xún)?nèi)罩?/h3>

本示例中將展示如何創(chuàng)建一個(gè)GetLogsTest.java文件,并使用關(guān)鍵字path-0/file-5查詢(xún)?nèi)罩尽榭刂品祷厝罩緱l數(shù),設(shè)置line參數(shù)為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.response.GetLogsResponse;

import java.util.Date;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
         // 本示例從環(huán)境變量中獲取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱(chēng)。
        String project = "your-project-name";
        // 設(shè)置日志服務(wù)的服務(wù)接入點(diǎn)。此處以杭州為例,其它地域請(qǐng)根據(jù)實(shí)際情況填寫(xiě)。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱(chēng)。
        String logStore = "your-logstore-name";

        // 創(chuàng)建日志服務(wù)Client。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內(nèi)執(zhí)行查詢(xún)。
        try {
            // 使用關(guān)鍵字path-0/file-5查詢(xún)?nèi)罩尽?            String query = "path-0/file-5";

            int from = (int) (new Date().getTime() / 1000 - 300);
            int to = (int) (new Date().getTime() / 1000);

            // 本示例中,query參數(shù)用于設(shè)置查詢(xún)語(yǔ)句;line參數(shù)用于控制返回日志條數(shù),取值為3,最大值為100。
            GetLogsResponse logsResponse = client.GetLogs(project, logStore, from, to, "", query, 3, 0,true);
            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;
        }
    }
}

返回結(jié)果示例如下:

-------------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:指定特定字段查詢(xún)?nèi)罩?/h3>

本示例中將展示如何創(chuàng)建一個(gè)GetLogsTest.java文件,并查詢(xún)請(qǐng)求方法為POST的日志。為控制返回日志條數(shù),設(shè)置line參數(shù)為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.response.GetLogsResponse;

import java.util.Date;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本示例從環(huán)境變量中獲取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱(chēng)。
        String project = "your-project-name";
        // 設(shè)置日志服務(wù)的服務(wù)接入點(diǎn)。此處以杭州為例,其它地域請(qǐng)根據(jù)實(shí)際情況填寫(xiě)。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱(chēng)。
        String logStore = "your-logstore-name";

        // 創(chuàng)建日志服務(wù)Client。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內(nèi)執(zhí)行SQL分析。
        try {
            // 統(tǒng)計(jì)請(qǐng)求方法為POST的日志。
            String query = "request_method:POST";

            int from = (int) (new Date().getTime() / 1000 - 300);
            int to = (int) (new Date().getTime() / 1000);

            // 本示例中,query參數(shù)用于設(shè)置查詢(xún)語(yǔ)句;line參數(shù)用于控制返回日志條數(shù),取值為3,最大值為100。
            GetLogsResponse logsResponse = client.GetLogs(project, logStore, from, to, "", query, 3, 0,true);
            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;
        }
    }
}

返回結(jié)果示例如下:

-------------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語(yǔ)句分析日志

本示例中將展示如何創(chuàng)建一個(gè)GetLogsTest.java文件,查詢(xún)請(qǐng)求方法為POST的日志,并統(tǒng)計(jì)POST請(qǐng)求的PV數(shù)量。示例如下:

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.response.GetLogsResponse;

import java.util.Date;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本示例從環(huán)境變量中獲取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱(chēng)。
        String project = "your-project-name";
        // 設(shè)置日志服務(wù)的服務(wù)接入點(diǎn)。此處以杭州為例,其它地域請(qǐng)根據(jù)實(shí)際情況填寫(xiě)。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱(chēng)。
        String logStore = "your-logstore-name";

        // 創(chuàng)建日志服務(wù)Client。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內(nèi)執(zhí)行SQL分析。
        try {
            // 查詢(xún)請(qǐng)求方法為POST的日志,并統(tǒng)計(jì)POST請(qǐng)求的PV數(shù)量。
            String query = "request_method:POST|select COUNT(*) as pv";

            int from = (int) (new Date().getTime() / 1000 - 300);
            int to = (int) (new Date().getTime() / 1000);

            // 本示例中,query參數(shù)用于設(shè)置查詢(xún)和分析語(yǔ)句,line參數(shù)無(wú)效,返回條數(shù)以query參數(shù)中的設(shè)置為準(zhǔn),返回1條。
            GetLogsResponse logsResponse = client.GetLogs(project, logStore, from, to, "", query, 3, 0,true);
            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;
        }
    }
}

返回結(jié)果示例如下:

-------------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分組分析日志

本示例中將展示如何創(chuàng)建一個(gè)GetLogsTest.java文件,查詢(xún)請(qǐng)求方法為POST的日志并且按照host進(jìn)行分組。示例如下:

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.response.GetLogsResponse;

import java.util.Date;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本示例從環(huán)境變量中獲取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱(chēng)。
        String project = "your-project-name";
        // 設(shè)置日志服務(wù)的服務(wù)接入點(diǎn)。此處以杭州為例,其它地域請(qǐng)根據(jù)實(shí)際情況填寫(xiě)。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱(chēng)。
        String logStore = "your-logstore-name";

        // 創(chuàng)建日志服務(wù)Client。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內(nèi)執(zhí)行SQL分析。
        try {
            // 統(tǒng)計(jì)請(qǐng)求方法為POST的日志并且按照host進(jìn)行分組。
            // 使用SQL語(yǔ)法中的limit語(yǔ)句限制條數(shù)為5。
            String query = "request_method:POST|select host, COUNT(*) as pv group by host limit 5";

            int from = (int) (new Date().getTime() / 1000 - 300);
            int to = (int) (new Date().getTime() / 1000);

            // 本示例中,query參數(shù)用于設(shè)置查詢(xún)和分析語(yǔ)句,line參數(shù)無(wú)效,返回條數(shù)以query參數(shù)中的設(shè)置為準(zhǔn),返回5條。
            GetLogsResponse logsResponse = client.GetLogs(project, logStore, from, to, "", query, 3, 0,true);
            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;
        }
    }
}

返回結(jié)果示例如下:

-------------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條)

本示例中將展示如何創(chuàng)建一個(gè)GetLogsTest.java文件,查詢(xún)請(qǐng)求方法為POST的日志并且按照host進(jìn)行分組,返回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.response.GetLogsResponse;

import java.util.Date;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本示例從環(huán)境變量中獲取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱(chēng)。
        String project = "your-project-name";
        // 設(shè)置日志服務(wù)的服務(wù)接入點(diǎn)。此處以杭州為例,其它地域請(qǐng)根據(jù)實(shí)際情況填寫(xiě)。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱(chēng)。
        String logStore = "your-logstore-name";

        // 創(chuàng)建日志服務(wù)Client。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內(nèi)執(zhí)行SQL分析。
        try {
            //統(tǒng)計(jì)請(qǐng)求方法為POST的日志并且按照host進(jìn)行分組。
            //使用SQL語(yǔ)法中的limit語(yǔ)句控制返回條數(shù)。
            String old_query = "request_method:POST|select host, COUNT(*) as pv group by host limit ";

            int from = (int) (new Date().getTime() / 1000 - 300);
            int to = (int) (new Date().getTime() / 1000);
            int log_offset = 0;
            int log_line = 200;
            
            String query = old_query + log_offset + "," + log_line;

            // 本示例中,query參數(shù)用于設(shè)置查詢(xún)和分析語(yǔ)句,line參數(shù)無(wú)效,返回條數(shù)以query參數(shù)中的設(shè)置為準(zhǔn)。
            GetLogsResponse logsResponse = client.GetLogs(project, logStore, from, to, "", query, 10, 0 ,true);
            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;
        }
    }
}

返回結(jié)果示例如下:

-------------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統(tǒng)計(jì)過(guò)去一小時(shí)內(nèi)的日志總條數(shù)

本示例中將展示如何創(chuàng)建一個(gè)GetLogsTest.java文件,并使用SQL語(yǔ)句*|select count(*) as count查詢(xún)過(guò)去一小時(shí)內(nèi)的日志總條數(shù)。示例如下:

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.response.GetLogsResponse;

import java.util.Date;

public class GetLogsTest {

    public static void main(String[] args) throws LogException {
        // 本示例從環(huán)境變量中獲取AccessKey ID和AccessKey Secret。
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        // 輸入Project名稱(chēng)。
        String project = "your-project-name";
        // 設(shè)置日志服務(wù)的接入點(diǎn)。此處以杭州為例,其它地域請(qǐng)根據(jù)實(shí)際情況填寫(xiě)。
        String host = "cn-hangzhou.log.aliyuncs.com";
        // 輸入Logstore名稱(chēng)。
        String logStore = "your-logstore-name";

        // 創(chuàng)建日志服務(wù)Client。
        Client client = new Client(host, accessId, accessKey);

        // 在指定的Logstore內(nèi)執(zhí)行SQL分析。
        try {
            // 查詢(xún)?nèi)罩究倵l數(shù)。
            String query = "*|select count(*) as count";
            // 查詢(xún)時(shí)間區(qū)間為1小時(shí)(3600秒)。
            int from = (int) (new Date().getTime() / 1000 - 3600);
            int to = (int) (new Date().getTime() / 1000);
            int log_offset = 0;
            int log_line = 200;

            // 本示例中,query參數(shù)中的SQL語(yǔ)句用于查詢(xún)?cè)摃r(shí)間區(qū)間中日志總條數(shù)。
            GetLogsResponse logsResponse = client.GetLogs(project, logStore, from, to, "", query, log_line, log_offset,true);
            System.out.println("-------------Query is started.-------------");
            System.out.println("from time is :" + from);
            System.out.println("to time is :" + to);
            System.out.println("Returned query result count :" + logsResponse.GetCount());

            for (QueriedLog log : logsResponse.getLogs()) {
                LogItem item = log.GetLogItem();
                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;
        }
    }
}

從返回結(jié)果可以看出,過(guò)去一小時(shí)內(nèi)的日志總條數(shù)為19051條。返回結(jié)果示例如下:

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

相關(guān)文檔

  • 在調(diào)用API接口過(guò)程中,若服務(wù)端返回結(jié)果中包含錯(cuò)誤信息,則表示調(diào)用API接口失敗。您可以參考API錯(cuò)誤碼對(duì)照表查找對(duì)應(yīng)的解決方法。更多信息,請(qǐng)參見(jiàn)API錯(cuò)誤處理對(duì)照表

  • 阿里云OpenAPI開(kāi)發(fā)者門(mén)戶(hù)提供調(diào)試、SDK、示例和配套文檔。通過(guò)OpenAPI,您無(wú)需手動(dòng)封裝請(qǐng)求和簽名操作,就可以快速對(duì)日志服務(wù)API進(jìn)行調(diào)試。更多信息,請(qǐng)參見(jiàn)OpenAPI開(kāi)發(fā)者門(mén)戶(hù)

  • 為滿足越來(lái)越多的自動(dòng)化日志服務(wù)配置需求,日志服務(wù)提供命令行工具CLI(Command Line Interface)。更多信息,請(qǐng)參見(jiàn)日志服務(wù)命令行工具CLI

  • 更多示例代碼,請(qǐng)參見(jiàn)Aliyun Log Java SDK on GitHub