代码改变世界

Android Log 工具类支持输出调用代码所属的线程ID,文件名,行号,方法名

2011-09-27 18:03  shaobin0604  阅读(584)  评论(0编辑  收藏  举报

代码

gist1244723

特性

1. 支持输出调用代码所属的线程ID,文件名,行号,方法名

09-27 17:38:45.311 D/SIPUA   ( 4700): [ Thread-132: Sipdroid.java: 410: run() ] _____ -----> PT=103, SSRC=0xbb7431a6, Seq= 268, len=1414, plen=1402, ts=1938987090 

2. 支持动态设置日志输出级别,原理参考

public static boolean isLoggable (String tag, int level)

Since: API Level 1

Checks to see whether or not a log for the specified tag is loggable at the specified level. The default level of any tag is set to INFO. This means that any level above and including INFO will be logged. Before you make any calls to a logging method you should check to see if your tag should be logged. You can change the default level by setting a system property: 'setprop log.tag.<YOUR_LOG_TAG> <LEVEL>' Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPPRESS will turn off all logging for your tag. You can also create a local.prop file that with the following in it: 'log.tag.<YOUR_LOG_TAG>=<LEVEL>' and place that in /data/local.prop.

Parameters
tag The tag to check.
level The level to check.
Returns
  • Whether or not that this is allowed to be logged.
Throws
IllegalArgumentException is thrown if the tag.length() > 23.