奇怪的 Log.i() 行为 Android Studio

huangapple go评论83阅读模式
英文:

Strange Log.i() behavior Android Studio

问题

我看到了一些非常奇怪的东西。我正在进行一个HTTP POST请求

        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            response = httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            String strResponse = null;
            if (entity != null) {
                strResponse = EntityUtils.toString(entity);
                Log.i("SetupAutoCardResponse",String.valueOf(strResponse));
                Log.i("otherTest","test");
                Log.i("otherTest",strResponse);
                return true;
            }
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }

日志中唯一的输出是 otherTest : Test
strResponse 相关的日志根本没有显示出来,我的意思是,什么都没有显示。它看起来不像是这样的 SetupAutoCardResponse : null 或者 otherTest: null。绝对什么都没有显示出来。但我知道我收到了一个响应。表达式返回 true

英文:

I'm seeing something really weird. Im making a http post request

        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            response = httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            String strResponse = null;
            if (entity != null) {
                strResponse = EntityUtils.toString(entity);
                Log.i("SetupAutoCardResponse",String.valueOf(strResponse));
                Log.i("otherTest","test");
                Log.i("otherTest",strResponse);
                return true;
            }
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }

The only output I see in the log is otherTest : Test.
The logs with strResponse dont show up at all, and by that I mean, nothing shows. It does not look like this SetupAutoCardResponse : null or otherTest: null. Absolutly nothing shows up. But I know I am getting a response. The expression returns true

答案1

得分: 1

在日志中,如果消息为Null、空白或空,日志将不会记录。
示例:Log.i(TAG, MSG);
为了确保它起作用,我们可以向MSG添加一些文本。

Log.i(TAG, String.format("%s %s", "MSG>", MSG));

英文:

In Log, if the Messsage is Null or Blank or Empty, Log will not write down.
Example: Log.i(TAG, MSG);
To make sure it works, we can add some text to MSG

 Log.i(TAG, String.format("%s %s", "MSG>" , MSG));

huangapple
  • 本文由 发表于 2020年9月23日 10:54:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/64020382.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定