|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.Writer
ch.javasoft.util.logging.LogWriter
public class LogWriter
The LogWriter is a special writer to support the log
formatting functionality provided by this package.
If a program wants to write some output, it might be desired to write the
output to the log file, formatted just like standard log messages. Since the
program possibly writes multiple lines, this log writer uses a cache and
flushes complete lines to the log file, using the formatter configured
with the used logger.
A sample usage of the log writer involves logging of exception traces. The
following code traces an exception to the log file, sample output is given
below. Note that a LogPrintWriter is used here, which is based on
the LogWriter:
...
catch (Exception e) {
Logger logger = Logger.getLogger("mylogger");
e.printStackTrace(new LogPrintWriter(logger, Level.WARNING));
}
Sample output looks like this
2008-09-13 10:47:45.990 main mylogger WARNING | java.lang.ArithmeticException: / by zero 2008-09-13 10:47:45.992 main mylogger WARNING | at ch.javasoft.util.logging.LogWriter.divideByZero(LogWriter.java:37) 2008-09-13 10:47:45.992 main mylogger WARNING | at ch.javasoft.util.logging.LogWriter.main(LogWriter.java:42)
| Field Summary |
|---|
| Fields inherited from class java.io.Writer |
|---|
lock |
| Constructor Summary | |
|---|---|
LogWriter(Logger logger,
Level level)
Constructor with logger and level on which the messages are logged |
|
LogWriter(String loggerName,
Level level)
Constructor with logger name and level on which the messages are logged |
|
| Method Summary | |
|---|---|
void |
close()
Calls flush() |
void |
flush()
Flushes the current content in the buffer to the log file, and clears the line buffer. |
protected String |
newLine()
The newline which is used for, default is the platform specific newline encoding as defined by the line.separator system property. |
void |
write(char[] cbuf,
int off,
int len)
Caches the characters, until a newline is detected. |
| Methods inherited from class java.io.Writer |
|---|
append, append, append, write, write, write, write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LogWriter(String loggerName,
Level level)
loggerName - the logger's namelevel - the log level to use for tracing
public LogWriter(Logger logger,
Level level)
logger - the loggerlevel - the log level to use for tracing| Method Detail |
|---|
public void write(char[] cbuf,
int off,
int len)
write in class Writerprotected String newLine()
public void flush()
flush in interface Flushableflush in class Writerpublic void close()
flush()
close in interface Closeableclose in class Writer
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||