Package net.sf.eBus.util.logging
Class CalendarFileHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- java.util.logging.StreamHandler
-
- net.sf.eBus.util.logging.CalendarFileHandler
-
- All Implemented Interfaces:
TimerTaskListener
public final class CalendarFileHandler extends StreamHandler implements TimerTaskListener
Logs messages to a user-specified file, rolling over to a new file at midnight. Log files are kept for only so many days beforeCalendarFileHandlerdeletes them. This retention limit is configurable but defaults to 10 days.The
CalendarFileHandleruses three parameters to generate the complete file name:<base name>.<date pattern>.<extension>
-
Base Name: Store the log files here using this base
name.
Example:
/var/log/app/app -
Date Pattern: Use this pattern to format the date
portion of the file name.
The data pattern is passed to a
SimpleDateFormat(String). SeeSimpleDateFormatfor a detailed explanation of valid date formats. -
Extension: This is first part of the log file's
name.
Example: log
Given the base name
/var/log/eBus/eBus, a date pattern "ddMMyyyy" and extensionlog, the July 15, 2001 log file name is/var/log/eBus/eBus.15072001.logConfiguration:
CalendarFileHandlerdefault configuration uses the following LogManager properties. If the named properties are either not defined or have invalid values, then the default settings are used.- net.sf.eBus.util.logging.CalendarFileHandler.basename (defaults to "./Logger")
- net.sf.eBus.util.logging.CalendarFileHandler.pattern (defaults to "yyyyMMdd")
- net.sf.eBus.util.logging.CalendarFileHandler.extension (defaults to "log")
- net.sf.eBus.util.logging.CalendarFileHandler.days_kept (defaults to 10 days)
- net.sf.eBus.util.logging.CalendarFileHandler.formatter (defaults to "net.sf.eBus.util.logging.PatternFormatter")
- net.sf.eBus.util.logging.CalendarFileHandler.level (defaults to system default)
- Author:
- Charles Rapp
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_BASENAMEThe log file's default base name is "Logger".static StringDEFAULT_DATE_FORMATThe log file's default data format is "yyyyMMdd".static intDEFAULT_DAYS_KEPTLog files are kept for 10 days by default.static StringDEFAULT_DIRECTORYLog files are placed in the application's current working directory (".") by default.static StringDEFAULT_EXTENSIONThe default file extension is "log".static LevelDEFAULT_LEVELThe log file handler default level isLevel.INFO.static intMAX_DAYS_KEPTThe maximum number of days a log file is kept is 96.static intMIN_DAYS_KEPTThe 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 Summary
Constructors Constructor Description CalendarFileHandler()Creates a newCalendarFileHandlerand configures it according toLogManagerconfiguration properties.CalendarFileHandler(String baseName, String datePattern, String extension, int daysKept)Creates a newCalendarFileHandlerinstance for the specified base name, date format pattern, file name extension and how long to keep the files around.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidhandleTimeout(TimerEvent task)Time to roll over to the next log file.voidpublish(LogRecord record)Flushes the output stream afterStreamHandlerpublishes the log record.-
Methods inherited from class java.util.logging.StreamHandler
close, flush, isLoggable, setEncoding, setOutputStream
-
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, reportError, setErrorManager, setFilter, setFormatter, setLevel
-
-
-
-
Field Detail
-
DEFAULT_DIRECTORY
public static final String DEFAULT_DIRECTORY
Log files are placed in the application's current working directory (".") by default.- See Also:
- Constant Field Values
-
DEFAULT_BASENAME
public static final String DEFAULT_BASENAME
The log file's default base name is "Logger".- See Also:
- Constant Field Values
-
DEFAULT_DATE_FORMAT
public static final String DEFAULT_DATE_FORMAT
The log file's default data format is "yyyyMMdd". For July 4, 1776 the formatted string is "17760704".- See Also:
- Constant Field Values
-
DEFAULT_LEVEL
public static final Level DEFAULT_LEVEL
The log file handler default level isLevel.INFO.
-
DEFAULT_EXTENSION
public static final String DEFAULT_EXTENSION
The default file extension is "log".- See Also:
- Constant Field Values
-
MIN_DAYS_KEPT
public static final 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.- See Also:
- Constant Field Values
-
MAX_DAYS_KEPT
public static final int MAX_DAYS_KEPT
The maximum number of days a log file is kept is 96. That's three months. That is plenty of time to archive the file if necessary.- See Also:
- Constant Field Values
-
DEFAULT_DAYS_KEPT
public static final int DEFAULT_DAYS_KEPT
Log files are kept for 10 days by default.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CalendarFileHandler
public CalendarFileHandler() throws IOException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetExceptionCreates a newCalendarFileHandlerand configures it according toLogManagerconfiguration properties.- Throws:
IllegalArgumentException- ifLogManagerconfiguration properties contains invalid or incorrect settings.IOException- if defined log directory is invalid.ClassNotFoundException- if defined formatter is not a known Java class.NoSuchMethodException- if defined formatter does not have a default constructor defined.InstantiationException- if defined formatter instantiation failed.IllegalAccessException- if defined formatter default constructor is inaccessible.InvocationTargetException- if formatter instantiation failed.
-
CalendarFileHandler
public CalendarFileHandler(String baseName, String datePattern, String extension, int daysKept) throws IOException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
Creates a newCalendarFileHandlerinstance for the specified base name, date format pattern, file name extension and how long to keep the files around.- Parameters:
baseName- where to put the log files.datePattern- date formatextension- file name extensiondaysKept- how long the log files are kept around (in days).- Throws:
IllegalArgumentException- if:-
if
baseName,datePatternorextensionisnull. -
baseName,datePatternorextensionis an empty string. -
daysKeptis <MIN_DAYS_KEPTor >MAX_DAYS_KEPT. -
datePatternis an invalid date format pattern as perjava.text.SimpleDateFormat. -
baseNameis in an unknown directory or directory cannot be accessed.
-
if
IllegalArgumentException- if any of the given parameters is set to an invalid value.IOException- if defined log directory is invalid.ClassNotFoundException- if defined formatter is not a known Java class.NoSuchMethodException- if defined formatter does not have a default constructor defined.InstantiationException- if defined formatter instantiation failed.IllegalAccessException- if defined formatter default constructor is inaccessible.InvocationTargetException- if formatter instantiation failed.
-
-
Method Detail
-
handleTimeout
public void handleTimeout(TimerEvent task)
Time to roll over to the next log file.- Specified by:
handleTimeoutin interfaceTimerTaskListener- Parameters:
task- the roll file timer task.
-
publish
public void publish(LogRecord record)
Flushes the output stream afterStreamHandlerpublishes the log record.StreamHandlerdoes not do this which means records are not seen in the log file as they are published.- Overrides:
publishin classStreamHandler- Parameters:
record- Publish this log record to the log file.
-
-