java的console.log()是什么?

新手上路,请多包涵

我正在构建一个 Android 应用程序,我想知道像 javascript 中的 console.log 这样调试的最佳方法是什么

原文由 Ben 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 470
2 个回答

日志 类:

用于发送日志输出的 API。

Generally, use the Log.v() Log.d() Log.i() Log.w() and Log.e() methods.

The order in terms of verbosity, from least to most is ERROR , WARN , INFO , DEBUG , VERBOSE 。除非在开发期间,否则不应将 Verbose 编译到应用程序中。调试日志被编译但在运行时被剥离。始终保留错误、警告和信息日志。

在 Android 之外,使用 System.out.println(String msg)

原文由 nhaarman 发布,翻译遵循 CC BY-SA 3.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 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题