⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logutil.java

📁 博克后台的开发,有很多使用的方法和例子可以提供给大家学习
💻 JAVA
字号:
package com.webpublish.util;

import java.util.Date;

import com.webpublish.config.ConfigUtil;

public class LogUtil {

	public String logContent;

	public String logItem;

	public String logName;

	public String logCreateItem;

	public String logCreateIdItem;

	public String logCreateJlbhItem;

	public String logString;

	public String logIniName;

	public String logIniPath;

	public String logMacro;

	public String initTime;

	public StringBuffer logNameTime;

	private ConfigUtil getConfig = new ConfigUtil("log.properties");

	public LogUtil(String logName, String logPath) {
		this.logContent = "";
		this.logItem = "";
		this.logCreateItem = "";
		this.logCreateIdItem = "";
		this.logCreateJlbhItem = "";
		this.logString = "";
		this.logMacro = "<!--#日志内容#-->";
		this.logName = logName;
		this.logIniPath = getConfig.getProperty(logPath);

	}

	public void beginLog(String CreateItem) {
		this.initLog();
		this.logString = "";
		this.logContent = "";
		this.logContent += "<tr><td width=180 align=center>"
				+ DateUtil.formatIso8601Daytime(new Date()) + "</td>";
		this.logContent += "<td width=700><font class=l9  color=blue>"
				+ CreateItem + " 开始转换!</font></td></tr>";
		this.updateLog();
	}

	public void endLog(String CreateItem) {
		this.logContent = "";
		this.logString = "";
		this.logContent += "<tr><td width=180 align=center>"
				+ DateUtil.formatIso8601Daytime(new Date()) + "</td>";
		this.logContent += "<td width=700><font class=l9  color=blue>"
				+ CreateItem + " 转换结束!</font></td></tr>";
		this.updateLog();
	}

	public void errLog(String syserr) {
		setLogItem();
		this.logContent = "";
		if (!syserr.equals("")) {
			this.logString = this.logString + "系统错误信息:" + syserr;
		}

		this.logContent += "<tr><td width=180 align=center>"
				+ DateUtil.formatIso8601Daytime(new Date()) + "</td>";
		this.logContent += "<td width=700><font class=l9 color=red>"
				+ this.logItem + "  " + this.logString + "</font></td></tr>";
		this.updateLog();
	}

	public boolean initLog() {
		String outStr;
		this.logIniName = getConfig.getProperty(this.logName)
				+ this.logNameTime + ".html";
		outStr = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"><title>颗粒生成日志</title>"
				+ "<STYLE type=text/css>.l9 {  font-size: 11pt; line-height: 18px; text-decoration: none;WORD-WRAP: break-word}"
				+ ".l14 {  font-size: 13pt; line-height: 24px; text-decoration: none} .bw { WORD-WRAP: break-word }</STYLE></head><body>"
				+ "<center><font class=l14  color=#0000ff><b>颗粒生成日志</b></font></center>"
				+ "<table width=880 border=1 cellpadding=0 cellspacing=0 bordercolor=#DFDFDF class=19 align=center>"
				+ "<tr><td width=180 align=center>日期 - 时间</td><td width=700 align=center>描  述</td></tr>"
				+ this.logMacro + "</table></body></html>";
		return FileUtil
				.createNewFile(this.logIniPath + this.logIniName, outStr);
	}

	public void msgLog(String outstr) {
		setLogItem();
		this.logContent = "";
		this.logContent += "<tr><td width=180 align=center>"
				+ DateUtil.formatIso8601Daytime(new Date()) + "</td>";
		this.logContent += "<td width=700><font class=l9>" + this.logItem + " "
				+ outstr + "</font></td></tr>";
		this.updateLog();
	}

	public void setLogItem() {

		if (this.logCreateIdItem != "") {
			if (this.logCreateJlbhItem == "") {
				this.logItem = this.logCreateItem + " ID="
						+ this.logCreateIdItem;
			} else {
				this.logItem = this.logCreateItem + " ID="
						+ this.logCreateIdItem + " 记录编号="
						+ this.logCreateJlbhItem;
			}
		} else {
			this.logItem = this.logCreateItem;
		}
	}

	public void setInitTime(String logTime) {
		// boolean tmp;
		// tmp = this.InitLog();
		this.initTime = logTime;
		this.logNameTime = DateUtil.formatLogtime(this.initTime);
	}

	public void successLog() {
		if (this.logCreateIdItem != "") {
			this.logItem = this.logCreateItem + " ID=" + this.logCreateIdItem;
		} else {
			this.logItem = this.logCreateItem;
		}

		this.logContent = "";
		this.logContent += "<tr><td width=180 align=center>"
				+ DateUtil.formatIso8601Daytime(new Date()) + "</td>";
		this.logContent += "<td width=700><font class=l9 color=#00CC00>"
				+ this.logItem + " 转换成功!</font></td></tr>";
		this.updateLog();
	}

	public boolean updateLog() {
		String tmpStr;
		tmpStr = this.logContent + this.logMacro;
		return FileUtil.replaceFileContent(this.logIniPath + this.logIniName,
				this.logMacro, tmpStr);
	}

	public static void main(String[] args) {
		LogUtil writeLog = new LogUtil("grainPubLogName", "grainPubLogPath");
		writeLog.setInitTime("2006-01-03 01:00:00");
		if (writeLog.initLog()) {
			writeLog.beginLog("提交!");
			writeLog
					.errLog("select klsxrecid,klzdrecid,klsxstatus,wzklxxflid,wzklgname,wzklgkind,wzklgtype,wzklifpage,wzklpmod,wzklcpath,wzklcname,wzklppurl,klmbtmecro,klmbltemp,klmbnoltemp,klzddbtype,klzddbconn,klzddbsql,klzdfields,klzdmacro,klzdnolnum,klzdlrnum,klzdlnum,klzdptseq from ydbuser.VWEB_KLSX where klsxrecid=?error!");
			writeLog.msgLog("一般信息!");
			writeLog.successLog();
			writeLog.endLog("提交!");
			System.out.println("OK!");
		} else {
			System.out.println("FALSE!");
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -