Android Log.v()、Log.d()、Log.i()、Log.w()、Log.e() - 何时使用? [英] Android Log.v(), Log.d(), Log.i(), Log.w(), Log.e() - When to use each one?

查看:32
本文介绍了Android Log.v()、Log.d()、Log.i()、Log.w()、Log.e() - 何时使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不同的 LogCat 方法是:

Log.v(); // Verbose
Log.d(); // Debug
Log.i(); // Info
Log.w(); // Warning
Log.e(); // Error

使用每种类型的日志记录的适当情况是什么?我知道这也许只是一点点语义,也许它并不重要,但是对于 Android Studio 和 Eclipse 中的 LogCat 过滤,很高兴知道我正在使用正确的方法合适的时间.

What are the appropriate situations to use each type of Logging? I know that perhaps it's just a little bit of semantics and perhaps it doesn't really matter, but for LogCat filtering in Android Studio and Eclipse, it would be nice to know I am using the proper methods at the appropriate times.

推荐答案

我们倒序来:

  • Log.e:这是在发生不好的事情时使用的.在诸如 catch 语句之类的地方使用此标记.您知道发生了错误,因此您正在记录错误.

  • Log.e: This is for when bad stuff happens. Use this tag in places like inside a catch statement. You know that an error has occurred and therefore you're logging an error.

Log.w:当您怀疑正在发生一些可疑的事情时使用此选项.您可能没有完全了解错误模式,但也许您已从某些意外行为中恢复过来.基本上,使用它来记录您不希望发生的事情,但不一定是错误.有点像嘿,这件事发生了,很奇怪,我们应该调查一下."

Log.w: Use this when you suspect something shady is going on. You may not be completely in full on error mode, but maybe you recovered from some unexpected behavior. Basically, use this to log stuff you didn't expect to happen but isn't necessarily an error. Kind of like a "hey, this happened, and it's weird, we should look into it."

Log.i:使用它向日志发布有用的信息.例如:您已成功连接到服务器.基本上用它来报告成功.

Log.i: Use this to post useful information to the log. For example: that you have successfully connected to a server. Basically use it to report successes.

Log.d:用于调试目的.如果您想打印出一堆消息以便记录程序的确切流程,请使用它.如果您想保留变量值的日志,请使用它.

Log.d: Use this for debugging purposes. If you want to print out a bunch of messages so you can log the exact flow of your program, use this. If you want to keep a log of variable values, use this.

Log.v:当您想对您的日志进行绝对疯狂时使用它.如果出于某种原因您决定记录应用程序特定部分中的每一件小事,请使用 Log.v 标签.

Log.v: Use this when you want to go absolutely nuts with your logging. If for some reason you've decided to log every little thing in a particular part of your app, use the Log.v tag.

作为奖励...

  • Log.wtf:当事情发生绝对、可怕、糟糕的错误时使用它.你知道那些你捕获错误的 catch 块,你永远不应该得到这些错误......是的,如果你想记录它们,请使用 Log.wtf
  • Log.wtf: Use this when stuff goes absolutely, horribly, holy-crap wrong. You know those catch blocks where you're catching errors that you never should get...yeah, if you wanna log them use Log.wtf

这篇关于Android Log.v()、Log.d()、Log.i()、Log.w()、Log.e() - 何时使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