GigaSpaces XAP 9.5 API

com.gigaspaces.logger
Class RollingFileHandler

java.lang.Object
  extended by java.util.logging.Handler
      extended by java.util.logging.StreamHandler
          extended by com.gigaspaces.logger.RollingFileHandler
Direct Known Subclasses:
AuditHandler

public class RollingFileHandler
extends StreamHandler

Rolling based logging Handler.

Rollover:

Rollover is based on two policies, whichever policy is triggered first:
  • File size rolling policy (default 2MB)
  • Time based rolling policy (default is daily)
  • Properties:

    formatter:

    The default log output formatting 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 = {homedir}/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 a NullBackupPolicy 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 logging Levels) 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:
    RollingFileHandlerConfigurer

    Field Summary
    protected static String APPEND_PROP
               
    protected static String BACKUP_POLICY_PROP
               
    protected static String DATE_PATTERN_DEFAULT
               
    protected static String DATE_PROP
               
    protected static String DEBUG_LEVEL
               
    protected static String DEBUG_LEVEL_DEFAULT
               
    protected static String FILE_APPEND_DEFAULT
               
    protected static String FILENAME_PATTERN_DEFAULT
               
    protected static String FILENAME_PATTERN_PROP
               
    protected  String FILENAME_PATTTERN_PLACEHOLDER_PREFIX
              Resolves to the full class name of this handler and the ".filename-pattern" property at the end.
    protected static String FORMATTER_PROP
               
    protected  String HANDLER_PROP_PREFIX
              Resolves to the full class name of this handler and a '.' at the end.
    protected static String HOMEDIR_PROP
               
    protected static String HOST_PROP
               
    protected static String LEVEL_PROP
               
    protected static String PID_PROP
               
    protected static String SERVICE_PROP
               
    protected static int SIZE_ROLLING_POLICY_DEFAULT
               
    protected static String SIZE_ROLLING_POLICY_PROP
               
    protected static String TIME_ROLLING_POLICY_DEFAULT
               
    protected static String TIME_ROLLING_POLICY_PROP
               
     
    Constructor Summary
    RollingFileHandler()
              Construct a default RollingFileHandler.
     
    Method Summary
    protected  void configure()
              Configures this logger using the properties provided by the LogManager.getProperty(String) method.
    static File[] filesCreated()
               
    static boolean isMonitoringCreatedFiles()
               
    static void monitorCreatedFiles()
               
     void publish(LogRecord record)
              Applies the policies before writing to the stream; re-configures the stream if policy is triggered.
     
    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
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    HANDLER_PROP_PREFIX

    protected final String 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

    protected static final String LEVEL_PROP
    See Also:
    Constant Field Values

    FORMATTER_PROP

    protected static final String FORMATTER_PROP
    See Also:
    Constant Field Values

    FILENAME_PATTERN_PROP

    protected static final String FILENAME_PATTERN_PROP
    See Also:
    Constant Field Values

    SIZE_ROLLING_POLICY_PROP

    protected static final String SIZE_ROLLING_POLICY_PROP
    See Also:
    Constant Field Values

    TIME_ROLLING_POLICY_PROP

    protected static final String TIME_ROLLING_POLICY_PROP
    See Also:
    Constant Field Values

    BACKUP_POLICY_PROP

    protected static final String BACKUP_POLICY_PROP
    See Also:
    Constant Field Values

    APPEND_PROP

    protected static final String APPEND_PROP
    See Also:
    Constant Field Values

    DEBUG_LEVEL

    protected static final String DEBUG_LEVEL
    See Also:
    Constant Field Values

    FILENAME_PATTTERN_PLACEHOLDER_PREFIX

    protected final String 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

    protected static final String HOMEDIR_PROP
    See Also:
    Constant Field Values

    HOST_PROP

    protected static final String HOST_PROP
    See Also:
    Constant Field Values

    PID_PROP

    protected static final String PID_PROP
    See Also:
    Constant Field Values

    SERVICE_PROP

    protected static final String SERVICE_PROP
    See Also:
    Constant Field Values

    DATE_PROP

    protected static final String DATE_PROP
    See Also:
    Constant Field Values

    DATE_PATTERN_DEFAULT

    protected static final String DATE_PATTERN_DEFAULT
    See Also:
    Constant Field Values

    FILENAME_PATTERN_DEFAULT

    protected static final String FILENAME_PATTERN_DEFAULT
    See Also:
    Constant Field Values

    SIZE_ROLLING_POLICY_DEFAULT

    protected static final int SIZE_ROLLING_POLICY_DEFAULT
    See Also:
    Constant Field Values

    TIME_ROLLING_POLICY_DEFAULT

    protected static final String TIME_ROLLING_POLICY_DEFAULT
    See Also:
    Constant Field Values

    FILE_APPEND_DEFAULT

    protected static final String FILE_APPEND_DEFAULT
    See Also:
    Constant Field Values

    DEBUG_LEVEL_DEFAULT

    protected static final String DEBUG_LEVEL_DEFAULT
    See Also:
    Constant Field Values
    Constructor Detail

    RollingFileHandler

    public RollingFileHandler()
    Construct a default RollingFileHandler. This will be configured entirely from LogManager properties (or their default values).

    Method Detail

    monitorCreatedFiles

    public static void monitorCreatedFiles()

    isMonitoringCreatedFiles

    public static boolean isMonitoringCreatedFiles()

    filesCreated

    public static File[] filesCreated()

    configure

    protected void configure()
    Configures this logger using the properties provided by the LogManager.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 on ManagementFactory.getRuntimeMXBean().getName().


    publish

    public void publish(LogRecord record)
    Applies the policies before writing to the stream; re-configures the stream if policy is triggered.

    Overrides:
    publish in class StreamHandler
    See Also:
    StreamHandler.publish(java.util.logging.LogRecord)

    GigaSpaces XAP 9.5 API

    Copyright © GigaSpaces.