我是靠谱客的博主 甜甜眼睛,这篇文章主要介绍android log日志输出到文件格式,安卓,输出log信息到文件中,现在分享给大家,希望可以做个参考。

public static boolean OutLogFile = true;// 输出log信息到文件

/** 输出log信息到文件中 */

public static String FileLog(String info)

{

if (OutLogFile)

{

String crashPath = "/sdcard/FileLog/Log/";

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

String date = formatter.format(new Date());

DateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");

String time = formatter2.format(new Date()) + " ";

String fileName = "log-" + date + ".txt";

info = "rn" + time + info;

try

{

if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))

{

// String path = "/sdcard/com.hm.pay.demo/crash/";

File dir = new File(crashPath);

if (!dir.exists())

{

dir.mkdirs();

}

FileOutputStream fos = new FileOutputStream(crashPath + fileName, true);

fos.write(info.getBytes());

fos.close();

}

}

catch (Exception e)

{

Log.e(TAG, "an error occured while writing file log...", e);

}

return crashPath + fileName;

}

else return "";

}

最后

以上就是甜甜眼睛最近收集整理的关于android log日志输出到文件格式,安卓,输出log信息到文件中的全部内容,更多相关android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部