我正在构建一个 Android 应用程序,我想知道像 javascript 中的 console.log 这样调试的最佳方法是什么
原文由 Ben 发布,翻译遵循 CC BY-SA 4.0 许可协议
我正在构建一个 Android 应用程序,我想知道像 javascript 中的 console.log 这样调试的最佳方法是什么
原文由 Ben 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用 Android 日志实用程序。
http://developer.android.com/reference/android/util/Log.html
Log 有一堆用于访问不同日志级别的静态方法。共同点是它们总是至少接受一个标签和一条日志消息。
标签是一种过滤日志消息输出的方法。您可以使用它们浏览您将看到的数以千计的日志消息,并找到您特别要查找的日志消息。
您可以通过访问 Log.x 对象(其中 x 方法是日志级别)来使用 Android 中的日志功能。例如:
Log.d("MyTagGoesHere", "This is my log message at the debug level here");
Log.e("MyTagGoesHere", "This is my log message at the error level here");
我通常会特别注意将标签作为我的类名,这样我也知道日志消息是在哪里生成的。为以后的游戏节省不少时间。
您可以使用适用于 Android 的 logcat 工具查看您的日志消息:
adb logcat
或者通过转到菜单栏打开 eclipse Logcat 视图
Window->Show View->Other then select the Android menu and the LogCat view
原文由 John O‘Connor 发布,翻译遵循 CC BY-SA 3.0 许可协议
15 回答8.4k 阅读
8 回答6.2k 阅读
1 回答4k 阅读✓ 已解决
3 回答6k 阅读
3 回答2.2k 阅读✓ 已解决
2 回答3.1k 阅读
2 回答3.8k 阅读
日志 类:
在 Android 之外,使用
System.out.println(String msg)
。