gpt4 book ai didi

android - 从 Android 客户端向相扑逻辑记录消息

转载 作者:行者123 更新时间:2023-11-29 16:43:54 24 4
gpt4 key购买 nike

我需要记录来自 Android 客户端的消息。是否有任何相扑逻辑 API 来记录来自 Android 应用程序的消息?

最佳答案

您可以将您的日志消息/来自您的 Android 应用程序的任何消息发布到 Summo Logic 基于云的日志管理。

Summo Logic 提供 Web 服务/REST 来执行 POST、GET 请求。

You just need to post your data on the request body and mention your Sumo collection endpoint as well as UniqueHTTPCollectorCode.

REST 服务/网络服务:https://[SumoEndpoint]/receiver/v1/http/[UniqueHTTPCollectorCode]

例如:“https://endpoint1.collection.us2.sumologic.com/receiver/v1/http/SanTC12dhaV1oma90Vvb..。”

您可以使用 Retorfit/Volley 库进行 REST 通信。

我给出了下面的伪代码,它通过 Android 异步任务在后台传达了基本的 REST 通信。

我强烈推荐使用上面提到的库。

public static String performPostRequest(String summoUrl, String payload, 
Context context) throws IOException {
URL url = new URL(summoUrl);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
String line;
StringBuffer jsonString = new StringBuffer();

uc.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
uc.setRequestMethod("POST");
uc.setDoInput(true);
uc.setInstanceFollowRedirects(false);
uc.connect();
OutputStreamWriter writer = new OutputStreamWriter(uc.getOutputStream(), "UTF-8");
writer.write(payload);
writer.close();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
while((line = br.readLine()) != null){
jsonString.append(line);
}
br.close();
} catch (Exception ex) {
ex.printStackTrace();
}
uc.disconnect();
return jsonString.toString();
}

异步任务

      new AsyncTask<String, String, String>() {

@Override
protected String doInBackground(String... params) {
try {
String response = makePostRequest(""https://endpoint1.collection.us2.sumologic.com/receiver/v1/http/ZaVnC4dhaV1oma90Vvb..."",
// Sample JSON Data "
{ \"organization": \"organization.name\",
\"environment": \"environment.name\",
\"apiProduct": \("apiproduct.name"),
\"proxyName": \("apiproxy.name"),
\"appName": \("developer.app.name"),
\"verb": \("request.verb"),
\"url": '' + \("client.scheme") + '://' + \("request.header.host") + \("request.uri"),
\"responseCode": \("message.status.code"),
\"responseReason": \("message.reason.phrase"),
\"clientLatency": total_client_time,
\"targetLatency": total_target_time,
\"totalLatency": total_request_time
}", getApplicationContext());
// Hard coded Success as response from Server, replace with this as per your need
return "Success";
} catch (IOException exception) {
exception.printStackTrace();
return exception.getMessage();
}
}

}.execute("");

有关更多信息,请参阅 Sumo 官方网页的文档

https://help.sumologic.com/Send-Data/Sources/02Sources-for-Hosted-Collectors/HTTP-Source/Upload-Data-to-an-HTTP-Source

关于android - 从 Android 客户端向相扑逻辑记录消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49371632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com