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

📄 log.java

📁 短信网关发送接受平台。
💻 JAVA
字号:
package log;/** * Title: * Description: *      写日志线程 * Copyright:    Copyright (c) 2002 * Company: * @author * @version 1.0 */import java.io.*;import orderapp.Config;import utilities.Utility;/** * Title: * Description:生成log内容的函数 * Copyright:    Copyright (c) 2002 * Company: * @author * @version 1.0 */public class Log{	private String root;	private PrintWriter out;	private FileWriter fout;	private String today;	public Log() {		this.today=Utility.getDateString();		createLog();	}	private void createLog(){		String fileName="..\\log\\order"+this.today+".txt";		//String fileName=Utility.getDateString()+".log.xml";		//Config.mail_fileAffix.add(fileName);		try{			File file=new File(fileName);			if (file.exists()){				file.renameTo(new File("..\\log\\order"+this.today+"@"+Utility.getTimeStr()+".txt"));				file=new File("..\\log\\order"+this.today+".txt");			}			this.root="log";			fout=new FileWriter(file);			this.out=new PrintWriter(fout);			this.out.println("Create Log =================");			this.out.println("<"+root+" date=\""+Utility.getDateString()+"\">");			this.out.flush();		}catch(IOException ioe){			ioe.printStackTrace();		}	}	public synchronized void log(String content){		try{			if (!this.today.equalsIgnoreCase(Utility.getDateString())){				this.close();				this.today=Utility.getDateString();				this.createLog();			}			//XMLElement element=new XMLElement("log-content",content);			//XMLAttribute attribute=new XMLAttribute("time",Utility.getTimeString());			//element.addAttribute(attribute);			this.out.println("<-"+Utility.getTimeString()+"->\t"+content+"\r");			this.out.flush();			//this.notifyAll();		}catch(Exception ie){			ie.printStackTrace();		}	}	public synchronized void log(Exception e,String content){		try{			if (!this.today.equalsIgnoreCase(Utility.getDateString())){				this.close();				this.today=Utility.getDateString();				this.createLog();			}			//XMLTag tag=new XMLTag("log-content");			//XMLAttribute attribute=new XMLAttribute("time",Utility.getTimeString());			//XMLElement element=new XMLElement("Exception",content);			//XMLAttribute exName=new XMLAttribute("name",e.getMessage());			//element.addAttribute(exName);			//tag.add(attribute);			//tag.add(element);			//this.out.println(tag.toString());			this.out.println(Utility.getTimeString()+e.toString()+"\r\n");			this.out.println(Utility.getTimeString()+content+"\r\n");			this.out.flush();			//this.notifyAll();		}catch(Exception ie){			ie.printStackTrace();		}	}/*	public synchronized void log(Exception e){		try{			if (!this.today.equalsIgnoreCase(Utility.getDateString())){				this.close();				this.today=Utility.getDateString();				this.createLog();			}			XMLTag tag=new XMLTag("log-content");			XMLAttribute attribute=new XMLAttribute("time",Utility.getTimeString());			XMLElement element=new XMLElement("Exception");			XMLAttribute exName=new XMLAttribute("name",e.getMessage());			element.addAttribute(exName);			tag.add(attribute);			tag.add(element);			this.out.println(tag.toString());			this.out.flush();			//this.notifyAll();		}catch(Exception ie){			ie.printStackTrace();		}	}	public synchronized void log(String from,String actType,String content){		try{			if (!this.today.equalsIgnoreCase(Utility.getDateString())){				this.close();				this.today=Utility.getDateString();				this.createLog();			}			XMLTag tag=new XMLTag("log-content");			XMLAttribute attribute=new XMLAttribute("time",Utility.getTimeString());			XMLElement element=new XMLElement("Data_Item",content);			XMLAttribute exName=new XMLAttribute("source",from);			element.addAttribute(exName);			XMLAttribute act=new XMLAttribute("type",actType);			element.addAttribute(act);			tag.add(attribute);			tag.add(element);			this.out.println(tag.toString());			this.out.flush();			//this.notifyAll();		}catch(Exception ie){			ie.printStackTrace();		}	}*/	public void close(){		try {		/*			ServiceInfo serviceInfo=null;			String content="<log_content type=\"sum\" time=\""+Utility.getTimeString()+"\"><statistics><total_mt>"+Config.mt_recorder_number+"</tota_mt><total_mo>"+Config.mo_recorder_number+"</total_mo>";			for (int i=0;i<Config.subcode_item.size();i++){				serviceInfo=(ServiceInfo)Config.subcode_item.elementAt(i);				content+="<module id=\""+serviceInfo.id+"\"><mt>"+serviceInfo.getMt()+"</mt><mo>"+serviceInfo.getMo()+"</mo></module>";			}			for (int i=0;i<Config.service_id_item.size();i++){				serviceInfo=(ServiceInfo)Config.service_id_item.elementAt(i);				content+="<module id=\""+serviceInfo.id+"\"><mt>"+serviceInfo.getMt()+"</mt><mo>"+serviceInfo.getMo()+"</mo></module>";			}			content+="</statistics></log_content>";			out.println(content);			out.println("</"+this.root+">");		*/			this.out.println("Log Close =====================");			out.close();			this.fout.close();		}catch(IOException ioe){			ioe.printStackTrace();		}	}/*	public static void main(String[] args) {		Log log1 = new Log();		log1.log(new IOException("dfadsfads\r\nfdsalaksdjfalskdf"),"his");		log1.log("dfsdkfladsf");		log1.log("dfjsakdlasdl");		try {		       Thread.sleep(3000);		}catch(Exception e){			e.printStackTrace();		}		log1.close();		log1.log("dfasdfasdssd");	}*/}

⌨️ 快捷键说明

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