Top Description Inners Fields Constructors Methods
org.apache.juli

public Class FileHandler

extends Handler
Class Inheritance
Known Direct Subclasses
org.apache.juli.AsyncFileHandler
Imports
java.io.BufferedOutputStream, .File, .FileOutputStream, .IOException, .OutputStream, .OutputStreamWriter, .PrintWriter, .UnsupportedEncodingException, java.nio.file.DirectoryStream, .Files, .Path, java.security.AccessController, .PrivilegedAction, java.sql.Timestamp, java.time.DateTimeException, .LocalDate, java.time.format.DateTimeFormatter, java.time.temporal.ChronoUnit, java.util.concurrent.ExecutorService, .Executors, java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.locks.ReadWriteLock, .ReentrantReadWriteLock, java.util.logging.ErrorManager, .Filter, .Formatter, .Handler, .Level, .LogManager, .LogRecord, java.util.regex.Pattern

Implementation of Handler that appends log messages to a file named {prefix}{date}{suffix} in a configured directory.

The following configuration properties are available:

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
private Integer
bufferSize

Log buffer size.

private volatile String
date

The as-of date for the currently open log file, or null if there is no open log file.

public static final int
public static final int
private static final ExecutorService
private String
directory

The directory in which log files are created.

private Integer
maxDays

Maximum number of days to keep the log files

private Pattern
pattern

Represents a file name pattern of type {prefix}{date}{suffix}.

private String
prefix

The prefix that is added to log file filenames.

private Boolean
rotatable

Determines whether the log file is rotatable

private String
suffix

The suffix that is added to log file filenames.

private volatile PrintWriter
writer

The PrintWriter to which we are currently logging, if any.

protected final ReadWriteLock
writerLock

Lock used to control access to the writer.

Constructor Summary

AccessConstructor and Description
public
public
FileHandler(String directory, String prefix, String suffix)

public
FileHandler(String directory, String prefix, String suffix, Integer maxDays)

public
FileHandler(String directory, String prefix, String suffix, Integer maxDays, Boolean rotatable, Integer bufferSize)

Method Summary

Modifier and TypeMethod and Description
private void
public void
close()

Implements abstract java.util.logging.Handler.close.

Close the currently open log file (if any).

protected void
private void
configure()

Configure from LogManager properties.

public void
flush()

Implements abstract java.util.logging.Handler.flush.

Flush the writer.

private Path
private String
getProperty(String name, String defaultValue)

private String
public void
open()

Open the new log file for the date specified by date.

protected void
public void
publish(LogRecord
description of the log event
record
)

Implements abstract java.util.logging.Handler.publish.

Format and publish a LogRecord.

private DirectoryStream<Path>
Inherited from java.util.logging.Handler:
getEncodinggetErrorManagergetFiltergetFormattergetLevelisLoggablereportErrorsetEncodingsetErrorManagersetFiltersetFormattersetLevel

Field Detail

bufferSizeback to summary
private Integer bufferSize

Log buffer size.

dateback to summary
private volatile String date

The as-of date for the currently open log file, or null if there is no open log file.

DEFAULT_BUFFER_SIZEback to summary
public static final int DEFAULT_BUFFER_SIZE
DEFAULT_MAX_DAYSback to summary
public static final int DEFAULT_MAX_DAYS
DELETE_FILES_SERVICEback to summary
private static final ExecutorService DELETE_FILES_SERVICE
directoryback to summary
private String directory

The directory in which log files are created.

maxDaysback to summary
private Integer maxDays

Maximum number of days to keep the log files

patternback to summary
private Pattern pattern

Represents a file name pattern of type {prefix}{date}{suffix}. The date is YYYY-MM-DD

prefixback to summary
private String prefix

The prefix that is added to log file filenames.

rotatableback to summary
private Boolean rotatable

Determines whether the log file is rotatable

suffixback to summary
private String suffix

The suffix that is added to log file filenames.

writerback to summary
private volatile PrintWriter writer

The PrintWriter to which we are currently logging, if any.

writerLockback to summary
protected final ReadWriteLock writerLock

Lock used to control access to the writer.

Constructor Detail

FileHandlerback to summary
public FileHandler()
FileHandlerback to summary
public FileHandler(String directory, String prefix, String suffix)
FileHandlerback to summary
public FileHandler(String directory, String prefix, String suffix, Integer maxDays)
FileHandlerback to summary
public FileHandler(String directory, String prefix, String suffix, Integer maxDays, Boolean rotatable, Integer bufferSize)

Method Detail

cleanback to summary
private void clean()
closeback to summary
public void close()

Implements abstract java.util.logging.Handler.close.

Close the currently open log file (if any).

Annotations
@Override
closeWriterback to summary
protected void closeWriter()
configureback to summary
private void configure()

Configure from LogManager properties.

flushback to summary
public void flush()

Implements abstract java.util.logging.Handler.flush.

Flush the writer.

Annotations
@Override
getDirectoryAsPathback to summary
private Path getDirectoryAsPath()
getPropertyback to summary
private String getProperty(String name, String defaultValue)
obtainDateFromPathback to summary
private String obtainDateFromPath(Path path)
openback to summary
public void open()

Open the new log file for the date specified by date.

openWriterback to summary
protected void openWriter()
publishback to summary
public void publish(LogRecord record)

Implements abstract java.util.logging.Handler.publish.

Format and publish a LogRecord.

Parameters
record:LogRecord

description of the log event

Annotations
@Override
streamFilesForDeleteback to summary
private DirectoryStream<Path> streamFilesForDelete() throws IOException
org.apache.juli back to summary

protected final Class FileHandler.ThreadFactory

extends Object
implements ThreadFactory
Class Inheritance
All Implemented Interfaces
java.util.concurrent.ThreadFactory

Field Summary

Modifier and TypeField and Description
private final ThreadGroup
private final boolean
private final String
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
public
ThreadFactory(final String namePrefix)

Method Summary

Modifier and TypeMethod and Description
public Thread
newThread(Runnable
a runnable to be executed by new thread instance
r
)

Implements java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

groupback to summary
private final ThreadGroup group
isSecurityEnabledback to summary
private final boolean isSecurityEnabled
namePrefixback to summary
private final String namePrefix
threadNumberback to summary
private final AtomicInteger threadNumber

Constructor Detail

ThreadFactoryback to summary
public ThreadFactory(final String namePrefix)

Method Detail

newThreadback to summary
public Thread newThread(Runnable r)

Implements java.util.concurrent.ThreadFactory.newThread.

Doc from java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Parameters
r:Runnable

a runnable to be executed by new thread instance

Returns:Thread

constructed thread, or null if the request to create a thread is rejected

Annotations
@Override