Skip to content

Most visited

Recently visited

navigation
Added in API level 1

FileHandler

public class FileHandler
extends StreamHandler

java.lang.Object
   ↳ java.util.logging.Handler
     ↳ java.util.logging.StreamHandler
       ↳ java.util.logging.FileHandler


A FileHandler writes logging records into a specified file or a rotating set of files.

When a set of files is used and a given amount of data has been written to one file, then this file is closed and another file is opened. The name of these files are generated by given name pattern, see below for details. When the files have all been filled the Handler returns to the first and goes through the set again.

By default, the I/O buffering mechanism is enabled, but when each log record is complete, it is flushed out.

XMLFormatter is the default formatter for FileHandler.

FileHandler reads the following LogManager properties for initialization; if a property is not defined or has an invalid value, a default value is used.

Name pattern is a string that may include some special substrings, which will be replaced to generate output files:

Normally, the generation numbers are not larger than the given file count and follow the sequence 0, 1, 2.... If the file count is larger than one, but the generation field("%g") has not been specified in the pattern, then the generation number after a dot will be added to the end of the file name.

The "%u" unique field is used to avoid conflicts and is set to 0 at first. If one FileHandler tries to open the filename which is currently in use by another process, it will repeatedly increment the unique number field and try again. If the "%u" component has not been included in the file name pattern and some contention on a file does occur, then a unique numerical value will be added to the end of the filename in question immediately to the right of a dot. The generation of unique IDs for avoiding conflicts is only guaranteed to work reliably when using a local disk file system.

Summary

Public constructors

FileHandler()

Construct a FileHandler using LogManager properties or their default value.

FileHandler(String pattern)

Constructs a new FileHandler.

FileHandler(String pattern, boolean append)

Construct a new FileHandler.

FileHandler(String pattern, int limit, int count)

Construct a new FileHandler.

FileHandler(String pattern, int limit, int count, boolean append)

Construct a new FileHandler.

Public methods

void close()

Flushes and closes all opened files.

void publish(LogRecord record)

Publish a LogRecord.

Inherited methods

From class java.util.logging.StreamHandler
From class java.util.logging.Handler
From class java.lang.Object

Public constructors

FileHandler

Added in API level 1
FileHandler ()

Construct a FileHandler using LogManager properties or their default value.

Throws
IOException if any I/O error occurs.

FileHandler

Added in API level 1
FileHandler (String pattern)

Constructs a new FileHandler. The given name pattern is used as output filename, the file limit is set to zero (no limit), the file count is set to one; the remaining configuration is done using LogManager properties or their default values. This handler writes to only one file with no size limit.

Parameters
pattern String: the name pattern for the output file.
Throws
IOException if any I/O error occurs.
IllegalArgumentException if the pattern is empty.
NullPointerException if the pattern is null.

FileHandler

Added in API level 1
FileHandler (String pattern, 
                boolean append)

Construct a new FileHandler. The given name pattern is used as output filename, the file limit is set to zero (no limit), the file count is initialized to one and the value of append becomes the new instance's append mode. The remaining configuration is done using LogManager properties. This handler writes to only one file with no size limit.

Parameters
pattern String: the name pattern for the output file.
append boolean: the append mode.
Throws
IOException if any I/O error occurs.
IllegalArgumentException if pattern is empty.
NullPointerException if pattern is null.

FileHandler

Added in API level 1
FileHandler (String pattern, 
                int limit, 
                int count)

Construct a new FileHandler. The given name pattern is used as output filename, the maximum file size is set to limit and the file count is initialized to count. The remaining configuration is done using LogManager properties. This handler is configured to write to a rotating set of count files, when the limit of bytes has been written to one output file, another file will be opened instead.

Parameters
pattern String: the name pattern for the output file.
limit int: the data amount limit in bytes of one output file, can not be negative.
count int: the maximum number of files to use, can not be less than one.
Throws
IOException if any I/O error occurs.
IllegalArgumentException if pattern is empty, limit < 0 or count < 1.
NullPointerException if pattern is null.

FileHandler

Added in API level 1
FileHandler (String pattern, 
                int limit, 
                int count, 
                boolean append)

Construct a new FileHandler. The given name pattern is used as output filename, the maximum file size is set to limit, the file count is initialized to count and the append mode is set to append. The remaining configuration is done using LogManager properties. This handler is configured to write to a rotating set of count files, when the limit of bytes has been written to one output file, another file will be opened instead.

Parameters
pattern String: the name pattern for the output file.
limit int: the data amount limit in bytes of one output file, can not be negative.
count int: the maximum number of files to use, can not be less than one.
append boolean: the append mode.
Throws
IOException if any I/O error occurs.
IllegalArgumentException if pattern is empty, limit < 0 or count < 1.
NullPointerException if pattern is null.

Public methods

close

Added in API level 1
void close ()

Flushes and closes all opened files.

publish

Added in API level 1
void publish (LogRecord record)

Publish a LogRecord.

Parameters
record LogRecord: the log record to publish.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.