org.objectweb.util.monolog.wrapper.printwriter
Class PrintWriterImpl

java.lang.Object
  extended byjava.io.Writer
      extended byjava.io.PrintWriter
          extended byorg.objectweb.util.monolog.wrapper.printwriter.PrintWriterImpl
All Implemented Interfaces:
Loggable

public class PrintWriterImpl
extends java.io.PrintWriter
implements Loggable

This class is a PrintWriter wrapper. It exports the PrintWriter methods but fowards the message to a Logger. This implementation bufferizes the data when a print method is used. The buffer and the data are always written when a println method is used. No end of line are inserted by the println methods. A line is equals to a monolog message.

Author:
Sebastien Chassande-Barrioz

Field Summary
protected  java.lang.String currentLine
          This field is the buffer which represents the current line.
protected  boolean errors
          This field indicates the setError method was called.
protected  int level
           
protected  Logger logger
          The inner logger instance
protected  LoggerFactory loggerFactory
           
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
PrintWriterImpl(Logger l)
          It builds a PrintWriterImpl instance.
PrintWriterImpl(Logger l, int level)
          It builds a PrintWriterImpl instance.
PrintWriterImpl(Logger logger, LoggerFactory loggerFactory)
          It builds a PrintWriterImpl instance.
 
Method Summary
 boolean checkError()
          Flush the stream and check its error state.
 void close()
          It writes the buffer if it is not empty
 void flush()
          It writes the buffer if it is not empty
 int getLevel()
           
 Logger getLogger()
          Retrieves the logger instance used
 LoggerFactory getLoggerFactory()
          Retrieves the logger factory instance used
 void print(boolean x)
          Print a boolean value in the buffer.
 void print(char x)
          Print a character in the buffer.
 void print(char[] x)
          Print an array of characters in the buffer.
 void print(double x)
          Print a double-precision floating-point number in the buffer.
 void print(float x)
          Print a floating-point number in the buffer.
 void print(int x)
          Print an integer in the buffer.
 void print(long x)
          Print a long integer in the buffer.
 void print(java.lang.Object x)
          Print an object in the buffer.
 void print(java.lang.String x)
          Print a string in the buffer.
 void println()
          Send the buffer to the logger
 void println(boolean x)
          Send the buffer and a boolean value to the logger
 void println(char x)
          Send the buffer and a character to the logger
 void println(char[] x)
          Send the buffer and an array of characters to the logger
 void println(double x)
          Send the buffer and a a double-precision floating-point number to the logger.
 void println(float x)
          Send the buffer and a floating-point number to the logger
 void println(int x)
          Send the buffer and an integer to the logger
 void println(long x)
          Send the buffer and a long integer number to the logger
 void println(java.lang.Object x)
          Send the buffer and an object to the logger
 void println(java.lang.String x)
          Send the buffer and a String to the logger
protected  void setError()
          Indicate that an error has occurred.
 void setLevel(int level)
           
 void setLogger(Logger logger)
          Assigns the logger instance to use
 void setLoggerFactory(LoggerFactory lf)
          Assigns the logger factory instance to use
 void write(char[] buf)
          Write an array of characters in the buffer.
 void write(char[] buf, int off, int len)
          Write a portion of an array of characters in the buffer.
 void write(int c)
          Write a single character in the buffer.
 void write(java.lang.String s)
          Write a string in the buffer.
 void write(java.lang.String s, int off, int len)
          Write a portion of a string in the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected Logger logger
The inner logger instance


loggerFactory

protected LoggerFactory loggerFactory

level

protected int level

currentLine

protected java.lang.String currentLine
This field is the buffer which represents the current line.


errors

protected boolean errors
This field indicates the setError method was called.

Constructor Detail

PrintWriterImpl

public PrintWriterImpl(Logger l)
                throws java.lang.NullPointerException
It builds a PrintWriterImpl instance. The default level is DEBUG

Parameters:
l - is the logger toward which the message must be send
Throws:
java.lang.NullPointerException - if the parameter is null.

PrintWriterImpl

public PrintWriterImpl(Logger logger,
                       LoggerFactory loggerFactory)
                throws java.lang.NullPointerException
It builds a PrintWriterImpl instance. The default level is DEBUG

Parameters:
logger - is the logger toward which the message must be send
loggerFactory - is the loggerFactory of the logger
Throws:
java.lang.NullPointerException - if one of the parameters is null.

PrintWriterImpl

public PrintWriterImpl(Logger l,
                       int level)
                throws java.lang.NullPointerException
It builds a PrintWriterImpl instance.

Parameters:
l - is the logger toward which the message must be send
level - is the level used to log message.
Throws:
java.lang.NullPointerException - if the parameter is null.
Method Detail

getLevel

public int getLevel()

setLevel

public void setLevel(int level)

getLogger

public Logger getLogger()
Retrieves the logger instance used

Specified by:
getLogger in interface Loggable

setLogger

public void setLogger(Logger logger)
Assigns the logger instance to use

Specified by:
setLogger in interface Loggable

getLoggerFactory

public LoggerFactory getLoggerFactory()
Retrieves the logger factory instance used

Specified by:
getLoggerFactory in interface Loggable

setLoggerFactory

public void setLoggerFactory(LoggerFactory lf)
Assigns the logger factory instance to use

Specified by:
setLoggerFactory in interface Loggable

checkError

public boolean checkError()
Flush the stream and check its error state.


close

public void close()
It writes the buffer if it is not empty


flush

public void flush()
It writes the buffer if it is not empty


print

public void print(boolean x)
Print a boolean value in the buffer.


print

public void print(char x)
Print a character in the buffer.


print

public void print(char[] x)
Print an array of characters in the buffer.


print

public void print(double x)
Print a double-precision floating-point number in the buffer.


print

public void print(float x)
Print a floating-point number in the buffer.


print

public void print(int x)
Print an integer in the buffer.


print

public void print(long x)
Print a long integer in the buffer.


print

public void print(java.lang.Object x)
Print an object in the buffer.


print

public void print(java.lang.String x)
Print a string in the buffer.


println

public void println()
Send the buffer to the logger


println

public void println(boolean x)
Send the buffer and a boolean value to the logger


println

public void println(char x)
Send the buffer and a character to the logger


println

public void println(char[] x)
Send the buffer and an array of characters to the logger


println

public void println(double x)
Send the buffer and a a double-precision floating-point number to the logger.


println

public void println(float x)
Send the buffer and a floating-point number to the logger


println

public void println(int x)
Send the buffer and an integer to the logger


println

public void println(long x)
Send the buffer and a long integer number to the logger


println

public void println(java.lang.Object x)
Send the buffer and an object to the logger


println

public void println(java.lang.String x)
Send the buffer and a String to the logger


setError

protected void setError()
Indicate that an error has occurred.


write

public void write(char[] buf)
Write an array of characters in the buffer.


write

public void write(char[] buf,
                  int off,
                  int len)
Write a portion of an array of characters in the buffer.


write

public void write(int c)
Write a single character in the buffer.


write

public void write(java.lang.String s)
Write a string in the buffer.


write

public void write(java.lang.String s,
                  int off,
                  int len)
Write a portion of a string in the buffer.