filelog.java

来自「短信网关发送接受平台。」· Java 代码 · 共 79 行

JAVA
79
字号
import java.util.*;
import java.io.*;

import LogRequest;

public class FileLog
{
	static FileLog m_filelog = null;
	
	FileOutputStream m_fos = null;
	PrintStream m_ps = null;
	
	private FileLog(String strFileName)
		throws IOException
	{
		m_fos = new FileOutputStream(strFileName);
		m_ps = new PrintStream(m_fos);
	}
	
	private void log(LogRequest lr,String strLine)
	{
		if(strLine != null && strLine.length() > 0)
		{
			m_ps.println(strLine);
		}
	}
	
	private void close()
	{
		if(m_ps != null)
		{
			m_ps.close();
		}
	}

	public static boolean openLog(String strFileName)
	{
		try
		{
			m_filelog = new FileLog(strFileName);
		}
		catch(Exception e)
		{
			System.out.println(e);
			System.out.println("FileLog.openLog : unexpected exit !");

			m_filelog = null;
			return false;
		}
		
		return true;
	}
	
	public static synchronized void log(LogRequest lr,String strLine,long lLogRequests)
	{
		if(m_filelog != null && lr.isRequested(lLogRequests))
		{
			if(lr.isRequested(LogRequest.LOG_TIME))
			{
				long lCurrTime = System.currentTimeMillis();
				Date date = new Date(lCurrTime);
				
				m_filelog.log(lr,date.toLocaleString() + ">" + strLine);
			}
			else
			{			
				m_filelog.log(lr,strLine);
			}
		}
	}
	
	public static void closeLog()
	{
		if(m_filelog != null)
		{
			m_filelog.close();
		}
	}
}

⌨️ 快捷键说明

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