kotkabeans
Class Log

java.lang.Object
  |
  +--kotkabeans.Log

public class Log
extends java.lang.Object

Title: Log

Description: Logs things to logfile

Copyright: Copyright (c) KORPPI-PROJEKTIRYHMÄ 2002

Company: Jyu

Usage:

To log allways use static methods Log.log("sentence");
To log only when selected to log, use named logs
Log.NamedLog debugLog = Log.getLog("debug"); debugLog.log("sentence");
To change named log active or not active
debugLog.setActive(true);


Nested Class Summary
static class Log.NamedLog
          Title: NamedLog Description: Named log file to log if this log is needed Copyright: jyu Copyright (c) 2002 Company: jty Usage: To log only when selected to log, use named logs
Log.NamedLog debugLog = Log.getLog("debug"); debugLog.log("sentence");
To change named log active or not active
debugLog.setActive(true);
 
Field Summary
protected static java.text.DateFormat df
           
protected static java.util.Collection ignoreCallsList
           
protected static java.io.PrintWriter logFile
           
protected static java.lang.String logfilename
           
protected static java.util.Map namedLogs
           
protected static boolean openTried
           
 
Constructor Summary
Log()
          Constructor opens the file one time
 
Method Summary
static void addIgnoreCallList(java.lang.String s)
          Adds a new mask to ignoreCallList
static java.lang.String getIgnoreCallsList()
          Get what words to ignore from call stack
static Log.NamedLog getLog(java.lang.String ln)
          Finds or creates named log with name ln
static java.lang.String getLogfilename()
          Get name for current logfile
static java.lang.String getStack()
          Return current call stack as string
static java.lang.String getStack(int ignoreCalls)
          Returns current call stack.
protected static void initLogFile()
          Initialize the log file one time.
static void log(java.lang.String sentence)
          Logs the sentence to log file
static void log(java.lang.String sentence, java.lang.Exception e)
          Logs the sentence and exception message and stack to logfile
static void logStack()
          Logs current call stack to logfile
static void logStack(int ignoreCalls)
          Logs current call stack to logfile
static void setIgnoreCallsList(java.lang.String ilist)
          Set list of lines to ignore from call stack
static void setLogfilename(java.lang.String lfn)
          Set logfilename.
static java.lang.String stackToString(java.lang.Throwable th)
          Returns stack as a string
static java.lang.String suppressStack(java.lang.String st, int ignoreCalls)
          Returns stack supressed with ignoreCalls from begining and then with ignoreCallsList
static java.lang.String suppressStack(java.lang.String st, int ignoreCalls, java.util.Collection ignoreCallsList)
          Returns stack supressed with ignoreCalls from begining and then with ignoreCallsList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logFile

protected static java.io.PrintWriter logFile

openTried

protected static boolean openTried

df

protected static java.text.DateFormat df

ignoreCallsList

protected static java.util.Collection ignoreCallsList

namedLogs

protected static java.util.Map namedLogs

logfilename

protected static java.lang.String logfilename
Constructor Detail

Log

public Log()
Constructor opens the file one time

Method Detail

getLog

public static Log.NamedLog getLog(java.lang.String ln)
Finds or creates named log with name ln

Parameters:
ln - Name for log to return
Returns:
if log with name ln exists, returns that, otherwise creates new

addIgnoreCallList

public static void addIgnoreCallList(java.lang.String s)
Adds a new mask to ignoreCallList

Parameters:
s - Mask to add to list

setIgnoreCallsList

public static void setIgnoreCallsList(java.lang.String ilist)
Set list of lines to ignore from call stack

Parameters:
ilist - List of "words" to ignore from call stack separated by ;

getIgnoreCallsList

public static java.lang.String getIgnoreCallsList()
Get what words to ignore from call stack

Returns:
What words to ignore from call stack

setLogfilename

public static void setLogfilename(java.lang.String lfn)
Set logfilename. NOT thread safe! Can lose log file if executed at the same time when writing to log!

Parameters:
lfn - New name for logfile

getLogfilename

public static java.lang.String getLogfilename()
Get name for current logfile

Returns:
Nam for current logfile

initLogFile

protected static void initLogFile()
Initialize the log file one time. NOT thread safe at the very first call! Can lose log file if executed at the same time when writing to existing log!


stackToString

public static java.lang.String stackToString(java.lang.Throwable th)
Returns stack as a string

Parameters:
th - - throwable where the stack is extracted
Returns:
stack from th as a string

suppressStack

public static java.lang.String suppressStack(java.lang.String st,
                                             int ignoreCalls,
                                             java.util.Collection ignoreCallsList)
Returns stack supressed with ignoreCalls from begining and then with ignoreCallsList

Parameters:
st - Stack as string to suppress
ignoreCalls - how many calls removed from begining
ignoreCallsList - String array of rows to suppress
Returns:
Suppressed stack as a string

suppressStack

public static java.lang.String suppressStack(java.lang.String st,
                                             int ignoreCalls)
Returns stack supressed with ignoreCalls from begining and then with ignoreCallsList

Parameters:
st - Stack as string to suppress
ignoreCalls - how many calls removed from begining
Returns:
Suppressed stack as a string

getStack

public static java.lang.String getStack(int ignoreCalls)
Returns current call stack. Skips calls listed in ignoreCallsList

Parameters:
ignoreCalls - how many call is ignored form the top of stack
Returns:
Current call stack as a string

getStack

public static java.lang.String getStack()
Return current call stack as string

Returns:
Current call stack as a string

logStack

public static void logStack(int ignoreCalls)
Logs current call stack to logfile

Parameters:
ignoreCalls - how many call levels ignored

logStack

public static void logStack()
Logs current call stack to logfile


log

public static void log(java.lang.String sentence)
Logs the sentence to log file

Parameters:
sentence - String to log

log

public static void log(java.lang.String sentence,
                       java.lang.Exception e)
Logs the sentence and exception message and stack to logfile

Parameters:
sentence - String to log
e - Exception to log