android 将log保存到文本_第1页
android 将log保存到文本_第2页
android 将log保存到文本_第3页
android 将log保存到文本_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 先加上此类 java view plaincopy package com leader hsj utils import java io BufferedReader import java io File import java io FileNotFoundException import java io FileOutputStream import java io IOException import java io InputStreamReader import java text SimpleDateFormat import java util Date import android content Context import android os Environment log 日志统计保存 author 陈伟斌 public class LogcatHelper private static LogcatHelper INSTANCE null private static String PATH LOGCAT private LogDumper mLogDumper null private int mPId private final static String LOG FILE DIR leaderlog 初始化目录 public void init Context context if Environment getExternalStorageState equals Environment MEDIA MOUNTED 优先保存到 SD 卡中 PATH LOGCAT Environment getExternalStorageDirectory getAbsolutePath File separator LOG FILE DIR else 如果 SD 卡不存在 就保存到本应用的目录下 PATH LOGCAT context getFilesDir getAbsolutePath File separator LOG FILE DIR File file new File PATH LOGCAT if file exists file mkdirs public static LogcatHelper getInstance Context context if INSTANCE null INSTANCE new LogcatHelper context return INSTANCE private LogcatHelper Context context init context mPId android os Process myPid public void start if mLogDumper null mLogDumper new LogDumper String valueOf mPId PATH LOGCAT mLogDumper start public void stop if mLogDumper null mLogDumper stopLogs mLogDumper null private class LogDumper extends Thread private Process logcatProc private BufferedReader mReader null private boolean mRunning true String cmds null private String mPID private FileOutputStream out null public LogDumper String pid String dir mPID pid try out new FileOutputStream new File dir leader getFileName log catch FileNotFoundException e TODO Auto generated catch block e printStackTrace 日志等级 v d w e f s 显示当前 mPID 程序的 E 和 W 等级的日志 cmds logcat e w grep mPID cmds logcat grep mPID 打印所有日志信息 cmds logcat s way 打印标签过滤信息 cmds logcat e i grep mPID public void stopLogs mRunning false Override public void run try logcatProc Runtime getRuntime exec cmds mReader new BufferedReader new InputStreamReader logcatProc getInputStream 1024 String line null while mRunning if line length 0 continue if out null catch IOException e e printStackTrace finally if logcatProc null logcatProc destroy logcatProc null if mReader null try mReader close mReader null catch IOException e e printStackTrace if out null try out close catch IOException e e printStackTrace out null public static String getFileName SimpleDateFormat format new SimpleDateFormat yyyy MM dd String date format format new Date System currentTimeMillis return date 2012年10月03日 23 41 31 public static String getDateEN SimpleDateFormat format1 new SimpleDateFormat yyyy MM dd HH mm ss String date1 format1 format new Date System currentTimeMillis return date1 2012 10 03 23 41 31 2 加上权限 html view plaincopy 3 调用 java view plaincopy LogcatH

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论