FileDocCategorySizeDatePackage
ServerLog.javaAPI DocphoneME MR2 API (J2ME)15899Wed May 02 18:00:42 BST 2007gov.nist.siplite.stack

ServerLog

public class ServerLog extends Object
Log file wrapper class. Log messages into the message trace file and also write the log into the debug file if needed. This class keeps an XML formatted trace around for later access via RMI. The trace can be viewed with a trace viewer (see tools.traceviewerapp).
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
public static int
TRACE_NONE
Dont trace
public static int
TRACE_MESSAGES
Trace messages.
public static int
TRACE_EXCEPTION
Trace exception processing.
public static int
TRACE_DEBUG
Debug trace level (all tracing enabled).
protected static PrintStream
printWriter
Print stream for writing out debug messages.
protected static PrintStream
traceWriter
Print stream for writing out tracing messages.
protected static String
auxInfo
Auxililary information to log with this trace.
protected static String
description
Desription for mesasge.
protected static String
stackIpAddress
Stack pointer for mesasge.
protected static int
traceLevel
Default trace level.
Constructors Summary
Methods Summary
public static voidcheckLogFile()
Checks for valid logging output destination.

    
               
        
        // Append buffer to the end of the file.
        if (printWriter == null) {
            printWriter = traceWriter;
            if (printWriter == null) printWriter = System.out;
            /*
	    if (auxInfo != null)
                printWriter.println
                        (" < description\n logDescription = \""+description+
                        "\"\n name = \"" + stackIpAddress +
                        "\"\n auxInfo = \"" + auxInfo +
                        "\"/ > \n ");
            else
                printWriter.println(" < description\n logDescription = \""
                        + description
                        + "\"\n name = \""
                        + stackIpAddress
                        + "\" / > \n");
	    */
        }
    
private static java.lang.StringgetStatusHeader(Message message)
Gets the status header from the requested message.

param
message the message being processed
return
the extracted status line

        // If this message has a "NISTStatus" extension then we extract
        // it for logging.
        Enumeration statusHeaders = message.getHeaders("NISTExtension");
        String status = null;
        if (statusHeaders.hasMoreElements()) {
            Header statusHdr = (Header) statusHeaders.nextElement();
            status = statusHdr.getHeaderValue();
        }
        return status;
    
public static intgetTraceLevel()
Gets the trace level for the stack.

return
the trace level

 return traceLevel; 
public static voidlogException(java.lang.Exception ex)
Logs an exception stack trace.

param
ex Exception to log into the log file

        if (traceLevel >= TRACE_EXCEPTION) {
            checkLogFile();
            if (printWriter != null) ex.printStackTrace();
        }
    
public static voidlogMessage(Message message, java.lang.String from, java.lang.String to, boolean sender, java.lang.String time)
Logs a message into the log directory. Status information is extracted from the NISTExtension Header.

param
message a Message to log
param
from from header of the message to log into the log directory
param
to to header of the message to log into the log directory
param
sender is the server the sender
param
time is the time to associate with the message.

        checkLogFile();
        CallIdHeader cid = (CallIdHeader)message.getCallId();
        String callId = null;
        if (cid != null)
            callId = ((CallIdHeader)message.getCallId()).getCallId();
        String firstLine = message.getFirstLine();
        String inputText = message.encode();
        String status = getStatusHeader(message);
        String tid = message.getTransactionId();
        logMessage(inputText, from, to, sender,
                callId, firstLine, status, tid, time);
    
public static voidlogMessage(Message message, java.lang.String from, java.lang.String to, boolean sender, long time)
Logs a message into the log directory. Status information is extracted from the NISTExtension Header.

param
message a Message to log
param
from from header of the message to log into the log directory
param
to to header of the message to log into the log directory
param
sender is the server the sender
param
time is the time to associate with the message.

        checkLogFile();
        CallIdHeader cid = (CallIdHeader)message.getCallId();
        String callId = null;
        if (cid != null) callId = cid.getCallId();
        String firstLine = message.getFirstLine().trim();
        String inputText = message.encode();
        String status = getStatusHeader(message);
        String tid = message.getTransactionId();
        logMessage(inputText, from, to, sender,
                callId, firstLine, status, tid, time);
    
public static voidlogMessage(Message message, java.lang.String from, java.lang.String to, boolean sender)
Logs a message into the log directory. Status information is extracted from SIPExtension header. The time associated with the message is the current time.

param
message a Message to log
param
from from header of the message to log into the log directory
param
to to header of the message to log into the log directory
param
sender is the server the sender

        logMessage(message, from, to, sender,
                new Long(System.currentTimeMillis()).toString());
    
public static voidlogMessage(Message message, java.lang.String from, java.lang.String to, java.lang.String status, boolean sender, java.lang.String time)
Logs a message into the log directory.

param
message a Message to log
param
from from header of the message to log into the log directory
param
to to header of the message to log into the log directory
param
status the status to log. This is appended to any NISTExtension header present in the message.
param
sender is the server the sender or receiver (true if sender).
param
time is the reception time.

        checkLogFile();
        CallIdHeader cid = (CallIdHeader) message.getCallId();
        String callId = null;
        if (cid != null) callId = cid.getCallId();
        String firstLine = message.getFirstLine().trim();
        String encoded = message.encode();
        String tid = message.getTransactionId();
        String shdr = getStatusHeader(message);
        if (shdr != null) {
            status = shdr + "/" + status;
        }
        logMessage(encoded, from, to, sender,
                callId, firstLine, status, tid, time);
    
