Codename One - 在String中获取由Log.p()和Log.e()生成的所有日志的可靠方法

时间:2017-12-18 11:30:40

标签: codenameone

在我的应用程序的开发阶段,对我来说,方便地获取Log.p()Log.e()在字符串中生成的所有日志(例如,在对话框中显示它们或使用与Log.sendLog()不同的方法通过电子邮件发送它们。

这就是我创建以下方法的原因。我的问题是它是否可靠,如果我没有复制已经存在的东西:

/**
 * Get all logs of the app generated with Log.p() or Log.e()
 * @return All logs of the app generated with Log.p() or Log.e()
 */
public static String getAllLogs() {
    String logs = "";
    try {
        logs = Util.readToString(Storage.getInstance().createInputStream("CN1Log__$"));
    } catch (IOException ex) {
        logs = "";
    }
    return logs;
}

1 个答案:

答案 0 :(得分:1)

这种方法的主要问题是操作系统处理打开文件的各种方式,因此我会避免使用它,因为它可能会通过检查触发崩溃,例如在写入文件时打开要读取的文件。

在iOS / Android上,这应该可以正常工作,因为它们是基于unix的,但在Windows上它可能具有挑战性。内存受限设备中的大型日志也可能导致崩溃。