📄 elog.java
字号:
/* * 作者: 胡李青 * qq: 31703299 * Copyright (c) 2007 huliqing * 主页 http://www.tbuy.biz/ * 你可以免费使用该软件,未经许可请勿作用于任何商业目的 */package biz.tbuy.common.logs;import biz.tbuy.common.ComApplication;import biz.tbuy.common.Constants;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;/** * @author huliqing * <p><b>qq:</b>31703299 * <p><b>E-mail:</b><a href="mailto:huliqing.cn@gmail.com">huliqing.cn@gmail.com</a> * <p><b>Homepage:</b><a href="http://www.tbuy.biz/">http://www.tbuy.biz/</a> */public class Elog { // 设置是否进行日志输出,如果为true,则在程序出现错误时,记录日志 public static boolean track = true; // 是否开启调试 public static boolean debug = true; // 调试输出,可选:file/console; file为日志文件,console为控制台输出 public static String debugOf = "console"; public Elog() { } /** * 日志跟踪,需要开启track. * @param message */ public static void log(String message) { if (!track) { return; } //File logPath = new File(getLogPath()); File logPath = new File(getElogPath()); if (!logPath.exists()) { logPath.mkdirs(); } Date theDate = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String fileName = "log" + sdf.format(theDate) + ".txt"; sdf.applyPattern("HH:mm:ss"); String nowTime = sdf.format(theDate); File logFile = new File(logPath, fileName); FileWriter fw = null; try { fw = new FileWriter(logFile, true); fw.write("Log:[" + nowTime + "]"); fw.write(message + "\r\n"); fw.flush(); fw.close(); } catch (IOException ioe) { System.out.println("Elog:log:I/O Error"); } } /** * debug * 调试输出,需要设置debug = true * 调试输出可选file或console, 如果选择file,则需要开启track * @param message 调试输出 */ public static void debug(String message) { if (!debug) { return; } if (debugOf.equals("console")) { System.out.println("debug:" + message); } else if (debugOf.equals("file")) { Elog.log("debug:" + message); } } /** * 返回错误日志文件的路径 * @return elogPath */ private static String getElogPath() { return ComApplication.getInstance().getServletContextPath() + Constants.PATH_ELOG; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -