ch.javasoft.util.logging
Class LogFragmenter

java.lang.Object
  extended by ch.javasoft.util.logging.LogFragmenter

public class LogFragmenter
extends Object

The LogFragmenter allows fragmented logging of a log record, which might for instance result as a single line in the log file. Normally, a record is logged as one line. With this class, multiple log records can be logged on a single line.

Fragmented logging starts with one of the xxxStart(..) methods, for instance, infoStart(String) to log with the INFO log level. The subsequent calls which should appear on the same line are logged with append(String), and the line is completed with end() or end(String).

Sample usage:

   Logger logger      = Logger.getLogger("myLogger");
   LogFragmenter frag = new LogFragmenter(logger);
   frag.start("Counting to 10: ", Level.INFO);
   for (int i = 1; i <= 10; i++) {
      if (i > 1) frag.append(", ");
      frag.append(String.valueOf(i));
   }
   frag.end();
 

NOTE: this class is intended to be used with the LogFormatter.


Constructor Summary
LogFragmenter(Logger logger)
          Constructor with logger to log to
LogFragmenter(String logger)
          Constructor with name of the logger to log to
 
Method Summary
 void append(String msg)
          Append the given message to the log, usually printed on the same log line
 void cleanUp()
          End fragmented logging if it is started, or do nothing otherwise
 void configStart(String msg)
          Start fragmented logging with the given message at log level CONFIG Calls start(String, Level) with Level.CONFIG
 void end()
          End fragmented logging without any additional message
 void end(String msg)
          End fragmented logging, appending the given message before logging is closed
 void finerStart(String msg)
          Start fragmented logging with the given message at log level FINER Calls start(String, Level) with Level.FINER
 void fineStart(String msg)
          Start fragmented logging with the given message at log level FINE Calls start(String, Level) with Level.FINE
 void finestStart(String msg)
          Start fragmented logging with the given message at log level FINEST Calls start(String, Level) with Level.FINEST
 void infoStart(String msg)
          Start fragmented logging with the given message at log level INFO Calls start(String, Level) with Level.INFO
 boolean isStarted()
           
 void severeStart(String msg)
          Start fragmented logging with the given message at log level SEVERE Calls start(String, Level) with Level.SEVERE
 void start(String msg, Level level)
          Start fragmented logging with the given message at the given level
 void warningStart(String msg)
          Start fragmented logging with the given message at log level WARNING Calls start(String, Level) with Level.WARNING
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LogFragmenter

public LogFragmenter(String logger)
Constructor with name of the logger to log to

Parameters:
logger - the name of the logger to log to
See Also:
Logger.getLogger(String)

LogFragmenter

public LogFragmenter(Logger logger)
Constructor with logger to log to

Parameters:
logger - the logger to log to
Method Detail

start

public void start(String msg,
                  Level level)
           throws IllegalStateException
Start fragmented logging with the given message at the given level

Parameters:
msg - the message to start logging with
level - the level on which all log messages (until end is called) will be logged
Throws:
IllegalStateException - if the logger has already been started

severeStart

public void severeStart(String msg)
Start fragmented logging with the given message at log level SEVERE Calls start(String, Level) with Level.SEVERE


warningStart

public void warningStart(String msg)
Start fragmented logging with the given message at log level WARNING Calls start(String, Level) with Level.WARNING


infoStart

public void infoStart(String msg)
Start fragmented logging with the given message at log level INFO Calls start(String, Level) with Level.INFO


configStart

public void configStart(String msg)
Start fragmented logging with the given message at log level CONFIG Calls start(String, Level) with Level.CONFIG


fineStart

public void fineStart(String msg)
Start fragmented logging with the given message at log level FINE Calls start(String, Level) with Level.FINE


finerStart

public void finerStart(String msg)
Start fragmented logging with the given message at log level FINER Calls start(String, Level) with Level.FINER


finestStart

public void finestStart(String msg)
Start fragmented logging with the given message at log level FINEST Calls start(String, Level) with Level.FINEST


append

public void append(String msg)
Append the given message to the log, usually printed on the same log line

Parameters:
msg - the message to append to the log
Throws:
IllegalStateException - if the logger has not yet been started

end

public void end()
End fragmented logging without any additional message

Throws:
IllegalStateException - if the logger has not yet been started

end

public void end(String msg)
End fragmented logging, appending the given message before logging is closed

Throws:
IllegalStateException - if the logger has not yet been started

cleanUp

public void cleanUp()
End fragmented logging if it is started, or do nothing otherwise


isStarted

public boolean isStarted()
Returns:
true if fragmented logging has been started