我是靠谱客的博主 甜甜眼睛,最近开发中收集的这篇文章主要介绍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 log日志输出到文件格式,安卓,输出log信息到文件中所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部