File appenders
Log4j Core provides multiple appenders that store log messages in a file. These appenders differ in the way they access the file system and might provide different performance characteristics.
File appenders do not offer a mechanism for external applications to force it to reopen the log file.
External log archiving tools such as
If you want to rotate your log files, use a rolling file appender instead. |
Appenders
Log4j Core provides three file appender implementations:
File
-
The
File
Appender usesFileOutputStream
to access log files. RandomAccessFile
-
The
RandomAccessFile
Appender usesRandomAccessFile
to access log files. MemoryMappedFile
-
The
MemoryMappedFile
Appender maps log files into aMappedByteBuffer
.Instead of making system calls to write to disk, this appender can simply change the program’s local memory, which is orders of magnitude faster.
Two appenders, even from different logger contexts, share a common
Sharing a |
Common configuration
Attribute | Type | Default value | Description |
---|---|---|---|
Required |
|||
The path to the current log file If the folder containing the file does not exist, it will be created. |
|||
|
The name of the appender. |
||
Optional |
|||
|
The size of the
See Buffering for more details. |
||
|
|
If Logging exceptions are always also logged to Status Logger |
|
|
|
If set to See Buffering for more details. |
Type | Multiplicity | Description |
---|---|---|
zero or one |
Allows filtering log events just before they are formatted and sent. See also appender filtering stage. |
|
zero or one |
Formats log events. See Layouts for more information. |
File
configuration
The File
Appender provides the following configuration options, beyond the common ones:
Attribute | Type | Default value | Description |
---|---|---|---|
|
|
If On most systems this guarantees atomic writes to the end of the file, even if the file is opened by multiple applications. |
|
|
|
If set to See Buffering for more details. |
|
boolean |
|
The appender creates the file on-demand. The appender only creates the file when a log event passes all filters and is routed to this appender. Defaults to false. |
|
|
If not The underlying files system shall support POSIX file attribute view. |
||
|
|
If not The underlying files system shall support file owner attribute view. |
|
|
|
If not The underlying files system shall support POSIX file attribute view. |
|
|
|
If Note that the effects of this setting depend on the Operating System: some systems like most POSIX OSes do not offer mandatory locking, but only advisory file locking. This setting can also reduce the performance of the appender. |
RandomAccessFile
configuration
The RandomAccessFile
Appender provides the following configuration options, beyond the common ones:
Attribute | Type | Default value | Description |
---|---|---|---|
|
|
If This setting does not give the same atomicity guarantees as for the
|
Unlike the File
appender, this appender always uses an internal buffer of size bufferSize
.
MemoryMappedFile
configuration
The MemoryMappedFile
Appender provides the following configuration options, beyond the common ones:
Attribute | Type | Default value | Description |
---|---|---|---|
|
|
If This setting does not give the same atomicity guarantees as for the
|
|
|
|
It specifies the size measured in bytes of the memory mapped log file buffer. |
Unlike other file appenders, this appender always uses a memory mapped buffer of size regionLength
as its internal buffer.