Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #517 #556

Merged
merged 1 commit into from Feb 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/main/java/run/halo/app/service/impl/AdminServiceImpl.java
Expand Up @@ -45,6 +45,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -473,6 +475,8 @@ public String getLogFiles(Long lines) {

File file = new File(haloProperties.getWorkDir(), LOG_PATH);

List<String> linesArray = new ArrayList<>();

StringBuilder result = new StringBuilder();

if (!file.exists()) {
Expand All @@ -493,8 +497,7 @@ public String getLogFiles(Long lines) {
randomAccessFile.seek(pos);
if (randomAccessFile.readByte() == '\n') {
String line = randomAccessFile.readLine();
result.append(new String(line.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
result.append(StringUtils.LF);
linesArray.add(new String(line.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
count++;
if (count == lines) {
break;
Expand All @@ -503,8 +506,7 @@ public String getLogFiles(Long lines) {
}
if (pos == 0) {
randomAccessFile.seek(0);
result.append(new String(randomAccessFile.readLine().getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
result.append(StringUtils.LF);
linesArray.add(new String(randomAccessFile.readLine().getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
}
}
} catch (Exception e) {
Expand All @@ -518,6 +520,14 @@ public String getLogFiles(Long lines) {
}
}
}

Collections.reverse(linesArray);

linesArray.forEach(line -> {
result.append(line)
.append(StringUtils.LF);
});

return result.toString();
}
}