Fix bug FileNotFoundException: target/logger-messages.txt polluting logs
[yangtools.git] / 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);
         }