package com.trs.web2frame.tool.tyjyh;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.trs.web2frame.tool.tyjyh.ConfigConstant;
/**
 * Created by CXC on 2017/6/5.
 */
public class Log_Exception {
	public static final String dirName = ConfigConstant.LOGDIR;
    /**
     * @将错误信息输入到txt中
     * @param path
     * @throws IOException
     */
    public static void Logger_txt(String content){
        System.out.println(content);
        File file = new File(dirName);
        if(!file.exists())file.mkdirs();
        String path = dirName+"/Loggeryy.txt";
        FileWriter fw = null;
        try {
            File F = new File(path);
            // 如果文件不存在,就动态创建文件
            if (!F.exists()) {
                F.createNewFile();
            }
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
            String timeNow = df.format(new Date()).toString();
            String writeDate = content;
            // 设置为:True,表示写入的时候追加数据
            fw = new FileWriter(F, true);
            // 回车并换行
            fw.write(writeDate + "\r\n");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static void Error_txt(String content){
        File file = new File(dirName);
        if(!file.exists())file.mkdirs();
        String path = dirName+"/LoggerError.txt";
        FileWriter fw = null;
        try {
            File F = new File(path);
            // 如果文件不存在,就动态创建文件
            if (!F.exists()) {
                F.createNewFile();
            }
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
            String timeNow = df.format(new Date()).toString();
            String writeDate = "时间:" + timeNow + "---" + content;
            // 设置为:True,表示写入的时候追加数据
            fw = new FileWriter(F, true);
            // 回车并换行
            fw.write(writeDate + "\r\n");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
