错误日志收集

1、config.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>

<info>

<DataSource1>
<DataSourceType>oracle</DataSourceType>
<DataDriver>oracle.jdbc.driver.OracleDriver</DataDriver>
<DataUser>itapwh</DataUser>
<DataPassword>123</DataPassword>
<DataUrl>jdbc:oracle:thin:@localhost:1521:orcl</DataUrl>
</DataSource1>

<File><!-- 修改参数需重启 -->
<span style="font-family: Arial, Helvetica, sans-serif;"><serviceErrorListPath>C:/serviceErrorListPath/</serviceErrorListPath></span>
</File>


</info>

2、Tools中的errorList方法

<span style="white-space:pre">	</span>public synchronized static void errorList(Exception e, String userName) {
		Date date = new Date();
		DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");// 时间格式1
		DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 时间格式2
		Document doc = null;
		Element root = null;
		PrintStream ps = null;
		OutputStream os = null;
		try {
			String pzwjlj=Tools.getPath();
			File pzwj = new File(java.net.URLDecoder.decode(pzwjlj, "GBK"),
					"config.xml");
			doc = new SAXReader().read(pzwj);
			root = doc.getRootElement().element("File");
			String folderPath = root.element("serviceErrorListPath").getTextTrim();
			File folder = new File(folderPath);
			if (!folder.isDirectory()) { // 目录不存在的话建立目录
				folder.mkdirs();
			}
			;
			String filePath = folderPath + File.separator + df1.format(date)
					+ ".zydl";
			File file = new File(filePath);
			os = new FileOutputStream(file, true);
			ps = new PrintStream(os);
			ps.println("(" + df2.format(date) + ")|(" + userName + ")");
			e.printStackTrace(ps);
			ps.println("--------------------------------------------------------");
			ps.flush();
			System.out.println("/*(" + df2.format(date) + ")|(" + userName
					+ ")出现错误,错误信息已记入日志*/");
		} catch (Exception e2) {
			System.out.println("/*注意:严重错误,错误收集功能出错*/");
			e2.printStackTrace();
		} finally {
			try {
				ps.close();
				os.close();
			} catch (Exception e1) {
				ps = null;
				os = null;
			}
		}
	}
3、方法调用

通常在catch中调用Tools.errorList(e,userName);即可。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值