Skip to content

Commit bfa9c1a

Browse files
authored
修复启动器未压缩日志的问题 (#3877)
1 parent 9a37d41 commit bfa9c1a

1 file changed

Lines changed: 21 additions & 23 deletions

File tree

  • HMCLCore/src/main/java/org/jackhuang/hmcl/util/logging

HMCLCore/src/main/java/org/jackhuang/hmcl/util/logging/Logger.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,35 +143,33 @@ private void onExit() {
143143
log(Level.WARNING, caller, "Failed to list log files in " + dir, e);
144144
}
145145

146-
if (list.size() <= logRetention) {
147-
return;
148-
}
149-
150-
list.sort((a, b) -> {
151-
int[] v1 = a.getValue();
152-
int[] v2 = b.getValue();
146+
if (list.size() > logRetention) {
147+
list.sort((a, b) -> {
148+
int[] v1 = a.getValue();
149+
int[] v2 = b.getValue();
153150

154-
assert v1.length == v2.length;
151+
assert v1.length == v2.length;
155152

156-
for (int i = 0; i < v1.length; i++) {
157-
int c = Integer.compare(v1[i], v2[i]);
158-
if (c != 0)
159-
return c;
160-
}
153+
for (int i = 0; i < v1.length; i++) {
154+
int c = Integer.compare(v1[i], v2[i]);
155+
if (c != 0)
156+
return c;
157+
}
161158

162-
return 0;
163-
});
159+
return 0;
160+
});
164161

165-
for (int i = 0, end = list.size() - logRetention; i < end; i++) {
166-
Path file = list.get(i).getKey();
162+
for (int i = 0, end = list.size() - logRetention; i < end; i++) {
163+
Path file = list.get(i).getKey();
167164

168-
try {
169-
if (!Files.isSameFile(file, logFile)) {
170-
log(Level.INFO, caller, "Delete old log file " + file, null);
171-
Files.delete(file);
165+
try {
166+
if (!Files.isSameFile(file, logFile)) {
167+
log(Level.INFO, caller, "Delete old log file " + file, null);
168+
Files.delete(file);
169+
}
170+
} catch (IOException e) {
171+
log(Level.WARNING, caller, "Failed to delete log file " + file, e);
172172
}
173-
} catch (IOException e) {
174-
log(Level.WARNING, caller, "Failed to delete log file " + file, e);
175173
}
176174
}
177175
}

0 commit comments

Comments
 (0)