Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/changelog/.2.x.x/add_FileManager_getPath_.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="added">
<description format="asciidoc">Add org.apache.logging.log4j.core.appender.FileManager.getPath().</description>
</entry>
Loading