org.objectweb.util.monolog.wrapper.printwriter

Class PrintWriterImpl

Implemented Interfaces:
Loggable

public class PrintWriterImpl
extends 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 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

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(Object x)
Print an object in the buffer.
void
print(String x)
Print a string in the buffer.
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
println()
Send the buffer to the logger
void
println(Object x)
Send the buffer and an object to the logger
void
println(String x)
Send the buffer and a String 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
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(String s)
Write a string in the buffer.
void
write(String s, int off, int len)
Write a portion of a string in the buffer.
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.

Field Details

currentLine

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


errors

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


level

protected int level


logger

protected Logger logger
The inner logger instance


loggerFactory

protected LoggerFactory loggerFactory

Constructor Details

PrintWriterImpl

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

Parameters:
l - is the logger toward which the message must be send


PrintWriterImpl

public PrintWriterImpl(Logger l,
                       int level)
            throws 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.


PrintWriterImpl

public PrintWriterImpl(Logger logger,
                       LoggerFactory loggerFactory)
            throws 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

Method Details

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


getLevel

public int getLevel()


getLogger

public Logger getLogger()
Retrieves the logger instance used
Specified by:
getLogger in interface Loggable


getLoggerFactory

public LoggerFactory getLoggerFactory()
Retrieves the logger factory instance used
Specified by:
getLoggerFactory in interface Loggable


print

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


print

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


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.


println

public void println()
Send the buffer to the logger


println

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


println

public void println(String x)
Send the buffer and a String 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


setError

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


setLevel

public void setLevel(int level)


setLogger

public void setLogger(Logger logger)
Assigns the logger instance to use
Specified by:
setLogger in interface Loggable


setLoggerFactory

public void setLoggerFactory(LoggerFactory lf)
Assigns the logger factory instance to use
Specified by:
setLoggerFactory in interface Loggable


write

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


write

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


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.