日志存储本地文件

public static final String logFileName = "market.txt";//日志名称
public static final String logFilePathFolder = Environment.getExternalStorageDirectory() + File.separator + "tdr_market_log" + File.separator;//日志上传

public class LogFileUtil {
    private static final String TAG = "LogFileUtil";
    private static int count = 0;
    private static boolean isRequesting;
    private static int KEY_FILE_SIZE = 3;

    public static int e(String tag, String msg) {
//        Log.e("--------size=", getFileSize() + "");
//        if (getFileSize() > getUploadFileSize() * 1024 * 1024 && !isRequesting) {
        if (getFileSize() > 1 * 5 * 1024 && !isRequesting) {
            createThreadZipFile();
//            pushCreateThreadZipFile();
//        } else {
//        }
        try {
            if (ObjectUtil.isNull(msg)) {
                msg = "";
            }
            fileLog(tag, msg);
        } catch (Exception e) {

        }

        return Log.e(tag, msg);
    }

    public static int i(String tag, String msg) {
//        if (getFileSize() > getUploadFileSize() * 1024 * 1024 && !isRequesting) {
//            createThreadZipFile();
//        } else {
//            fileLog(tag, msg);
//        }

        try {
            if (ObjectUtil.isNull(msg)) {
                msg = "";
            }
            fileLog(tag, msg);
        } catch (Exception e) {

        }

        return Log.i(tag, msg);
    }


    public static void fileLog(String tag, String msg) {

        try {
            if ("mounted".equals(Environment.getExternalStorageState())) {
                File dir = new File(Constant.logFilePathFolder);
                if (!dir.exists()) {
                    dir.mkdirs();
                }

                File logFile = new File(Constant.logFilePathFolder, Constant.logFileName);
                if (!logFile.exists()) {
                    logFile.createNewFile();
                }

                BufferedWriter bw = null;
                if (ObjectUtil.isNull(bw)) {
                    bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logFile, true), Charset.forName(""UTF-8")));
                }
                bw.append((new Timestamp(System.currentTimeMillis())).toString()).append("  ").append(tag).append(":").append(msg).append("\n");
//                bw.flush();
                bw.close();
            }
        } catch (Exception var4) {

        }
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值