|  | @@ -1,5 +1,6 @@
 | 
	
		
			
				|  |  |  package com.xxl.job.core.log;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.xxl.job.core.biz.model.LogResult;
 | 
	
		
			
				|  |  |  import org.apache.log4j.AppenderSkeleton;
 | 
	
		
			
				|  |  |  import org.apache.log4j.Layout;
 | 
	
		
			
				|  |  |  import org.apache.log4j.spi.LoggingEvent;
 | 
	
	
		
			
				|  | @@ -117,8 +118,9 @@ public class XxlJobFileAppender extends AppenderSkeleton {
 | 
	
		
			
				|  |  |  	 * @param logFileName
 | 
	
		
			
				|  |  |  	 * @return log content
 | 
	
		
			
				|  |  |  	 */
 | 
	
		
			
				|  |  | -	public static String readLog(String logFileName ){
 | 
	
		
			
				|  |  | +	public static LogResult readLog(String logFileName, int fromLineNum){
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +		// valid log file
 | 
	
		
			
				|  |  |  		if (logFileName==null || logFileName.trim().length()==0) {
 | 
	
		
			
				|  |  |  			return null;
 | 
	
		
			
				|  |  |  		}
 | 
	
	
		
			
				|  | @@ -127,27 +129,20 @@ public class XxlJobFileAppender extends AppenderSkeleton {
 | 
	
		
			
				|  |  |  		if (!logFile.exists()) {
 | 
	
		
			
				|  |  |  			return null;
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -		
 | 
	
		
			
				|  |  | -		String logData = readLines(logFile);
 | 
	
		
			
				|  |  | -		return logData;
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	/**
 | 
	
		
			
				|  |  | -	 * read log data
 | 
	
		
			
				|  |  | -	 * @param logFile
 | 
	
		
			
				|  |  | -	 * @return log line content
 | 
	
		
			
				|  |  | -	 */
 | 
	
		
			
				|  |  | -	public static String readLines(File logFile){
 | 
	
		
			
				|  |  | -		BufferedReader reader = null;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		// read file
 | 
	
		
			
				|  |  | +		StringBuffer logContentBuffer = new StringBuffer();
 | 
	
		
			
				|  |  | +		int toLineNum = 0;
 | 
	
		
			
				|  |  | +		LineNumberReader reader = null;
 | 
	
		
			
				|  |  |  		try {
 | 
	
		
			
				|  |  | -			reader = new BufferedReader(new InputStreamReader(new FileInputStream(logFile), "utf-8"));
 | 
	
		
			
				|  |  | -			if (reader != null) {
 | 
	
		
			
				|  |  | -				StringBuilder sb = new StringBuilder();
 | 
	
		
			
				|  |  | -				String line = null;
 | 
	
		
			
				|  |  | -				while ((line = reader.readLine()) != null) {
 | 
	
		
			
				|  |  | -					sb.append(line).append("\n");
 | 
	
		
			
				|  |  | +			reader = new LineNumberReader(new FileReader(logFile));
 | 
	
		
			
				|  |  | +			String line = null;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +			while ((line = reader.readLine())!=null) {
 | 
	
		
			
				|  |  | +				toLineNum++;
 | 
	
		
			
				|  |  | +				if (reader.getLineNumber() >= fromLineNum) {
 | 
	
		
			
				|  |  | +					logContentBuffer.append(line).append("\n");
 | 
	
		
			
				|  |  |  				}
 | 
	
		
			
				|  |  | -				return sb.toString();
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  		} catch (IOException e) {
 | 
	
		
			
				|  |  |  			e.printStackTrace();
 | 
	
	
		
			
				|  | @@ -159,35 +154,41 @@ public class XxlJobFileAppender extends AppenderSkeleton {
 | 
	
		
			
				|  |  |  					e.printStackTrace();
 | 
	
		
			
				|  |  |  				}
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  | -		} 
 | 
	
		
			
				|  |  | -		return null;
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		// result
 | 
	
		
			
				|  |  | +		LogResult logResult = new LogResult();
 | 
	
		
			
				|  |  | +		logResult.setFromLineNum(fromLineNum);
 | 
	
		
			
				|  |  | +		logResult.setToLineNum(toLineNum);
 | 
	
		
			
				|  |  | +		logResult.setLogContent(logContentBuffer.toString());
 | 
	
		
			
				|  |  | +		logResult.setEnd(false);
 | 
	
		
			
				|  |  | +		return logResult;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		/*
 | 
	
		
			
				|  |  | +        // it will return the number of characters actually skipped
 | 
	
		
			
				|  |  | +        reader.skip(Long.MAX_VALUE);
 | 
	
		
			
				|  |  | +        int maxLineNum = reader.getLineNumber();
 | 
	
		
			
				|  |  | +        maxLineNum++;	// 最大行号
 | 
	
		
			
				|  |  | +        */
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	/**
 | 
	
		
			
				|  |  | -	 * read data from line num
 | 
	
		
			
				|  |  | +	 * read log data
 | 
	
		
			
				|  |  |  	 * @param logFile
 | 
	
		
			
				|  |  | -	 * @param fromLineNum
 | 
	
		
			
				|  |  | -	 * @return log content
 | 
	
		
			
				|  |  | -	 * @throws Exception
 | 
	
		
			
				|  |  | +	 * @return log line content
 | 
	
		
			
				|  |  |  	 */
 | 
	
		
			
				|  |  | -	public static String readLinesFrom(File logFile, int fromLineNum) {  
 | 
	
		
			
				|  |  | -        LineNumberReader reader = null;
 | 
	
		
			
				|  |  | +	public static String readLines(File logFile){
 | 
	
		
			
				|  |  | +		BufferedReader reader = null;
 | 
	
		
			
				|  |  |  		try {
 | 
	
		
			
				|  |  | -			reader = new LineNumberReader(new FileReader(logFile));
 | 
	
		
			
				|  |  | -			
 | 
	
		
			
				|  |  | -			// sBuffer
 | 
	
		
			
				|  |  | -	        StringBuffer sBuffer = new StringBuffer();
 | 
	
		
			
				|  |  | -	    	String line = null;
 | 
	
		
			
				|  |  | -	    	int maxLineNum = 0;
 | 
	
		
			
				|  |  | -	    	while ((line = reader.readLine())!=null) {
 | 
	
		
			
				|  |  | -	    		maxLineNum++;
 | 
	
		
			
				|  |  | -	    		if (reader.getLineNumber() >= fromLineNum) {
 | 
	
		
			
				|  |  | -	    			sBuffer.append(line).append("\n");
 | 
	
		
			
				|  |  | +			reader = new BufferedReader(new InputStreamReader(new FileInputStream(logFile), "utf-8"));
 | 
	
		
			
				|  |  | +			if (reader != null) {
 | 
	
		
			
				|  |  | +				StringBuilder sb = new StringBuilder();
 | 
	
		
			
				|  |  | +				String line = null;
 | 
	
		
			
				|  |  | +				while ((line = reader.readLine()) != null) {
 | 
	
		
			
				|  |  | +					sb.append(line).append("\n");
 | 
	
		
			
				|  |  |  				}
 | 
	
		
			
				|  |  | +				return sb.toString();
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  | -	    	
 | 
	
		
			
				|  |  | -	    	System.out.println("maxLineNum : " + maxLineNum);
 | 
	
		
			
				|  |  | -	    	return sBuffer.toString();
 | 
	
		
			
				|  |  |  		} catch (IOException e) {
 | 
	
		
			
				|  |  |  			e.printStackTrace();
 | 
	
		
			
				|  |  |  		} finally {
 | 
	
	
		
			
				|  | @@ -198,16 +199,8 @@ public class XxlJobFileAppender extends AppenderSkeleton {
 | 
	
		
			
				|  |  |  					e.printStackTrace();
 | 
	
		
			
				|  |  |  				}
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -		
 | 
	
		
			
				|  |  | +		} 
 | 
	
		
			
				|  |  |  		return null;
 | 
	
		
			
				|  |  | -		
 | 
	
		
			
				|  |  | -        /*
 | 
	
		
			
				|  |  | -        // it will return the number of characters actually skipped
 | 
	
		
			
				|  |  | -        reader.skip(Long.MAX_VALUE);	
 | 
	
		
			
				|  |  | -        int maxLineNum = reader.getLineNumber();  
 | 
	
		
			
				|  |  | -        maxLineNum++;	// 最大行号
 | 
	
		
			
				|  |  | -        */
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |