Skip to content

Commit

Permalink
Fix Modify the log queue traversal method (#9953)
Browse files Browse the repository at this point in the history
  • Loading branch information
106umao committed Apr 29, 2022
1 parent b31eafc commit ca800bf
Showing 1 changed file with 8 additions and 10 deletions.
Expand Up @@ -141,7 +141,6 @@ private void writeLogQueueToFile(String accessLog, Queue<AccessLogData> logQueue
processWithAccessKeyLogger(logQueue, file);
}
} catch (Exception e) {
logQueue.poll();
logger.error(e.getMessage(), e);
}
}
Expand All @@ -157,22 +156,21 @@ private void writeLogToFile() {
}

private void processWithAccessKeyLogger(Queue<AccessLogData> logQueue, File file) throws IOException {
try (FileWriter writer = new FileWriter(file, true)) {
for (Iterator<AccessLogData> iterator = logQueue.iterator();
iterator.hasNext();
iterator.remove()) {
writer.write(iterator.next().getLogMessage());
FileWriter writer = new FileWriter(file, true);
try {
while (!logQueue.isEmpty()) {
writer.write(logQueue.poll().getLogMessage());
writer.write(System.getProperty(LINE_SEPARATOR));
}
}finally {
writer.flush();
writer.close();
}
}

private void processWithServiceLogger(Queue<AccessLogData> logQueue) {
for (Iterator<AccessLogData> iterator = logQueue.iterator();
iterator.hasNext();
iterator.remove()) {
AccessLogData logData = iterator.next();
while (!logQueue.isEmpty()) {
AccessLogData logData = logQueue.poll();
LoggerFactory.getLogger(LOG_KEY + "." + logData.getServiceName()).info(logData.getLogMessage());
}
}
Expand Down

0 comments on commit ca800bf

Please sign in to comment.