Simple Log 2.0.1
[grlea]

org.grlea.log.rollover
Class RolloverManager

java.lang.Object
  extended byjava.io.Writer
      extended byorg.grlea.log.rollover.RolloverManager

public class RolloverManager
extends java.io.Writer

The RolloverManager is a Writer implementation used by Simple Log to enable periodic log-rolling functionality. It is a writer which writes to an "active" log file and, when told by its RolloverStrategy that the file is due to be rolled over, moves the content of the active log file into a new rollover log file. Sufficient mechanics are employed to ensure that no log content is lost while the roll over is being conducted.

Version:
$Revision: 1.2 $
Author:
Graham Lea

Nested Class Summary
static interface RolloverManager.ErrorReporter
          An interface for objects wishing to be notified of errors occurring in a RolloverManager while it is running.
 
Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
RolloverManager(java.util.Properties properties, RolloverManager.ErrorReporter errorReporter)
          Creates a new RolloverManager, configuring it with provided properties.
 
Method Summary
 void close()
          Closes the file resources associated with this RolloverManager and releases any other resources used by it.
 void configure(java.util.Properties properties)
          Configures this RolloverManager using the given properties.
static java.io.Writer createRolloverManager(java.util.Properties properties, RolloverManager.ErrorReporter errorReporter)
           
 void flush()
          Does nothing, as the RolloverManager auto-flushes after every write()
 RolloverStrategy getStrategy()
          Returns the RolloverStrategy object currently in use by this RolloverManager.
 void rolloverIfNecessary()
          Prompts the RolloverManager to check whether the log file needs to be rolled and to perform that rolling if necessary.
 void setStrategy(RolloverStrategy strategy)
          Sets the RolloverStrategy to be used by this RolloverManager.
 void write(char[] cbuf, int off, int len)
          Writes the output to the current writer and flushes it.
 
Methods inherited from class java.io.Writer
write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RolloverManager

public RolloverManager(java.util.Properties properties,
                       RolloverManager.ErrorReporter errorReporter)
                throws java.io.IOException
Creates a new RolloverManager, configuring it with provided properties. The given RolloverManager.ErrorReporter object is retained and used to report errors for the life of the new RolloverManager instance.

Parameters:
properties - properties to be used to configure the new RolloverManager
errorReporter - and object to which errors that occur while the RolloverManager is running will be reported. May be null.
Throws:
java.io.IOException - if an error occurs while configuring the RolloverManager or opening the files it will be logging to.
java.lang.IllegalArgumentException - if properties is null.
Method Detail

configure

public void configure(java.util.Properties properties)
               throws java.io.IOException
Configures this RolloverManager using the given properties.

Parameters:
properties - properties to be used to configure this RolloverManager
Throws:
java.io.IOException - if an error occurs while configuring the RolloverManager or opening the files it will be logging to.

close

public void close()
Closes the file resources associated with this RolloverManager and releases any other resources used by it. Any errors occurring during this operation are captured and reported to the error reporter.


flush

public void flush()
Does nothing, as the RolloverManager auto-flushes after every write()


write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
Writes the output to the current writer and flushes it.

Throws:
java.io.IOException - if an error occurs writing to the current writer.

rolloverIfNecessary

public void rolloverIfNecessary()
                         throws java.io.IOException
Prompts the RolloverManager to check whether the log file needs to be rolled and to perform that rolling if necessary.

Throws:
java.io.IOException - if an error occurs while rolling the log file.

getStrategy

public RolloverStrategy getStrategy()
Returns the RolloverStrategy object currently in use by this RolloverManager.


setStrategy

public void setStrategy(RolloverStrategy strategy)
Sets the RolloverStrategy to be used by this RolloverManager. Once the strategy has been set using this method, it will never be changed by calls to configure(java.util.Properties), which includes auto-reloading of the properties.

Parameters:
strategy - the new strategy implementation to be used
Throws:
java.lang.IllegalArgumentException - if strategy is null.

createRolloverManager

public static java.io.Writer createRolloverManager(java.util.Properties properties,
                                                   RolloverManager.ErrorReporter errorReporter)
                                            throws java.io.IOException
Throws:
java.io.IOException

Copyright (c) 2004-2006, Graham Lea. All rights reserved.