Merge pull request #1576 from adyliu/master

read less than 1MiB & 10000 lines of log file
pull/72/head
许雪里 2 months ago committed by GitHub
commit 497fd65122
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -5,6 +5,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -151,16 +152,25 @@ public class XxlJobFileAppender {
StringBuffer logContentBuffer = new StringBuffer();
int toLineNum = 0;
LineNumberReader reader = null;
boolean isEnd = false;
try {
//reader = new LineNumberReader(new FileReader(logFile));
reader = new LineNumberReader(new InputStreamReader(new FileInputStream(logFile), "utf-8"));
String line = null;
long totalSize = 0;
while ((line = reader.readLine())!=null) {
toLineNum = reader.getLineNumber(); // [from, to], start as 1
if (toLineNum >= fromLineNum) {
logContentBuffer.append(line).append("\n");
}
totalSize += line.getBytes(StandardCharsets.UTF_8).length;
//read less than 1MiB & 10000 lines to hold on the netty or jvm memory
if(toLineNum > 10000 || totalSize > 1024*1024) {
logContentBuffer.append("******************** FILE IS TOO LARGE ********************");
isEnd = true;
break;
}
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
@ -175,7 +185,7 @@ public class XxlJobFileAppender {
}
// result
LogResult logResult = new LogResult(fromLineNum, toLineNum, logContentBuffer.toString(), false);
LogResult logResult = new LogResult(fromLineNum, toLineNum, logContentBuffer.toString(), isEnd);
return logResult;
/*

Loading…
Cancel
Save