You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2019/06/02 22:28:36 UTC

[logging-log4j2] branch master updated: LOG4J2-2610 - Only update creation time if flie size is 0

This is an automated email from the ASF dual-hosted git repository.

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new 51ace0a  LOG4J2-2610 - Only update creation time if flie size is 0
51ace0a is described below

commit 51ace0af494ec3eafd2163b162692bae06653062
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sun Jun 2 15:28:26 2019 -0700

    LOG4J2-2610 - Only update creation time if flie size is 0
---
 .../org/apache/logging/log4j/core/appender/FileManager.java  | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
index 4a5866d..9e86139 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
@@ -139,11 +139,13 @@ public class FileManager extends OutputStreamManager {
         LOGGER.debug("Now writing to {} at {}", filename, new Date());
         final File file = new File(filename);
         final FileOutputStream fos = new FileOutputStream(file, isAppend);
-        try {
-            FileTime now = FileTime.fromMillis(System.currentTimeMillis());
-            Files.setAttribute(file.toPath(), "creationTime", now);
-        } catch (Exception ex) {
-            LOGGER.warn("Unable to set current file tiem for {}", filename);
+        if (file.exists() && file.length() == 0) {
+            try {
+                FileTime now = FileTime.fromMillis(System.currentTimeMillis());
+                Files.setAttribute(file.toPath(), "creationTime", now);
+            } catch (Exception ex) {
+                LOGGER.warn("Unable to set current file tiem for {}", filename);
+            }
         }
         defineAttributeView(Paths.get(filename));
         return fos;