public class Logger
extends java.lang.Object
This class allows a single log output to be copied to multiple destinations.
The logger maintains three output destinations:
A log destination,
A console destination,
An Error destination.
Typically, these are: A log file, System.out, and System.err.
However, any PrintWriter can be used for any destination.
The same PrintWriter can be specified for multiple destinations,
or a destination can specified as null.
Duplicate messages are not sent to the same destination.
(If two separate PrintWriters are created for the same OutputStream
they do not appear as the same destination, and duplicate messages
may occur.)
In the unconfigured state, the default logger writes all messages to System.out, and error messages are also written to System.err.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String[] |
DEP_LIST
Class dependencies
|
static java.lang.String |
PNL
Platform line separator (newline on UNIX)
|
static java.lang.String |
SEPARATOR_LINE
A string of 78 dashes
|
static java.lang.String |
VERSION
Class version
|
| Constructor and Description |
|---|
Logger(java.io.PrintWriter logWriter,
java.io.PrintWriter consoleWriter,
java.io.PrintWriter errorWriter)
Create a new Logger.
This constructor does not affect the default logger. |
| Modifier and Type | Method and Description |
|---|---|
void |
configure(java.io.PrintWriter logWriter,
java.io.PrintWriter consoleWriter,
java.io.PrintWriter errorWriter)
Configure the logger.
|
java.io.PrintWriter |
getLogDest()
Get Primary log output destination.
|
static Logger |
getLogger()
Get a reference to the default Logger.
|
static Logger |
getLogger(java.io.PrintWriter logWriter,
java.io.PrintWriter consoleWriter,
java.io.PrintWriter errorWriter)
Get a reference to the default Logger.
|
LoggingReader |
getLoggingReader(java.io.Reader in,
java.lang.String id)
Get a LoggingReader that logs to the primary log destination
for this logger.
|
LoggingWriter |
getLoggingWriter(java.io.Writer out,
java.lang.String id)
Get a LoggingWriter that logs to the primary log destination
for this logger.
|
boolean |
isDebugging()
Get debug status.
|
boolean |
isTracingIo() |
void |
printConln()
Print a blank line to the console output destination.
|
void |
printConln(boolean timestamp)
Print to the console output destination with optional timestamp.
|
void |
printConln(java.lang.String message)
Print to the console output destination.
|
void |
printConln(java.lang.String message,
boolean timestamp)
Print to the console output destination with optional timestamp.
|
void |
printErrln()
Print a blank line to the error output destination.
|
void |
printErrln(boolean timestamp)
Print to the error output destination with optional timestamp.
|
void |
printErrln(java.lang.String message)
Print to the error output destination.
|
void |
printErrln(java.lang.String message,
boolean timestamp)
Print to the error output destination with optional timestamp.
|
void |
println()
Print a blank line to the primary log output destination.
|
void |
println(boolean timestamp)
Print to the primary log output destination with optional timestamp.
|
void |
println(java.lang.String message)
Print to the primary log output destination.
|
void |
println(java.lang.String message,
boolean timestamp)
Print to the primary log output destination with optional timestamp.
|
void |
setDebugging(boolean debug)
Set or clear debug mode.
|
void |
setTracingIo(boolean ioTrace) |
public static final java.lang.String VERSION
public static final java.lang.String[] DEP_LIST
public static final java.lang.String SEPARATOR_LINE
public static final java.lang.String PNL
public Logger(java.io.PrintWriter logWriter,
java.io.PrintWriter consoleWriter,
java.io.PrintWriter errorWriter)
logWriter - PrintWriter to log destinationconsoleWriter - PrintWriter to console destinationerrorWriter - PrintWriter to error destinationpublic static Logger getLogger()
public static Logger getLogger(java.io.PrintWriter logWriter, java.io.PrintWriter consoleWriter, java.io.PrintWriter errorWriter)
If the default Logger has not been configured, configure it using the
passed parameters. If the default Logger has already been configured,
ignore the passed parameters.
This is useful in a servlet context, where peer servlets use
the same log.
logWriter - PrintWriter to log destinationconsoleWriter - PrintWriter to console destinationerrorWriter - PrintWriter to error destinationpublic void configure(java.io.PrintWriter logWriter,
java.io.PrintWriter consoleWriter,
java.io.PrintWriter errorWriter)
logWriter - consoleWriter - errorWriter - public void println()
public void println(java.lang.String message)
message - The message to be printedpublic void println(boolean timestamp)
timestamp - If true, print a time-stamppublic void println(java.lang.String message,
boolean timestamp)
message - The message to be printedtimestamp - If true, time-stamp the messagepublic void printConln()
public void printConln(java.lang.String message)
message - The message to be printedpublic void printConln(boolean timestamp)
timestamp - If true, print a time-stamppublic void printConln(java.lang.String message,
boolean timestamp)
message - The message to be printedtimestamp - If true, time-stamp the messagepublic void printErrln()
public void printErrln(java.lang.String message)
message - The message to be printedpublic void printErrln(boolean timestamp)
timestamp - If true, print a time-stamppublic void printErrln(java.lang.String message,
boolean timestamp)
message - The message to be printedtimestamp - If true, time-stamp the messagepublic boolean isDebugging()
public void setDebugging(boolean debug)
debug - If true, set debug modepublic boolean isTracingIo()
public void setTracingIo(boolean ioTrace)
public java.io.PrintWriter getLogDest()
public LoggingReader getLoggingReader(java.io.Reader in, java.lang.String id)
in - The base input readerid - Id to use for the log entriespublic LoggingWriter getLoggingWriter(java.io.Writer out, java.lang.String id)
out - The base output writerid - Id to use for the log entries