Package org.apache.juli
Class FileHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- org.apache.juli.FileHandler
-
- Direct Known Subclasses:
AsyncFileHandler
public class FileHandler extends java.util.logging.HandlerImplementation of Handler that appends log messages to a file named {prefix}{date}{suffix} in a configured directory.The following configuration properties are available:
directory- The directory where to create the log file. If the path is not absolute, it is relative to the current working directory of the application. The Apache Tomcat configuration files usually specify an absolute path for this property,${catalina.base}/logsDefault value:logsrotatable- Iftrue, the log file will be rotated on the first write past midnight and the filename will be{prefix}{date}{suffix}, where date is yyyy-MM-dd. Iffalse, the file will not be rotated and the filename will be{prefix}{suffix}. Default value:trueprefix- The leading part of the log file name. Default value:juli.suffix- The trailing part of the log file name. Default value:.logbufferSize- Configures buffering. The value of0uses system default buffering (typically an 8K buffer will be used). A value of<0forces a writer flush upon each log write. A value>0uses a BufferedOutputStream with the defined value but note that the system default buffering will also be applied. Default value:-1encoding- Character set used by the log file. Default value: empty string, which means to use the system default character set.level- The level threshold for this Handler. See thejava.util.logging.Levelclass for the possible levels. Default value:ALLfilter- Thejava.util.logging.Filterimplementation class name for this Handler. Default value: unsetformatter- Thejava.util.logging.Formatterimplementation class name for this Handler. Default value:org.apache.juli.OneLineFormattermaxDays- The maximum number of days to keep the log files. If the specified value is<=0then the log files will be kept on the file system forever, otherwise they will be kept the specified maximum days. Default value:-1.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classFileHandler.ThreadFactoryThread factory for creating log file cleanup threads.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEDefault value for the log buffer size.static intDEFAULT_MAX_DAYSDefault value for the maximum number of days to keep log files.protected java.util.concurrent.locks.ReadWriteLockwriterLockLock used to control access to the writer.
-
Constructor Summary
Constructors Constructor Description FileHandler()Default constructor.FileHandler(java.lang.String directory, java.lang.String prefix, java.lang.String suffix)Constructor with directory, prefix, and suffix.FileHandler(java.lang.String directory, java.lang.String prefix, java.lang.String suffix, java.lang.Integer maxDays)Constructor with directory, prefix, suffix, and maxDays.FileHandler(java.lang.String directory, java.lang.String prefix, java.lang.String suffix, java.lang.Integer maxDays, java.lang.Boolean rotatable, java.lang.Integer bufferSize)Constructor with all configuration options.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the currently open log file (if any).protected voidcloseWriter()Close the currently open log file writer.voidflush()Flush the writer.voidopen()Open the new log file for the date specified bydate.protected voidopenWriter()Open the writer for the current log file.voidpublish(java.util.logging.LogRecord record)Format and publish aLogRecord.
-
-
-
Field Detail
-
DEFAULT_MAX_DAYS
public static final int DEFAULT_MAX_DAYS
Default value for the maximum number of days to keep log files. A value of -1 means unlimited.- See Also:
- Constant Field Values
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
Default value for the log buffer size. A value of -1 forces a flush on each write.- See Also:
- Constant Field Values
-
writerLock
protected final java.util.concurrent.locks.ReadWriteLock writerLock
Lock used to control access to the writer.
-
-
Constructor Detail
-
FileHandler
public FileHandler()
Default constructor. Uses LogManager properties for all configuration.
-
FileHandler
public FileHandler(java.lang.String directory, java.lang.String prefix, java.lang.String suffix)Constructor with directory, prefix, and suffix.- Parameters:
directory- The directory where log files are createdprefix- The leading part of the log file namesuffix- The trailing part of the log file name
-
FileHandler
public FileHandler(java.lang.String directory, java.lang.String prefix, java.lang.String suffix, java.lang.Integer maxDays)Constructor with directory, prefix, suffix, and maxDays.- Parameters:
directory- The directory where log files are createdprefix- The leading part of the log file namesuffix- The trailing part of the log file namemaxDays- The maximum number of days to keep log files
-
FileHandler
public FileHandler(java.lang.String directory, java.lang.String prefix, java.lang.String suffix, java.lang.Integer maxDays, java.lang.Boolean rotatable, java.lang.Integer bufferSize)Constructor with all configuration options.- Parameters:
directory- The directory where log files are createdprefix- The leading part of the log file namesuffix- The trailing part of the log file namemaxDays- The maximum number of days to keep log filesrotatable- Whether the log file is rotatablebufferSize- The log buffer size
-
-
Method Detail
-
publish
public void publish(java.util.logging.LogRecord record)
Format and publish aLogRecord.- Specified by:
publishin classjava.util.logging.Handler- Parameters:
record- description of the log event
-
close
public void close()
Close the currently open log file (if any).- Specified by:
closein classjava.util.logging.Handler
-
closeWriter
protected void closeWriter()
Close the currently open log file writer.
-
flush
public void flush()
Flush the writer.- Specified by:
flushin classjava.util.logging.Handler
-
open
public void open()
Open the new log file for the date specified bydate.
-
openWriter
protected void openWriter()
Open the writer for the current log file.
-
-