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

📄 mabstractlogger.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
字号:
package net.jumperz.app.MBitDog;

import java.io.*;
import java.util.regex.*;
import java.text.*;
import net.jumperz.util.*;
import java.util.*;

public abstract class MAbstractLogger
{
protected String fileName;
protected Pattern pattern;
protected boolean negationFlag = false;
protected int rotate;
protected boolean eat;
protected String suffix;
protected String command;

protected String currentLogFileName;
OutputStream stream;
int suffixIndex;

public abstract void log( String line ) throws IOException;
protected abstract void reset();
//--------------------------------------------------------------------------------
public void cleanUp()
{
try
	{
	if( stream != null )
		{
		stream.flush();
		stream.close();
		}
	execCommand();
	}
catch( IOException e )
	{
	e.printStackTrace();
	}
}
//--------------------------------------------------------------------------------
private void execCommand()
throws IOException
{
if( !command.equals( "none" ) 
 && !command.equals( "" )
  )
	{
	Runtime.getRuntime().exec( command + " " + currentLogFileName );
	}
}
//--------------------------------------------------------------------------------
protected void rotateLogFile()
throws IOException
{
stream.close();
execCommand();
rotateStream();

suffixIndex++;
reset();
}
//--------------------------------------------------------------------------------
protected void rotateStream()
throws IOException
{
DecimalFormat format = new DecimalFormat( suffix );

	// determine the filename
for( ;;++suffixIndex )
	{
	String suffixStr = format.format( suffixIndex );
	currentLogFileName = fileName + "." + suffixStr;
	File file = new File( currentLogFileName );
	String shortFileName = file.getName();
	File dir = file.getParentFile();
	String[] fileList = dir.list();

	boolean exists = false;
	int len = shortFileName.length();
	for( int i = 0; i < fileList.length; ++i )
		{
		if( fileList[ i ].length() >= len )
			{
			String tmpFileName = fileList[ i ].substring( 0, len );
			if( tmpFileName.equalsIgnoreCase( shortFileName ) )
				{
				exists = true;
				break;
				}
			}
		}

	if( exists == false )
		{
		break;
		}
	}

	//open stream
stream = new BufferedOutputStream( new FileOutputStream( currentLogFileName ) );
}
//--------------------------------------------------------------------------------
public final boolean match( String line )
{
Matcher matcher = pattern.matcher( line );
boolean match = matcher.find();
return ( match != negationFlag );
}
//--------------------------------------------------------------------------------
public final void setPattern( String patternStr, boolean ignoreCase )
{
if( ignoreCase )
	{
	pattern = Pattern.compile( patternStr, Pattern.CASE_INSENSITIVE );
	}
else
	{
	pattern = Pattern.compile( patternStr );
	}
}
//--------------------------------------------------------------------------------
public String getCommand() {
	return command;
}

public boolean isEater() {
	return eat;
}

public String getFileName() {
	return fileName;
}

public int getRotate() {
	return rotate;
}

public boolean isNegationFlag() {
	return negationFlag;
}

public String getSuffix() {
	return suffix;
}

public void setCommand(String string) {
	command = string;
}

public void setEat(boolean b) {
	eat = b;
}

public void setFileName(String string) {
	fileName = string;
}

public void setRotate(int i) {
	rotate = i;
}

public void setNegationFlag(boolean b) {
	negationFlag = b;
}

public void setSuffix(String string) {
	suffix = string;
}

}

⌨️ 快捷键说明

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