Package com.gigaspaces.logger
Class RollingFileHandler
java.lang.Object
java.util.logging.Handler
java.util.logging.StreamHandler
com.gigaspaces.logger.RollingFileHandler
- Direct Known Subclasses:
AuditHandler
Rolling based logging File size rolling policy (default 2MB)
Time based rolling policy (default is daily)
Handler. Rollover:
Rollover is based on two policies, whichever policy is triggered first:Properties:
formatter:
The default log outputformatting is given by GSSimpleFormatter. Configuration: com.gigaspaces.logger.RollingFileHandler.formatter
= com.gigaspaces.logger.GSSimpleFormatter filename-pattern:
The file name pattern can be configured to include a placeholder for properties to resolve, such as homedir, host, pid and date. Each placeholder is identified by a set of curly brackets{..}. It may also be a placeholder for a custom defined
property. Configuration: com.gigaspaces.logger.RollingFileHandler.filename-pattern
= {gs.logs}/logs/{date,yyyy-MM-dd~HH.mm}-gigaspaces-{service}-{host}-{pid}.log
A place holder value is that of an overriding system property. If no override was specified,
and the property is one of the predefined properties (i.e. homedir, host, pid, date), its value
is evaluated by the handler implementation. If the place holder is of a custom property, and no
value is defined, the propety is left as is. If any error occurs, it is reported and the property
is replaced by an empty string. Example override by system property:
-Dcom.gigaspaces.logger.RollingFileHandler.filename-pattern.date=yyyy-MM-dd
append:
The append property specifies if output should be appended to an existing file. Default is set to false. Thus, if a file already exists by this name, a unique incrementing index to resolve the conflict will be concatenated. It will be added at the end of the filename replacing ".log" with "__{unique}.log" or at the end of the filename if the pattern doesn't end with ".log".Configuration: com.gigaspaces.logger.RollingFileHandler.append
= false size-rolling-policy:
The file size rolling policy can be configured to roll the file when a size limit is reached. It specifies an approximate maximum amount to write (in bytes) to any one file. If this is zero, then there is no limit. If the property is omitted, then a default of 2MB is assumed.Configuration:
com.gigaspaces.logger.RollingFileHandler.size-rolling-policy = 2000000
time-rolling-policy:
The time based rolling policy can be configured to roll the file at an occurring schedule. The time policy can be set to either one of: daily, weekly, monthly or yearly. If the property is omitted, then the default pattern of "daily" is assumed; meaning daily rollover (at midnight). For example, if "monthly" is configured, the file will rollover at the beginning of each month.Configuration: com.gigaspaces.logger.RollingFileHandler.time-rolling-policy
= daily backup-policy:
A backup-policy can be configured to backup files. By default aNullBackupPolicy is configured, which does nothing. It can be
replaced by a DeleteBackupPolicy to keep a backup of files for a specified period. The
BackupPolicy interface allows custom implementations to be plugged-in.
Configuration:
com.gigaspaces.logger.RollingFileHandler.backup-policy = com.gigaspaces.logger.DeleteBackupPolicy
com.gigaspaces.logger.DeleteBackupPolicy.period = 30
com.gigaspaces.logger.DeleteBackupPolicy.backup = 10
debug-level:
The debug level (configured to one of loggingLevels) is the level
in which debug messages are displayed to the "standard" output stream. By default the level is
configured to "CONFIG" which displays the log file name. Configuration:
com.gigaspaces.logger.RollingFileHandler.debug-level = CONFIG system property overrides
Any of the logger properties can be configured by a system property override, as specified by: -Dcom.gigaspaces.logger.RollingFileHandler.[property-name]=[property-value]
For example: -Dcom.gigaspaces.logger.RollingFileHandler.debug-level=OFF
- Since:
- 7.0
- Author:
- Moran Avigdor
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected final StringResolves to the full class name of this handler and the ".filename-pattern" property at the end.protected static final Stringprotected final StringResolves to the full class name of this handler and a '.' at the end.protected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final intprotected static final Stringprotected static final Stringprotected static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidConfigures this logger using the properties provided by theLogManager.getProperty(String)method.static File[]static booleanstatic voidvoidApplies the policies before writing to the stream; re-configures the stream if policy is triggered.Methods inherited from class java.util.logging.StreamHandler
flush, isLoggable, setEncoding, setOutputStreamMethods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, reportError, setErrorManager, setFilter, setFormatter, setLevel
-
Field Details
-
HANDLER_PROP_PREFIX
Resolves to the full class name of this handler and a '.' at the end. Serves as the prefix for handler properties in logging configuration file and as the prefix for system property overrides.logging configuration file: com.gigaspaces.logger.RollingFileHandler.[property-name]=[property-value] System property: -Dcom.gigaspaces.logger.RollingFileHandler.[property-name]=[property-value]
-
LEVEL_PROP
- See Also:
-
FORMATTER_PROP
- See Also:
-
FILENAME_PATTERN_PROP
- See Also:
-
SIZE_ROLLING_POLICY_PROP
- See Also:
-
TIME_ROLLING_POLICY_PROP
- See Also:
-
BACKUP_POLICY_PROP
- See Also:
-
APPEND_PROP
- See Also:
-
DEBUG_LEVEL
- See Also:
-
FILENAME_PATTTERN_PLACEHOLDER_PREFIX
Resolves to the full class name of this handler and the ".filename-pattern" property at the end. Serves as the prefix for filename-pattern place holder system property overrides.-Dcom.gigaspaces.logger.RollingFileHandler.filename-pattern.[placeholder-name]=[placeholder-value]
-
HOMEDIR_PROP
- See Also:
-
LOGSDIR_PROP
- See Also:
-
HOST_PROP
- See Also:
-
PID_PROP
- See Also:
-
SERVICE_PROP
- See Also:
-
DATE_PROP
- See Also:
-
DATE_PATTERN_DEFAULT
- See Also:
-
FILENAME_PATTERN_DEFAULT
- See Also:
-
SIZE_ROLLING_POLICY_DEFAULT
protected static final int SIZE_ROLLING_POLICY_DEFAULT- See Also:
-
TIME_ROLLING_POLICY_DEFAULT
- See Also:
-
FILE_APPEND_DEFAULT
- See Also:
-
DEBUG_LEVEL_DEFAULT
- See Also:
-
-
Constructor Details
-
RollingFileHandler
public RollingFileHandler()Construct a default RollingFileHandler. This will be configured entirely from LogManager properties (or their default values).
-
-
Method Details
-
monitorCreatedFiles
public static void monitorCreatedFiles() -
isMonitoringCreatedFiles
public static boolean isMonitoringCreatedFiles() -
filesCreated
-
configure
protected void configure()Configures this logger using the properties provided by theLogManager.getProperty(String)method. More specifically, configures the default ".level", ".formatter", ".filename-pattern", ".size-rolling-policy", ".time-rolling-policy", and ".append" properties. The configure method is called only once at construction, but before any output stream is open. A user may wish to extend this handler and provide additional configurations or overrides, before the output stream's file-name is generated. For example, a user may implement a process ID extension that assigns the appropriate system property with it's value, that will be used as the replacement for the default process ID extractor, which relies onManagementFactory.getRuntimeMXBean().getName(). -
publish
Applies the policies before writing to the stream; re-configures the stream if policy is triggered.- Overrides:
publishin classStreamHandler- See Also:
-
close
- Overrides:
closein classStreamHandler- Throws:
SecurityException
-