android.util.Log发布时 - 我该怎么办/不会做 [英] android.util.Log when publishing - what can I do / not do
问题描述
我已经得到了很多Log.i Log.d Log.e的地狱在我的$ C $下一个最近的应用程序,我所做的一切。我将要发布这个程序,我真的不希望人们看到它时,他们插有电话进入亚行,但我不希望它有我自己的调试。
I've got a hell of a lot of Log.i Log.d Log.e in my code for a recent app I've done. I'm about to publish this app and I don't really want people seeing it when they plug there phone into adb, but I do want it there for my own debugging.
我是想延长android.util.log,只是有一个布尔开关在里面,所以我可以只是关闭日志当我发布并把它开发时就但这类是final的,我错过了一招?
I was wanting to extend android.util.log and just have a boolean switch in there so I could just turn off the log when I publish and turn it on when developing but this class is final, am I missing a trick?
我真的不想去到c为remove我所有的$ C $,真实的,如果出现最坏最坏我可以做一个CTRL + H全局替换日志中//日志,但这吸吮作为一个答案。
I don't really want to go through my code an remove all, true if worst comes to worst I could do a ctrl+h global replace Log for //Log but that does suck as an answer.
我也意识到,Log.d被剥离在运行,但它仍然跑(失去一点点的性能),所以不运行,这将是一个额外的好处。
I also realise that Log.d is stripped out at runtime but it is still ran (losing a little performance) so not running this would be an added bonus.
是啊所以基本上我在寻找一种方式来切换我的调试和关闭编程,这也可以让我以后,使之成为preference什么的,如果人们想查看或帮帮忙,送它。
Yeah so basically I'm looking for a way to toggle my debug on and off programatically, this can also allow me later on to make it a preference or something if people want to view it or help out and send it on.
你们有什么实现的呢?
感谢
推荐答案
随着屋大维指出插入记录不断将做到这一点的最好办法。写一个新的类,这个调用原来的记录方法,如果启用了调试是不是一个好主意。
As Octavian points out inserting a logging constant would be the best way to do this. Writing a new class for this that calls the original logging methods if debugging is enabled is not a good idea.
好做法:
if (C.D) Log.d(C.T, "your log text here " + foo + bar);
不好的做法:
Bad practice:
YourLog.d("your log text here " + foo + bar);
// and in YourLog.java's d() method:
... { if (debugging) Log.d(tag, text); }
第一个解决方案是非常快的,如果C类的常数D是错误的。如果您对创建日志字符串复杂的字符串操作,如果调试被关闭,他们将不会被执行。编译器甚至可以在编译时去掉这些操作如果D是错误的,这可能会导致零运行时开销。第二个(坏的)解决方案将始终建立整个字符串,并调用一个方法,这是架空你不需要。
The first solution is very fast if the constant D of class C is false. If you have complex string operations for creating your logging string they will not be executed if debugging is deactivated. The compiler can even remove these operations at compile time if D is false, which may result in zero runtime overhead. The second (bad) solution will always build the whole string and call a method, which is overhead you don't need.
在一般的第一个解决方案将是最好的。打字时对性能方面的原因 - 是的,我真的叫类和成员C,D和T(常数/调试/标签)。 ; - )
In general the first solution would be best. And yes, I really call the class and members C, D and T (Constants/Debugging/Tag) - for performance reasons during typing. ;-)
这篇关于android.util.Log发布时 - 我该怎么办/不会做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!