1

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

4

1 回答 1

3

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

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

您只需在请求正文上发布您的数据并提及您的 Sumo 集合端点以及 UniqueHTTPCollectorCode。

REST 服务/Web 服务: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

于 2018-03-19T20:30:09.040 回答