【问题标题】:redirecting system.out to logcat [duplicate]将 system.out 重定向到 logcat [重复]
【发布时间】:2017-11-02 18:39:33
【问题描述】:

我正在将我为桌面应用程序做的系统移植到 android 作为应用程序中包含的 jar。

有没有办法使用 system.out.println(存在于 jar 中)并查看它们登录 logcat(或其他任何地方)?

我目前正在使用 eclipse 中的 adb 在真实设备上进行调试,并且我在 logcat 控制台中正确地看到了设备日志,但没有看到标准输出。

【问题讨论】:

  • 你为什么要使用system.out.println?你可以使用Log.d('Log entry', 'some log entry description or event')
  • 我包含用于桌面应用程序的 java 代码(并且在其构建路径中没有 android),我需要调试该代码在 android 设备上的运行情况,因此我需要结果system.out 在那个罐子里。
  • 显然所有System.out.println 调用都在android 中丢失了。 stackoverflow.com/questions/2220547/…

标签: android eclipse adb logcat


【解决方案1】:

请参阅this 问题。基本上,没有。要登录 Android,您必须使用 Log。 Log.i、Log.d、Log.v 等。您可以使用几种不同风格的日志,并在 Android Monitor 中过滤这些日志。您必须手动将 System.out.println 转换为日志。

但是你可以用 RegEx 替换它们。

1) 在 Eclipse 中不确定,但使用热键进入“全部替换文件路径”窗口(Android Studio 中的 ctrl + shift + r)。

2) 确保正则表达式 (RegEx) 已打开

3) 在“查找”字段中,只需输入

system.out.println\(

4) 替换为

Log\.d("TAG",

你应该很高兴。

【讨论】:

  • haw.. 所以它没有。我还必须将 e.printStackTrace( 更改为 Log.e(APP_TAG, Log.getStackTraceString(e) 并在我猜的每个项目的构建路径中包含 android ......然后切换回原来的样子......每个时间...
猜你喜欢
  • 2019-04-17
  • 1970-01-01
  • 2012-11-30
  • 2014-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-12
相关资源
最近更新 更多