登录 J2ME

发布于 2024-07-06 02:59:58 字数 80 浏览 6 评论 0原文

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

允世 2024-07-13 02:59:59

具有Symbian 本身修改的Sun 虚拟机的Series60 和UIQ 手机具有标准输出重定向功能。

您不仅可以捕获 System.out,而且 Throwable.printStackTrace() 也可以工作。

在早期的手机上,您需要编写一个 C++ 应用程序来连接到标准库服务器进程。 Symbian 开发了 Redirector 应用程序,可以将 VM 标准输出捕获到控制台或文件中。

在较新的手机上,引入了“redirect://”GCF 协议,该协议可以将 VM 标准输出读入 Java byte[] 或 String 对象(您可能希望在单独的 MIDlet 中执行此操作),并且重定向器应用程序被重写为爪哇。

在 Series60 第三版功能包 2 手机(及更高版本)中使用的最新 J9 VM 上,您可能需要尝试“redirect://test”。

The Series60 and UIQ phone that have a Sun virtual machine modified by Symbian itself have Standard Output redirection.

Not only can you capture System.out but Throwable.printStackTrace() also works.

On early handsets, You would need to write a C++ application that hooks into the standard library server process. Symbian produced the Redirector application that could capture the VM standard output to a console or a file.

On newer handsets, a "redirect://" GCF protocol was introduced that could read the VM standard output into a Java byte[] or String object (you would want to do that in a separate MIDlet) and the Redirector application was rewritten in Java.

On the newest J9 VM used in Series60 3rd Edition Feature Pack 2 handsets (and later), you may need to try "redirect://test" instead.

暗地喜欢 2024-07-13 02:59:59

我已经在生产应用程序中使用了 MIDPLogger 达到了某种可接受的水平,尽管我我们发现它在集成到应用程序中之后比作为套件中的另一个 Midlet 等具有更多用途。 我还找到了 MicroLog 但没有详细使用它。

I've used MIDPLogger to some acceptable level in a production application, although I have found it has more use after integrating into the application rather than as another Midlet in suite or so forth. I also found MicroLog but haven't used it to any great detail.

情泪▽动烟 2024-07-13 02:59:59

我写了一个字节码优化器,由于类文件的格式,你可以指向类名和类名的UTF编码。 函数,它允许您使用 MyClass.someFunc() 输出日志(如果您想获取类型,您可以处理签名),它允许您使用 LINE & 执行类似 C 风格调试的操作。 FILE 宏。

I wrote a bytecode optimizer, and because of the format of class files you can point to the UTF encoding of classname & function which allows you to output logs with MyClass.someFunc() (you can process the signature if you want to get the types) which allows you to do something like the C style debug using LINE & FILE macros.

掩于岁月 2024-07-13 02:59:59

使用记录器类的条件编译并不能解决完全删除日志记录语句的问题,因为您通常会记录多个简单字符串。 您将查找变量值,然后将它们组装成字符串,例如:WhateverLog.log( "Loaded " + someclass.size() + " foos" )。

现在,如果您只省略WhateverLog.log 的主体(如已接受的解决方案中所示),您仍然会留下许多不必要的代码,包括字符串连接(以及因此创建的StringBuffer)。 这就是为什么你最好使用像 proguard 这样的字节码后处理工具(已经提到过)。 Proguard 的 -assumenosideeffects 将允许其优化器不仅删除日志记录语句,还删除其结果仅由日志记录调用使用的所有代码。

Using conditional compilation of the logger class does not solve the problem of completely removing logging statements because you will quite often log more than a simple string. You will look up variable values and then assemble them into strings, e.g.: WhateverLog.log( "Loaded " + someclass.size() + " foos" ).

Now if you only leave out the body of WhateverLog.log (as shown in the accepted solution), you will still leave a lot of unnecessary code in, including String concatenation (and thus a StringBuffer creation). That's why you'd better use a byte code post processing tool like proguard (already mentioned). Proguard's -assumenosideeffects will allow its optimizer to remove not only the logging statements but also all code whose results would only be used by the logging call.

沫离伤花 2024-07-13 02:59:59

J2ME的LWUIT框架提供了Logging形式,可以在其中记录语句。 您可以在您认为可能生成异常的每个位置添加日志。

示例:Log.getInstance().showLog();
通过添加以上行,您可以跟踪 J2ME 设备中的日志记录。

LWUIT framework of the J2ME provide the Logging form which can have a log the statement inside it. You can add the log at each and every place you think may generate the exception.

Example : Log.getInstance().showLog();
By adding the above line you can able to track the logging in the J2ME devices.

病毒体 2024-07-13 02:59:58

MicroLog 是肯定的选择。 它是一个类似于 Log4j 的 Java ME (J2ME) 小型日志库。 它支持记录到控制台、文件、RecordStore、Canvas、表单、蓝牙、串行端口(蓝牙、IR、USB)、Socket(包括 SSL)、UDP、Syslog、MMS、SMS、电子邮件或 Amazon S3 。

http://sourceforge.net/projects/microlog/

MicroLog is sure bet. It is a small logging library for Java ME (J2ME) like Log4j. It has support for logging to console, file, RecordStore, Canvas, Form, Bluetooth, a serial port (Bluetooth, IR, USB), Socket(incl SSL), UDP, Syslog, MMS, SMS, e-mail or to Amazon S3.

http://sourceforge.net/projects/microlog/

霓裳挽歌倾城醉 2024-07-13 02:59:58

如果您使用 Proguard 进行预处理和混淆,那么您可以拥有一个简单的日志记录类。

public class Log {
  public static void debug(final String message) {
    //#if !release.build
    System.out.println(message);
    //#endif
  }
}

或者在您需要的地方进行日志记录。 现在,如果release.build属性设置为true,该代码将被注释掉,这将导致一个空方法。 Proguard 将删除所有空方法的使用 - 实际上发布版本将删除所有调试消息。

编辑:

在库级别考虑它(我正在映射 J2ME 库),我可能已经找到了更好的解决方案。

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;
  }
}

这样,最终开发人员可以在他/她感兴趣的库内启用日志级别。如果不启用任何内容,则所有日志记录代码都将在最终产品混淆中被删除。 甜甜的:)

/JaanusSiim

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
  }
}

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.

Edit:

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

嘿哥们儿 2024-07-13 02:59:58

您可以使用 proguard 中的 -assumenosideaffects 来完全删除您的日志记录类:

-assumenosideeffects public class logger.Logger {*;}

而不必进行预处理。

You can use the -assumenosideaffects in proguard to completley remove your logging class:

-assumenosideeffects public class logger.Logger {*;}

Rather than having to preprocess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文