Class FileManager
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.AbstractManager
-
- org.apache.logging.log4j.core.appender.OutputStreamManager
-
- org.apache.logging.log4j.core.appender.FileManager
-
- All Implemented Interfaces:
java.lang.AutoCloseable,ByteBufferDestination
- Direct Known Subclasses:
RollingFileManager
public class FileManager extends OutputStreamManager
Manages actual File I/O for File Appenders.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classFileManager.FactoryDataFactory Data.private static classFileManager.FileManagerFactoryFactory to create a FileManager.-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractManager
AbstractManager.AbstractFactoryData
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringadvertiseURIprivate booleanattributeViewEnabledprivate intbufferSizeprivate booleancreateOnDemandprivate static FileManager.FileManagerFactoryFACTORYprivate java.lang.StringfileGroupprivate java.lang.StringfileOwnerprivate java.util.Set<java.nio.file.attribute.PosixFilePermission>filePermissionsprivate booleanisAppendprivate booleanisLocking-
Fields inherited from class org.apache.logging.log4j.core.appender.OutputStreamManager
byteBuffer, layout
-
Fields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedFileManager(java.lang.String fileName, java.io.OutputStream os, boolean append, boolean locking, java.lang.String advertiseURI, Layout<? extends java.io.Serializable> layout, boolean writeHeader, java.nio.ByteBuffer buffer)Deprecated.protectedFileManager(java.lang.String fileName, java.io.OutputStream os, boolean append, boolean locking, java.lang.String advertiseURI, Layout<? extends java.io.Serializable> layout, int bufferSize, boolean writeHeader)Deprecated.protectedFileManager(LoggerContext loggerContext, java.lang.String fileName, java.io.OutputStream os, boolean append, boolean locking, boolean createOnDemand, java.lang.String advertiseURI, Layout<? extends java.io.Serializable> layout, boolean writeHeader, java.nio.ByteBuffer buffer)Deprecated.protectedFileManager(LoggerContext loggerContext, java.lang.String fileName, java.io.OutputStream os, boolean append, boolean locking, boolean createOnDemand, java.lang.String advertiseURI, Layout<? extends java.io.Serializable> layout, java.lang.String filePermissions, java.lang.String fileOwner, java.lang.String fileGroup, boolean writeHeader, java.nio.ByteBuffer buffer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.io.OutputStreamcreateOutputStream()protected voidcreateParentDir(java.io.File file)protected voiddefineAttributeView(java.nio.file.Path path)intgetBufferSize()Returns the buffer size to use if the appender was configured with BufferedIO=true, otherwise returns a negative number.java.util.Map<java.lang.String,java.lang.String>getContentFormat()FileManager's content format is specified by:Key: "fileURI" Value: provided "advertiseURI" param.java.lang.StringgetFileGroup()Returns file group if defined and the OS supports POSIX/group file attribute view, null otherwise.static FileManagergetFileManager(java.lang.String fileName, boolean append, boolean locking, boolean bufferedIo, boolean createOnDemand, java.lang.String advertiseUri, Layout<? extends java.io.Serializable> layout, int bufferSize, java.lang.String filePermissions, java.lang.String fileOwner, java.lang.String fileGroup, Configuration configuration)Returns the FileManager.java.lang.StringgetFileName()Returns the name of the File being managed.java.lang.StringgetFileOwner()Returns file owner if defined and the OS supports owner file attribute view, null otherwise.java.util.Set<java.nio.file.attribute.PosixFilePermission>getFilePermissions()Returns POSIX file permissions if defined and the OS supports POSIX file attribute, null otherwise.booleanisAppend()Returns the append status.booleanisAttributeViewEnabled()Returns true if file attribute view enabled for this file manager.booleanisCreateOnDemand()Returns the lazy-create.booleanisLocking()Returns the lock status.protected voidwrite(byte[] bytes, int offset, int length, boolean immediateFlush)Some output streams synchronize writes while others do not.protected voidwriteToDestination(byte[] bytes, int offset, int length)OverridesOutputStreamManager.writeToDestination(byte[], int, int)to add support for file locking.-
Methods inherited from class org.apache.logging.log4j.core.appender.OutputStreamManager
closeOutputStream, drain, flush, flushBuffer, flushDestination, getByteBuffer, getManager, getOutputStream, hasOutputStream, isOpen, releaseSub, setOutputStream, skipFooter, write, write, write, writeBytes, writeBytes, writeFooter, writeHeader
-
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getCount, getLoggerContext, getManager, getManagerCount, getName, getStrSubstitutor, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
-
-
-
-
Field Detail
-
FACTORY
private static final FileManager.FileManagerFactory FACTORY
-
isAppend
private final boolean isAppend
-
createOnDemand
private final boolean createOnDemand
-
isLocking
private final boolean isLocking
-
advertiseURI
private final java.lang.String advertiseURI
-
bufferSize
private final int bufferSize
-
filePermissions
private final java.util.Set<java.nio.file.attribute.PosixFilePermission> filePermissions
-
fileOwner
private final java.lang.String fileOwner
-
fileGroup
private final java.lang.String fileGroup
-
attributeViewEnabled
private final boolean attributeViewEnabled
-
-
Constructor Detail
-
FileManager
@Deprecated protected FileManager(java.lang.String fileName, java.io.OutputStream os, boolean append, boolean locking, java.lang.String advertiseURI, Layout<? extends java.io.Serializable> layout, int bufferSize, boolean writeHeader)Deprecated.
-
FileManager
@Deprecated protected FileManager(java.lang.String fileName, java.io.OutputStream os, boolean append, boolean locking, java.lang.String advertiseURI, Layout<? extends java.io.Serializable> layout, boolean writeHeader, java.nio.ByteBuffer buffer)Deprecated.- Since:
- 2.6
-
FileManager
@Deprecated protected FileManager(LoggerContext loggerContext, java.lang.String fileName, java.io.OutputStream os, boolean append, boolean locking, boolean createOnDemand, java.lang.String advertiseURI, Layout<? extends java.io.Serializable> layout, boolean writeHeader, java.nio.ByteBuffer buffer)
Deprecated.- Since:
- 2.7
-
FileManager
protected FileManager(LoggerContext loggerContext, java.lang.String fileName, java.io.OutputStream os, boolean append, boolean locking, boolean createOnDemand, java.lang.String advertiseURI, Layout<? extends java.io.Serializable> layout, java.lang.String filePermissions, java.lang.String fileOwner, java.lang.String fileGroup, boolean writeHeader, java.nio.ByteBuffer buffer)
- Since:
- 2.9
-
-
Method Detail
-
getFileManager
public static FileManager getFileManager(java.lang.String fileName, boolean append, boolean locking, boolean bufferedIo, boolean createOnDemand, java.lang.String advertiseUri, Layout<? extends java.io.Serializable> layout, int bufferSize, java.lang.String filePermissions, java.lang.String fileOwner, java.lang.String fileGroup, Configuration configuration)
Returns the FileManager.- Parameters:
fileName- The name of the file to manage.append- true if the file should be appended to, false if it should be overwritten.locking- true if the file should be locked while writing, false otherwise.bufferedIo- true if the contents should be buffered as they are written.createOnDemand- true if you want to lazy-create the file (a.k.a. on-demand.)advertiseUri- the URI to use when advertising the filelayout- The layoutbufferSize- buffer size for buffered IOfilePermissions- File permissionsfileOwner- File ownerfileGroup- File groupconfiguration- The configuration.- Returns:
- A FileManager for the File.
-
createOutputStream
protected java.io.OutputStream createOutputStream() throws java.io.IOException- Overrides:
createOutputStreamin classOutputStreamManager- Throws:
java.io.IOException
-
createParentDir
protected void createParentDir(java.io.File file)
-
defineAttributeView
protected void defineAttributeView(java.nio.file.Path path)
-
write
protected void write(byte[] bytes, int offset, int length, boolean immediateFlush)Description copied from class:OutputStreamManagerSome output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.- Overrides:
writein classOutputStreamManager- Parameters:
bytes- The serialized Log event.offset- The offset into the byte array.length- The number of bytes to write.immediateFlush- flushes immediately after writing.
-
writeToDestination
protected void writeToDestination(byte[] bytes, int offset, int length)OverridesOutputStreamManager.writeToDestination(byte[], int, int)to add support for file locking.- Overrides:
writeToDestinationin classOutputStreamManager- Parameters:
bytes- the array containing dataoffset- from where to writelength- how many bytes to write- Since:
- 2.8
-
getFileName
public java.lang.String getFileName()
Returns the name of the File being managed.- Returns:
- The name of the File being managed.
-
isAppend
public boolean isAppend()
Returns the append status.- Returns:
- true if the file will be appended to, false if it is overwritten.
-
isCreateOnDemand
public boolean isCreateOnDemand()
Returns the lazy-create.- Returns:
- true if the file will be lazy-created.
-
isLocking
public boolean isLocking()
Returns the lock status.- Returns:
- true if the file will be locked when writing, false otherwise.
-
getBufferSize
public int getBufferSize()
Returns the buffer size to use if the appender was configured with BufferedIO=true, otherwise returns a negative number.- Returns:
- the buffer size, or a negative number if the output stream is not buffered
-
getFilePermissions
public java.util.Set<java.nio.file.attribute.PosixFilePermission> getFilePermissions()
Returns POSIX file permissions if defined and the OS supports POSIX file attribute, null otherwise.- Returns:
- File POSIX permissions
- See Also:
PosixFileAttributeView
-
getFileOwner
public java.lang.String getFileOwner()
Returns file owner if defined and the OS supports owner file attribute view, null otherwise.- Returns:
- File owner
- See Also:
FileOwnerAttributeView
-
getFileGroup
public java.lang.String getFileGroup()
Returns file group if defined and the OS supports POSIX/group file attribute view, null otherwise.- Returns:
- File group
- See Also:
PosixFileAttributeView
-
isAttributeViewEnabled
public boolean isAttributeViewEnabled()
Returns true if file attribute view enabled for this file manager.- Returns:
- True if POSIX or owner supported and defined false otherwise.
-
getContentFormat
public java.util.Map<java.lang.String,java.lang.String> getContentFormat()
FileManager's content format is specified by:Key: "fileURI" Value: provided "advertiseURI" param.- Overrides:
getContentFormatin classAbstractManager- Returns:
- Map of content format keys supporting FileManager
-
-