public final class CalendarFileHandler extends java.util.logging.StreamHandler implements TimerTaskListener
CalendarFileHandler
deletes them.
This retention limit is configurable but defaults to 10 days.
The CalendarFileHandler
uses three parameters to
generate the complete file name:
<base name>.<date pattern>.<extension>
Example: /var/log/app/app
The data pattern is passed to a
SimpleDateFormat(String)
. See
SimpleDateFormat
for a detailed
explanation of valid date formats.
Example: log
Given the base name /var/log/eBus/eBus
, a date
pattern "ddMMyyyy" and extension log
, the
July 15, 2001 log file name is
/var/log/eBus/eBus.15072001.log
Configuration: CalendarFileHandler
default configuration uses the following LogManager
properties. If the named properties are either not defined or
have invalid values, then the default settings are used.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_BASENAME
The log file's default base name is "Logger".
|
static java.lang.String |
DEFAULT_DATE_FORMAT
The log file's default data format is "yyyyMMdd".
|
static int |
DEFAULT_DAYS_KEPT
Log files are kept for 10 days by default.
|
static java.lang.String |
DEFAULT_DIRECTORY
Log files are placed in the application's current working
directory (".") by default.
|
static java.lang.String |
DEFAULT_EXTENSION
The default file extension is "log".
|
static java.util.logging.Level |
DEFAULT_LEVEL
The log file handler default level is
Level.INFO . |
static int |
MAX_DAYS_KEPT
The maximum number of days a log file is kept is 96.
|
static int |
MIN_DAYS_KEPT
The minimum number of days a log file is kept is 0
which means that the file is deleted as soon as the day
ends.
|
Constructor and Description |
---|
CalendarFileHandler()
Creates a new
CalendarFileHandler and configures
it according to LogManager configuration
properties. |
CalendarFileHandler(java.lang.String baseName,
java.lang.String datePattern,
java.lang.String extension,
int daysKept)
Creates a new
CalendarFileHandler instance for
the specified base name, date format pattern, file name
extension and how long to keep the files around. |
Modifier and Type | Method and Description |
---|---|
void |
handleTimeout(TimerEvent task)
Time to roll over to the next log file.
|
void |
publish(java.util.logging.LogRecord logRecord)
Flushes the output stream after
StreamHandler
publishes the log record. |
close, flush, isLoggable, setEncoding, setOutputStream
public static final java.lang.String DEFAULT_DIRECTORY
public static final java.lang.String DEFAULT_BASENAME
public static final java.lang.String DEFAULT_DATE_FORMAT
public static final java.util.logging.Level DEFAULT_LEVEL
Level.INFO
.public static final java.lang.String DEFAULT_EXTENSION
public static final int MIN_DAYS_KEPT
public static final int MAX_DAYS_KEPT
public static final int DEFAULT_DAYS_KEPT
public CalendarFileHandler() throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
CalendarFileHandler
and configures
it according to LogManager
configuration
properties.java.lang.IllegalArgumentException
- if LogManager
configuration properties contains
invalid or incorrect settings.java.io.IOException
- if defined log directory is invalid.java.lang.ClassNotFoundException
- if defined formatter is not a known Java class.java.lang.NoSuchMethodException
- if defined formatter does not have a default
constructor defined.java.lang.InstantiationException
- if defined formatter instantiation failed.java.lang.IllegalAccessException
- if defined formatter default constructor is
inaccessible.java.lang.reflect.InvocationTargetException
- if formatter instantiation failed.public CalendarFileHandler(java.lang.String baseName, java.lang.String datePattern, java.lang.String extension, int daysKept) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
CalendarFileHandler
instance for
the specified base name, date format pattern, file name
extension and how long to keep the files around.baseName
- where to put the log files.datePattern
- date formatextension
- file name extensiondaysKept
- how long the log files are kept around
(in days).java.lang.IllegalArgumentException
- if:
baseName
, datePattern
or
extension
is null
.
baseName
, datePattern
or
extension
is an empty string.
daysKept
is < MIN_DAYS_KEPT
or > MAX_DAYS_KEPT
.
datePattern
is an invalid date format
pattern as per
java.text.SimpleDateFormat
.
baseName
is in an unknown directory or
directory cannot be accessed.
java.lang.IllegalArgumentException
- if any of the given parameters is set to an invalid
value.java.io.IOException
- if defined log directory is invalid.java.lang.ClassNotFoundException
- if defined formatter is not a known Java class.java.lang.NoSuchMethodException
- if defined formatter does not have a default
constructor defined.java.lang.InstantiationException
- if defined formatter instantiation failed.java.lang.IllegalAccessException
- if defined formatter default constructor is
inaccessible.java.lang.reflect.InvocationTargetException
- if formatter instantiation failed.public void handleTimeout(TimerEvent task)
handleTimeout
in interface TimerTaskListener
task
- the roll file timer task.public void publish(java.util.logging.LogRecord logRecord)
StreamHandler
publishes the log record. StreamHandler
does not
do this which means records are not seen in the log
file as they are published.publish
in class java.util.logging.StreamHandler
logRecord
- Publish this log record to the log file.Copyright © 2001 - 2024. Charles W. Rapp. All rights reserved.