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 46123ce074a..d8d5ccfd06e 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 @@ -246,19 +246,20 @@ public static FileManager getFileManager( protected OutputStream createOutputStream() throws IOException { final String filename = getFileName(); LOGGER.debug("Now writing to {} at {}", filename, new Date()); - final File file = new File(filename); + final Path path = getPath(); + final File file = path.toFile(); createParentDir(file); final FileOutputStream fos = new FileOutputStream(file, isAppend); if (file.exists() && file.length() == 0) { try { final FileTime now = FileTime.fromMillis(System.currentTimeMillis()); - Files.setAttribute(file.toPath(), "creationTime", now); + Files.setAttribute(path, "creationTime", now); } catch (Exception ex) { LOGGER.warn("Unable to set current file time for {}", filename); } writeHeader(fos); } - defineAttributeView(Paths.get(filename)); + defineAttributeView(path); return fos; } @@ -343,6 +344,16 @@ protected synchronized void writeToDestination(final byte[] bytes, final int off public String getFileName() { return getName(); } + + /** + * Returns the Path of the file being managed. + * @return The name of the file being managed. + * @since 2.26.0 + */ + public Path getPath() { + return Paths.get(getFileName()); + } + /** * Returns the append status. * @return true if the file will be appended to, false if it is overwritten. diff --git a/src/changelog/.2.x.x/add_FileManager_getPath_.xml b/src/changelog/.2.x.x/add_FileManager_getPath_.xml new file mode 100644 index 00000000000..b5cbf716e26 --- /dev/null +++ b/src/changelog/.2.x.x/add_FileManager_getPath_.xml @@ -0,0 +1,7 @@ + + + Add org.apache.logging.log4j.core.appender.FileManager.getPath(). +