Fix bug FileNotFoundException: target/logger-messages.txt polluting logs 71/42071/2
authorMichael Vorburger <vorburger@redhat.com>
Tue, 19 Jul 2016 17:05:46 +0000 (19:05 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Tue, 19 Jul 2016 17:10:48 +0000 (19:10 +0200)
Change-Id: I1f9bfd493d1554b4d081738c7bb6e4a30fa19290
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/LogMessageExtractorCheck.java

index 6041d927485b03f95d9c7bbe788a16645ff3cad1..8b223f261b654c86fbb04ccd06249d2fac605e7f 100644 (file)
@@ -55,7 +55,12 @@ public class LogMessageExtractorCheck extends AbstractLogMessageCheck {
 
     protected void updateMessagesReportFile(LogMessageOccurence log) {
         try {
-            Files.append(log.toString() + "\n", getLogMessagesReportFile(), StandardCharsets.UTF_8);
+            final File file = getLogMessagesReportFile();
+            if (file.exists()) {
+                Files.append(log.toString() + "\n", file, StandardCharsets.UTF_8);
+            } else {
+                Files.write(log.toString() + "\n", file, StandardCharsets.UTF_8);
+            }
         } catch (IOException e) {
             LOG.error("Failed to append to file: {}", logMessagesReportFile.getPath(), e);
         }