public static voidlogMessage(Message message, java.lang.String from, java.lang.String to, java.lang.String status, boolean sender, long time)
Logs a message into the log directory.

param
message a Message to log
param
from from header of the message to log into the log directory
param
to to header of the message to log into the log directory
param
status the status to log. This is appended to any NISTExtension header present in the message.
param
sender is the server the sender or receiver (true if sender).
param
time is the reception time.

        checkLogFile();
        CallIdHeader cid = (CallIdHeader) message.getCallId();
        String callId = null;
        if (cid != null) callId = cid.getCallId();
        String firstLine = message.getFirstLine().trim();
        String encoded = message.encode();
        String tid = message.getTransactionId();
        String shdr = getStatusHeader(message);
        if (shdr != null) {
            status = shdr + "/" + status;
        }
        logMessage(encoded, from, to, sender,
                callId, firstLine, status, tid, time);
    
public static voidlogMessage(Message message, java.lang.String from, java.lang.String to, java.lang.String status, boolean sender)
Logs a message into the log directory. Time stamp associated with the message is the current time.

param
message a Message to log
param
from from header of the message to log into the log directory
param
to to header of the message to log into the log directory
param
status the status to log.
param
sender is the server the sender or receiver (true if sender).

        logMessage(message, from, to, status, sender,
                System.currentTimeMillis());
    
public static voidlogMessage(java.lang.String message)
Logs a message into the log file.

param
message message to log into the log file.

        // String tname = Thread.currentThread().getName();
        checkLogFile();
        String logInfo = message;
        // printWriter.println(logInfo);
        
        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180, logInfo);
        }
    
public static synchronized voidlogMessage(java.lang.String message, java.lang.String from, java.lang.String to, boolean sender, java.lang.String callId, java.lang.String firstLine, java.lang.String status, java.lang.String tid, java.lang.String time)
Logs a message into the log directory.

param
message a Message to log
param
from from header of the message to log into the log directory
param
to to header of the message to log into the log directory
param
sender is the server the sender (true if I am the sender).
param
callId CallId of the message to log into the log directory.
param
firstLine First line of the message to display
param
status Status information (generated while processing message).
param
tid is the transaction id for the message.
param
time the reception time (or date).

        
        MessageLog log = new MessageLog(message, from, to, time,
                sender, firstLine, status, tid, callId);
        logMessage(log.flush());
    
public static synchronized voidlogMessage(java.lang.String message, java.lang.String from, java.lang.String to, boolean sender, java.lang.String callId, java.lang.String firstLine, java.lang.String status, java.lang.String tid, long time)
Logs a message into the log directory.

param
message a Message to log
param
from from header of the message to log into the log directory
param
to to header of the message to log into the log directory
param
sender is the server the sender (true if I am the sender).
param
callId CallId of the message to log into the log directory.
param
firstLine First line of the message to display
param
status Status information (generated while processing message).
param
tid is the transaction id for the message.
param
time the reception time (or date).

        
        MessageLog log = new MessageLog(message, from, to, time,
                sender, firstLine,
                status, tid, callId);
        logMessage(log.flush());
    
public static voidlogMessage(java.lang.String message, java.lang.String from, java.lang.String to, boolean sender, java.lang.String callId, java.lang.String firstLine, java.lang.String status, java.lang.String tid)
Logs a message into the log directory.

param
message a Message to log
param
from from header of the message to log into the log directory
param
to to header of the message to log into the log directory
param
sender is the server the sender
param
callId CallId of the message to log into the log directory.
param
firstLine First line of the message to display
param
status Status information (generated while processing message).
param
tid is the transaction id for the message.

        String time = new Long(System.currentTimeMillis()).toString();
        logMessage
                (message, from, to, sender, callId, firstLine, status,
                tid, time);
    
public static booleanneedsLogging(int logLevel)
Checks to see if logging is enabled at a level (avoids unecessary message formatting.

param
logLevel level at which to check.
return
true if tracing the requested logging level

        return traceLevel >= logLevel;
    
public static booleanneedsLogging()
Global check for whether to log or not. ToHeader minimize the time return false here.

return
true -- if logging is globally enabled and false otherwise.

        return traceLevel >= 16;
    
public static voidsetAuxInfo(java.lang.String auxInfo)
Sets aux information. Auxiliary information may be associated with the log file. This is useful for remote logs.

param
auxInfo -- auxiliary information.

        ServerLog.auxInfo = auxInfo;
    
public static voidsetDescription(java.lang.String desc)
Sets the descriptive String for the log.

param
desc is the descriptive string.

        description = desc;
    
public static voidsetLogFileName(java.lang.String loggerURL)
Sets the log file name. (need revisit)

param
loggerURL is the name of the log file to set.

        
    
public static voidsetTraceLevel(int level)
Sets the trace level for the stack.

param
level -- the trace level to set. The following trace levels are supported:
  • 0 -- no tracing
  • 16 -- trace messages only
  • 32 Full tracing including debug messages.

        traceLevel = level;