|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--Logger
This class handles logging of messages to one or more Logger.LoggerTargets (XML DOM, file, Writer, ServletContext, etc.)
Usage:
- The typical scenario for using this class is:
- To log to an XML DOM:
Logger logger = new Logger();
logger.addTarget(new XMLDOMLoggerTarget(xmlDOM));
logger.setLogLevel(2);
logger.log(1, "Line of text to write to the log.");
- To log to a file:
Logger logger = new Logger();
logger.addTarget(new Logger.FilenameLoggerTarget("/my/log/file"));
logger.setLogLevel(2);
logger.log(1, "Line of text to write to the log.");
- To log to a Writer:
Logger logger = new Logger();
logger.addTarget(new Logger.WriterLoggerTarget(writer));
logger.setLogLevel(2);
logger.log(1, "Line of text to write to the log.");
- To log to a ServletContext:
Logger logger = new Logger();
logger.addTarget(new ServletContextLoggerTarget(objServletContext));
logger.setLogLevel(2);
logger.log(1, "Line of text to write to the log.");
- To log to multiple targets:
Logger logger = new Logger();
logger.addTarget(new XMLDOMLoggerTarget(xmlDOM));
logger.addTarget(new XMLDOMLoggerTarget(xmlDOM2));
...
logger.addTarget(new Logger.FilenameLoggerTarget("/my/log/file"));
logger.addTarget(new Logger.FilenameLoggerTarget("/my/log/file2"));
...
logger.addTarget(new Logger.WriterLoggerTarget(writer));
logger.addTarget(new Logger.WriterLoggerTarget(writer2));
...
logger.addTarget(new ServletContextLoggerTarget(objServletContext));
logger.addTarget(new ServletContextLoggerTarget(objServletContext2));
...
logger.setLogLevel(2);
logger.log(1, "Line of text to write to the logs.");
- To log to System.out:
Logger logger = new Logger();
logger.addTarget(new Logger.WriterLoggerTarget
(new PrintWriter(System.out)));
logger.setLogLevel(2);
logger.log(1, "Line of text to write to the log.");
Assumptions:
Effects:
Anticipated Changes:
- Format the data in the log file better (date/time, nesting levels, etc.)?
Or leave that job to a log file viewer?
Notes:
Implementation Notes:
Portability Issues:
| Inner Class Summary | |
static class |
Logger.Entry
This class represents a log entry that can be sent by a Logger to a LoggerTarget. |
static class |
Logger.FilenameLoggerTarget
This class implements the LoggerTarget interface, writing log entries to a named text file. |
static interface |
Logger.LoggerTarget
This interface must be implemented by any class that expects to be called by the Logger class to log entries to a target (XML DOM, file, Writer, ServletContext, etc.) |
static class |
Logger.Tester
Each class contains a Tester inner class with a main() for easier unit testing. |
static class |
Logger.WriterLoggerTarget
This class implements the LoggerTarget interface, writing log entries to a Writer. |
| Constructor Summary | |
Logger()
Constructor. |
|
| Method Summary | |
void |
addTarget(Logger.LoggerTarget target)
Add to the list of LoggerTargets to which logging is done. |
int |
getLogLevel()
Get the log level. |
java.lang.String |
getUsername()
Get the username. |
void |
log(int intLogLevel,
java.lang.String strMsg)
Log a message to the various LoggerTargets. |
static void |
logErrorSafely(Logger logger,
int intLogLevel,
java.lang.String strMsg,
java.lang.Throwable e)
Log an error message, suppressing all possible errors, even the error of passing a null value for logger. |
static void |
logSafely(Logger logger,
int intLogLevel,
java.lang.String strMsg)
Log a message, suppressing all possible errors, even the error of passing a null value for logger. |
void |
setLogLevel(int intNew)
Set the log level. |
void |
setUsername(java.lang.String strNew)
Set the username to be recorded in log entries. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Logger()
Exceptions - None.| Method Detail |
public void addTarget(Logger.LoggerTarget target)
target - An additional LoggerTarget to log to.Exceptions - None.public void setLogLevel(int intNew)
intNew - The new log level.Exceptions - None.public int getLogLevel()
Exceptions - None.public void setUsername(java.lang.String strNew)
strNew - The new username.Exceptions - None.public java.lang.String getUsername()
Exceptions - None.
public void log(int intLogLevel,
java.lang.String strMsg)
intLoglevel - Level at which to log the message.strMsg - String to write to the log entry.Exceptions - None.
public static void logSafely(Logger logger,
int intLogLevel,
java.lang.String strMsg)
logger - The Logger to pass the message to.intLoglevel - Level at which to log the message.strMsg - String to write to the log entry.Exceptions - None.
public static void logErrorSafely(Logger logger,
int intLogLevel,
java.lang.String strMsg,
java.lang.Throwable e)
logger - The Logger to pass the message to.intLoglevel - Level at which to log the message.strMsg - String to write to the log entry.e - Throwable to include in the message text.Exceptions - None.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||