【问题标题】:Android system log fileAndroid系统日志文件
【发布时间】:2011-06-17 23:05:40
【问题描述】:

android 操作系统是否将系统事件记录到某个日志文件中?如果是这样,我在哪里/如何阅读?

背景:昨晚让我的 SEMC X10 Mini Pro 充电后,我醒来发现它没电了。我想查看一个日志文件,以尝试找出手机关闭的时间和原因。

【问题讨论】:

    标签: android


    【解决方案1】:

    找到this older post,这对你来说可能也很有趣。

    【讨论】:

    • Android Market Place 的日志收集器非常完美,谢谢。
    【解决方案2】:

    使用这个类:这会将日志写入 sd 上的文件

    public class Logger {
    
        public static final String APP_ID = "Android APP";
        public static String logDir = "/androidapp";
        public static String logFileName = "/log.txt";
        public static boolean writeLogsToFile = false;
        public static final int LOG_LEVEL_VERBOSE = 4;
        public static final int LOG_LEVEL_DEBUG = 3;
        public static final int LOG_LEVEL_INFO = 2;
        public static final int LOG_LEVEL_ERROR = 1;
        public static final int LOG_LEVEL_OFF = 0;
        public static final int CURRENT_LOG_LEVEL = LOG_LEVEL_DEBUG;
    
        public static void log(String message, int logLevel) {
            if (logLevel > CURRENT_LOG_LEVEL) {
                return;
            } else {
                Log.v(APP_ID, message);
                if (writeLogsToFile) {
                    writeToFile(message);
                }
            }
        }
    
        private static void writeToFile(String message) {
            try {
                File sdCard = Environment.getExternalStorageDirectory();
                File dir = new File(sdCard.getAbsolutePath() + logDir);
                dir.mkdirs();
                File file = new File(dir, logFileName);
                PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file, true), 8 * 1024));
                writer.println(APP_ID + " " + new Date().toString() + " : " + message);
                writer.flush();
                writer.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static void verbose(String message) {
            log(message, LOG_LEVEL_VERBOSE);
        }
    
        public static void debug(String message) {
            log(message, LOG_LEVEL_DEBUG);
        }
    
        public static void error(String message) {
            log(message, LOG_LEVEL_ERROR);
        }
    
        public static void info(String message) {
            log(message, LOG_LEVEL_INFO);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-21
      • 2014-04-22
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      • 2017-02-09
      • 2017-11-06
      相关资源
      最近更新 更多