Class FileHandler


  • public class FileHandler
    extends Handler
    This FileHandler is very much similar to the java.util.logging.FileHandler .

    The FileHandler can either write to a specified file, or it can write to a rotating set of files.

    For a rotating set of files, as each file reaches the limit ( LogConstants.MAX_FILE_SIZE), it is closed, rotated out, and a new file opened. Successively older files and named by adding "-1", "-2", etc., * to the base filename. The Locking mechanism is much more relaxed (in JDK's FileHandler an exclusive lock is created on the file till the handler is closed which makes reading impossible)

    • Constructor Detail

      • FileHandler

        public FileHandler​(String fileName)
        Creates a new FileHandler. It takes a string parameter which represents file name. When this constructor is called a new file to be created. Assuming that the fileName logger provides is the timestamped fileName.
        Parameters:
        fileName - The filename associate with file handler.
    • Method Detail

      • setEncoding

        public void setEncoding​(String encoding)
                         throws SecurityException,
                                UnsupportedEncodingException
        Set (or change) the character encoding used by this Handler. The encoding should be set before any LogRecords are written to the Handler.
        Overrides:
        setEncoding in class Handler
        Parameters:
        encoding - The name of a supported character encoding. May be null, to indicate the default platform encoding.
        Throws:
        SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").
        UnsupportedEncodingException - if the named encoding is not supported.
      • close

        public void close()
        Flush any buffered messages and Close all the files.
        Specified by:
        close in class Handler
      • publish

        public void publish​(LogRecord lrecord)
        Format and publish a LogRecord.

        This FileHandler is associated with a Formatter, which has to format the LogRecord according to ELF and return back the string formatted as per ELF. This method first checks if the header is already written to the file, if not, gets the header from the Formatter and writes it at the beginning of the file.

        Specified by:
        publish in class Handler
        Parameters:
        lrecord - the log record to be published.
      • nonBlockingFlush

        protected void nonBlockingFlush()
        Flush any buffered messages.
      • flush

        public void flush()
        Specified by:
        flush in class Handler