Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

nl.aidministrator.util.servlets
Class ServletLog  view ServletLog download ServletLog.java

java.lang.Object
  extended bynl.aidministrator.util.servlets.ServletLog

public class ServletLog
extends java.lang.Object

Servlet Logging Util. The ServletLog requires servlets to register themselves when their doGet() or doPost() method is called. In this registration procedure, a mapping is made between the thread that the servlet is running in and the host that it handles the request for. This mapping is later used in all calls to logging-methods to look-up the host for the thread calling the logging-methods.


Field Summary
protected static java.text.SimpleDateFormat _formatter
           
protected static java.lang.String[] _levelNames
           
protected  int _logLevel
          Log level
protected  java.io.Writer _logWriter
          Writer for the log file.
protected  java.lang.String _threadName
          Name of the thread.
protected static java.util.HashMap _threadTable
          Maps Threads to ServletLogs.
protected static java.util.HashMap _writerTable
          Maps (absolute) file paths to PrintWriters.
static int ALL
           
static int ERROR
           
static int NONE
           
static int STATUS
           
static int TRACE
           
static int WARNING
           
 
Constructor Summary
ServletLog()
           
ServletLog(java.io.Writer logWriter)
           
ServletLog(java.io.Writer logWriter, int logLevel)
           
 
Method Summary
private static java.lang.String _createLogMessage(java.lang.String msg, java.lang.Object arg, int level, java.lang.String threadName)
           
private static ServletLog _createServletLog()
          Creates a ServletLog for the thread calling this method.
private static java.io.Writer _getLogWriter(java.lang.String logFile)
           
private static ServletLog _getServletLog()
          Gets the ServletLog for the thread calling this method.
protected static void _log(java.lang.String msg, java.lang.Object arg, int level)
           
 void doLog(java.lang.String msg, java.lang.Object arg, int level)
           
static void error(java.lang.String msg)
           
static void error(java.lang.String msg, int c)
           
static void error(java.lang.String msg, java.lang.Object arg)
           
 int getLogLevel()
           
 java.lang.String getThreadName()
           
static void initThread(java.lang.String logFile, int logLevel)
          Sets the log file and log level for the thread calling this method.
static void log(java.lang.String msg)
           
static void log(java.lang.String msg, int c)
           
static void log(java.lang.String msg, java.lang.Object arg)
           
 void setLogLevel(int logLevel)
           
 void setLogWriter(java.io.Writer logWriter)
           
 void setThreadName(java.lang.String threadName)
           
static void trace(java.lang.String msg)
           
static void trace(java.lang.String msg, int c)
           
static void trace(java.lang.String msg, java.lang.Object arg)
           
static void warning(java.lang.String msg)
           
static void warning(java.lang.String msg, int c)
           
static void warning(java.lang.String msg, java.lang.Object arg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
See Also:
Constant Field Values

ERROR

public static final int ERROR
See Also:
Constant Field Values

WARNING

public static final int WARNING
See Also:
Constant Field Values

STATUS

public static final int STATUS
See Also:
Constant Field Values

TRACE

public static final int TRACE
See Also:
Constant Field Values

ALL

public static final int ALL
See Also:
Constant Field Values

_formatter

protected static java.text.SimpleDateFormat _formatter

_levelNames

protected static java.lang.String[] _levelNames

_threadTable

protected static java.util.HashMap _threadTable
Maps Threads to ServletLogs.


_writerTable

protected static java.util.HashMap _writerTable
Maps (absolute) file paths to PrintWriters.


_logWriter

protected java.io.Writer _logWriter
Writer for the log file.


_logLevel

protected int _logLevel
Log level


_threadName

protected java.lang.String _threadName
Name of the thread.

Constructor Detail

ServletLog

public ServletLog()

ServletLog

public ServletLog(java.io.Writer logWriter)

ServletLog

public ServletLog(java.io.Writer logWriter,
                  int logLevel)
Method Detail

initThread

public static void initThread(java.lang.String logFile,
                              int logLevel)
Sets the log file and log level for the thread calling this method. All following log messages sent by this thread with a priority equal to or higher than the indicated logLevel will be written to the indicated log file. If 'logFile' is equal to 'null', messages will be printed to System.err.


_createServletLog

private static ServletLog _createServletLog()
Creates a ServletLog for the thread calling this method. If the thread has already created a ServletLog before, this existing ServletLog will be returned.


_getServletLog

private static ServletLog _getServletLog()
Gets the ServletLog for the thread calling this method. If no ServletLog is available, null will be returned.


_getLogWriter

private static java.io.Writer _getLogWriter(java.lang.String logFile)
                                     throws java.io.IOException

setLogWriter

public void setLogWriter(java.io.Writer logWriter)

setLogLevel

public void setLogLevel(int logLevel)

getLogLevel

public int getLogLevel()

setThreadName

public void setThreadName(java.lang.String threadName)

getThreadName

public java.lang.String getThreadName()

doLog

public void doLog(java.lang.String msg,
                  java.lang.Object arg,
                  int level)

_createLogMessage

private static java.lang.String _createLogMessage(java.lang.String msg,
                                                  java.lang.Object arg,
                                                  int level,
                                                  java.lang.String threadName)

error

public static void error(java.lang.String msg)

error

public static void error(java.lang.String msg,
                         int c)

error

public static void error(java.lang.String msg,
                         java.lang.Object arg)

warning

public static void warning(java.lang.String msg)

warning

public static void warning(java.lang.String msg,
                           int c)

warning

public static void warning(java.lang.String msg,
                           java.lang.Object arg)

log

public static void log(java.lang.String msg)

log

public static void log(java.lang.String msg,
                       int c)

log

public static void log(java.lang.String msg,
                       java.lang.Object arg)

trace

public static void trace(java.lang.String msg)

trace

public static void trace(java.lang.String msg,
                         int c)

trace

public static void trace(java.lang.String msg,
                         java.lang.Object arg)

_log

protected static void _log(java.lang.String msg,
                           java.lang.Object arg,
                           int level)