j2me存在哪些日志记录解决方案?
What logging solutions exist for j2me?
我特别希望轻松排除发行"版本的日志记录,以拥有更小的软件包和&内存占用量.
I'm specifically interested in easily excluding logging for "release" version, to have a smaller package & memory footprint.
推荐答案如果您通过Proguard使用预处理和模糊处理,则可以拥有一个简单的日志记录类.
If you are using preprocessing and obfuscation with Proguard, then you can have a simple logging class.
public class Log { public static void debug(final String message) { //#if !release.build System.out.println(message); //#endif } }或者在需要的地方进行日志记录.现在,如果release.build属性设置为true,则该代码将被注释掉,这将导致一个空方法. Proguard将删除所有使用空方法的方法-实际上,发布版本将删除所有调试消息.
Or do logging where ever you need to. Now, if release.build property is set to true, this code will be commented out, that will result in an empty method. Proguard will remove all usages of empty method - In effect release build will have all debug messages removed.
关于库级别的思考(我正在研究J2ME库的映射),我可能已经找到了更好的解决方案.
Thinking about it on library level (I'm working on mapping J2ME library) I have, probably, found a better solution.
public class Log { private static boolean showDebug; public static void debug(final String message) { if (showDebug) { System.out.println(message); } } public static void setShowDebug(final boolean show) { showDebug = show; } }通过这种方式,最终开发人员可以在他/她感兴趣的库中启用日志级别.如果什么都不启用,则在最终产品混淆中将删除所有日志记录代码.甜:)
This way end developer can enable log levels inside library that he/she is interested in. If nothing will be enabled, all logging code will be removed in end product obfuscation. Sweet :)
/JaanusSiim
/JaanusSiim
更多推荐
登录J2ME
发布评论