mirror of https://github.com/halo-dev/halo
fix: Incorrect sequence of tailing log file#517 (#556)
parent
491ff98916
commit
028268c698
|
@ -45,6 +45,8 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -473,6 +475,8 @@ public class AdminServiceImpl implements AdminService {
|
||||||
|
|
||||||
File file = new File(haloProperties.getWorkDir(), LOG_PATH);
|
File file = new File(haloProperties.getWorkDir(), LOG_PATH);
|
||||||
|
|
||||||
|
List<String> linesArray = new ArrayList<>();
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
|
@ -493,8 +497,7 @@ public class AdminServiceImpl implements AdminService {
|
||||||
randomAccessFile.seek(pos);
|
randomAccessFile.seek(pos);
|
||||||
if (randomAccessFile.readByte() == '\n') {
|
if (randomAccessFile.readByte() == '\n') {
|
||||||
String line = randomAccessFile.readLine();
|
String line = randomAccessFile.readLine();
|
||||||
result.append(new String(line.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
|
linesArray.add(new String(line.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
|
||||||
result.append(StringUtils.LF);
|
|
||||||
count++;
|
count++;
|
||||||
if (count == lines) {
|
if (count == lines) {
|
||||||
break;
|
break;
|
||||||
|
@ -503,8 +506,7 @@ public class AdminServiceImpl implements AdminService {
|
||||||
}
|
}
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
randomAccessFile.seek(0);
|
randomAccessFile.seek(0);
|
||||||
result.append(new String(randomAccessFile.readLine().getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
|
linesArray.add(new String(randomAccessFile.readLine().getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
|
||||||
result.append(StringUtils.LF);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -518,6 +520,14 @@ public class AdminServiceImpl implements AdminService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Collections.reverse(linesArray);
|
||||||
|
|
||||||
|
linesArray.forEach(line -> {
|
||||||
|
result.append(line)
|
||||||
|
.append(StringUtils.LF);
|
||||||
|
});
|
||||||
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue