在 J2ME 中登录 [英] Logging in J2ME

查看:25
本文介绍了在 J2ME 中登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 中登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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