Android
java.util.logging
public class

java.util.logging.FileHandler

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

A Handler writes description of logging event into a specified file or a rotating set of files.

If a set of files are used, when a given amount of data has been written to one file, this file is closed, and another file is opened. The name of these files are generated by given name pattern, see below for details.

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

XMLFormatter is default formatter for FileHandler.

MemoryHandler will read following LogManager properties for initialization, if given properties are not defined or has invalid values, default value will be used.

  • java.util.logging.FileHandler.level specifies the level for this Handler, defaults to Level.ALL.
  • java.util.logging.FileHandler.filter specifies the Filter class name, defaults to no Filter.
  • java.util.logging.FileHandler.formatter specifies the Formatter class, defaults to java.util.logging.XMLFormatter.
  • java.util.logging.FileHandler.encoding specifies the character set encoding name, defaults to the default platform encoding.
  • java.util.logging.FileHandler.limit specifies an maximum bytes to write to any one file, defaults to zero, which means no limit.
  • java.util.logging.FileHandler.count specifies how many output files to rotate, defaults to 1.
  • java.util.logging.FileHandler.pattern specifies name pattern for the output files. See below for details. Defaults to "%h/java%u.log".
  • java.util.logging.FileHandler.append specifies whether this FileHandler should append onto existing files, defaults to false.

Name pattern is a string that may includes some special sub-strings, which will be replaced to generate output files:

  • "/" represents the local pathname separator
  • "%t" represents the system temporary directory
  • "%h" represents the home directory of current user, which is specified by "user.home" system property
  • "%g" represents the generation number to distinguish rotated logs
  • "%u" represents a unique number to resolve conflicts
  • "%%" represents percent sign character '%'

Normally, the generation numbers are not larger than 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 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 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)
Construct a FileHandler, the given name pattern is used as output filename, the file limit is set to zero(no limit), and the file count is set to one, other configuration using LogManager properties or their default value This handler write to only one file and no amount limit.
            FileHandler(String pattern, boolean append)
Construct a FileHandler, the given name pattern is used as output filename, the file limit is set to zero(i.e.
            FileHandler(String pattern, int limit, int count)
Construct a FileHandler, the given name pattern is used as output filename, the file limit is set to given limit argument, and the file count is set to given count argument, other configuration using LogManager properties or their default value 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.
            FileHandler(String pattern, int limit, int count, boolean append)
Construct a FileHandler, the given name pattern is used as output filename, the file limit is set to given limit argument, the file count is set to given count argument, and the append mode is set to given append argument, other configuration using LogManager properties or their default value 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.

Public Methods

          void  close()
Flush and close all opened files.
          void  publish(LogRecord record)
Publish a LogRecord
Methods inherited from class java.util.logging.StreamHandler
Methods inherited from class java.util.logging.Handler
Methods inherited from class java.lang.Object

Details

Public Constructors

public FileHandler()

Construct a FileHandler using LogManager properties or their default value

Throws

IOException if any IO exception happened
SecurityException if security manager exists and it determines that caller does not have the required permissions to control this handler, required permissions include LogPermission("control") and other permission like FilePermission("write"), etc.

public FileHandler(String pattern)

Construct a FileHandler, the given name pattern is used as output filename, the file limit is set to zero(no limit), and the file count is set to one, other configuration using LogManager properties or their default value This handler write to only one file and no amount limit.

Parameters

pattern the name pattern of output file

Throws

IOException if any IO exception happened
SecurityException if security manager exists and it determines that caller does not have the required permissions to control this handler, required permissions include LogPermission("control") and other permission like FilePermission("write"), etc.
NullPointerException if the pattern is null.
IllegalArgumentException if the pattern is empty.

public FileHandler(String pattern, boolean append)

Construct a FileHandler, the given name pattern is used as output filename, the file limit is set to zero(i.e. no limit applies), the file count is initialized to one, and the value of append becomes the new instance's append mode. Other configuration is done using LogManager properties. This handler write to only one file and no amount limit.

Parameters

pattern the name pattern of output file
append the append mode

Throws

IOException if any IO exception happened
SecurityException if security manager exists and it determines that caller does not have the required permissions to control this handler, required permissions include LogPermission("control") and other permission like FilePermission("write"), etc.
NullPointerException if the pattern is null.
IllegalArgumentException if the pattern is empty.

public FileHandler(String pattern, int limit, int count)

Construct a FileHandler, the given name pattern is used as output filename, the file limit is set to given limit argument, and the file count is set to given count argument, other configuration using LogManager properties or their default value 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 the name pattern of output file
limit the data amount limit in bytes of one output file, cannot less than one
count the maximum number of files can be used, cannot less than one

Throws

IOException if any IO exception happened
SecurityException if security manager exists and it determines that caller does not have the required permissions to control this handler, required permissions include LogPermission("control") and other permission like FilePermission("write"), etc.
NullPointerException if pattern is null.
IllegalArgumentException if count<1, or limit<0

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

Construct a FileHandler, the given name pattern is used as output filename, the file limit is set to given limit argument, the file count is set to given count argument, and the append mode is set to given append argument, other configuration using LogManager properties or their default value 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 the name pattern of output file
limit the data amount limit in bytes of one output file, cannot less than one
count the maximum number of files can be used, cannot less than one
append the append mode

Throws

IOException if any IO exception happened
SecurityException if security manager exists and it determines that caller does not have the required permissions to control this handler, required permissions include LogPermission("control") and other permission like FilePermission("write"), etc.
NullPointerException if pattern is null.
IllegalArgumentException if count<1, or limit<0

Public Methods

public void close()

Flush and close all opened files.

Throws

SecurityException if security manager exists and it determines that caller does not have the required permissions to control this handler, required permissions include LogPermission("control") and other permission like FilePermission("write"), etc.

public void publish(LogRecord record)

Publish a LogRecord

Parameters

record the log record to be published
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56