xsul
Class MLogger

java.lang.Object
  extended byxsul.MLogger

public class MLogger
extends java.lang.Object

This is very small implementation of logging for JDK 1.2 (or better) that is self-contained (it is just one class!) and is both easy to use and simple to configurable from command line by using system properties (-Dlog=...) or from inside of your application (see setCmdNames() method). To use in your application simply copy this file to your source tree, chnage package name and in your code use:

   private static final MLogger logger = Mlogger.getLogger();
   ...
   logger.fine("hellp from logger");
 

Following system properties are supported:

NOTE: the API is modelled after Log4J and JDK 1.4 logger so should be easy to switch.

Version:
$Revision: 1.8 $ $Date: 2005/02/16 05:52:51 $ (GMT)
Author:
Aleksander Slominski [http://www.extreme.indiana.edu/~aslom]

Nested Class Summary
static class MLogger.Level
           
static class MLogger.Log
          Logging class that can be switched off completly to deliver max performance if required (just set Log.ON to false)
static class MLogger.LogManager
           
 
Field Summary
static int DEFAULT_NESTING_LEVEL
           
static MLogger global
           
static java.lang.String PROPERTY_DEBUG
           
static java.lang.String PROPERTY_LOG
           
static java.lang.String PROPERTY_MULTILINE
           
static java.lang.String PROPERTY_PREFIX
           
static java.lang.String PROPERTY_SHOWTIME
           
static java.lang.String PROPERTY_WRAPCOL
           
 
Method Summary
 java.lang.Throwable caught(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Throwable thrown)
           
 java.lang.Throwable caught(java.lang.Throwable thrown)
          report that exception was caught with log message at FINER level and "CAUGHT" message
 void config(java.lang.String msg)
           
 void config(java.lang.String msg, java.lang.Throwable thrown)
           
 void entering()
          Log a method entry with Level.FINER and message "ENTRY"
 void entering(java.lang.Object param1)
          Log a method entry with Level.FINER and message "ENTRY" and parametr content appended
 void entering(java.lang.Object[] params)
          Log a method entry with Level.FINER and message "ENTRY" and parametrs content appended
 void entering(java.lang.String sourceClass, java.lang.String sourceMethod)
           
 void entering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object param1)
           
 void entering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object[] params)
           
 void exiting()
          Log a method return with Level.FINER and message "RETURN"
 java.lang.Object exiting(java.lang.Object result)
          Log a method return with Level.FINER and message "RETURN" and return value appended
 void exiting(java.lang.String sourceClass, java.lang.String sourceMethod)
           
 java.lang.Object exiting(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object result)
           
 void fine(java.lang.String msg)
           
 void fine(java.lang.String msg, java.lang.Throwable thrown)
           
 void finer(java.lang.String msg)
           
 void finer(java.lang.String msg, java.lang.Throwable thrown)
           
 void finest(java.lang.String msg)
           
 void finest(java.lang.String msg, java.lang.Throwable thrown)
           
static void formatTime(long time, java.lang.StringBuffer buf)
           
static MLogger getAnonymousMLogger()
           
 MLogger.Level getLevel()
           
static MLogger getLogger()
           
static MLogger getLogger(java.lang.String name)
           
static boolean getMultiline()
           
 java.lang.String getName()
           
static boolean getShowTime()
           
static java.io.PrintStream getSink()
           
static int getWrapCol()
           
 void info(java.lang.String msg)
           
 void info(java.lang.String msg, java.lang.Throwable thrown)
           
 boolean isConfigEnabled()
           
 boolean isFineEnabled()
           
 boolean isFinerEnabled()
           
 boolean isFinestEnabled()
           
 boolean isInfoEnabled()
           
 boolean isLoggable(MLogger.Level level)
           
 boolean isSevereEnabled()
           
 boolean isWarningEnabled()
           
 void log(MLogger.Level level, java.lang.String msg)
           
 void log(MLogger.Level level, java.lang.String msg, java.lang.Object param1)
           
 void log(MLogger.Level level, java.lang.String msg, java.lang.Object[] params)
           
 void log(MLogger.Level level, java.lang.String msg, java.lang.Throwable thrown)
           
 void logg(MLogger.Level level, java.lang.String msg)
           
 void logg(MLogger.Level level, java.lang.String msg, java.lang.Throwable thrown)
           
 void logg(MLogger.Level level, java.lang.String msg, java.lang.Throwable thrown, int nestingLevel)
           
static java.lang.String parametersToList(java.lang.Object[] params)
           
static void setCmdNames(java.lang.String names)
          Enables list of loggers passed as string parameter.
 void setLevel(MLogger.Level newLevel)
           
static void setMultiline(boolean enable)
           
static void setShowTime(boolean enable)
           
static void setSink(java.io.PrintStream ps)
           
static void setWrapCol(int i)
           
 void severe(java.lang.String msg)
           
 void severe(java.lang.String msg, java.lang.Throwable thrown)
           
 java.lang.Throwable throwing(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Throwable thrown)
           
 java.lang.Throwable throwing(java.lang.Throwable thrown)
          Log an exception thrown with Level.FINER and message "THROW" and exception appended
 java.lang.String toString()
           
 void warning(java.lang.String msg)
           
 void warning(java.lang.String msg, java.lang.Throwable thrown)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

global

public static final MLogger global

PROPERTY_PREFIX

public static final java.lang.String PROPERTY_PREFIX
See Also:
Constant Field Values

PROPERTY_LOG

public static final java.lang.String PROPERTY_LOG
See Also:
Constant Field Values

PROPERTY_SHOWTIME

public static final java.lang.String PROPERTY_SHOWTIME
See Also:
Constant Field Values

PROPERTY_DEBUG

public static final java.lang.String PROPERTY_DEBUG
See Also:
Constant Field Values

PROPERTY_WRAPCOL

public static final java.lang.String PROPERTY_WRAPCOL
See Also:
Constant Field Values

PROPERTY_MULTILINE

public static final java.lang.String PROPERTY_MULTILINE
See Also:
Constant Field Values

DEFAULT_NESTING_LEVEL

public static final int DEFAULT_NESTING_LEVEL
See Also:
Constant Field Values
Method Detail

getAnonymousMLogger

public static MLogger getAnonymousMLogger()

getLogger

public static MLogger getLogger()

getLogger

public static MLogger getLogger(java.lang.String name)

getName

public java.lang.String getName()

isLoggable

public boolean isLoggable(MLogger.Level level)

isSevereEnabled

public final boolean isSevereEnabled()

isWarningEnabled

public final boolean isWarningEnabled()

isInfoEnabled

public final boolean isInfoEnabled()

isConfigEnabled

public final boolean isConfigEnabled()

isFineEnabled

public final boolean isFineEnabled()

isFinerEnabled

public final boolean isFinerEnabled()

isFinestEnabled

public final boolean isFinestEnabled()

setLevel

public void setLevel(MLogger.Level newLevel)

getLevel

public MLogger.Level getLevel()

parametersToList

public static java.lang.String parametersToList(java.lang.Object[] params)

entering

public void entering()
Log a method entry with Level.FINER and message "ENTRY"


entering

public void entering(java.lang.String sourceClass,
                     java.lang.String sourceMethod)

entering

public void entering(java.lang.Object param1)
Log a method entry with Level.FINER and message "ENTRY" and parametr content appended


entering

public void entering(java.lang.String sourceClass,
                     java.lang.String sourceMethod,
                     java.lang.Object param1)

entering

public void entering(java.lang.Object[] params)
Log a method entry with Level.FINER and message "ENTRY" and parametrs content appended


entering

public void entering(java.lang.String sourceClass,
                     java.lang.String sourceMethod,
                     java.lang.Object[] params)

exiting

public void exiting()
Log a method return with Level.FINER and message "RETURN"


exiting

public void exiting(java.lang.String sourceClass,
                    java.lang.String sourceMethod)

exiting

public java.lang.Object exiting(java.lang.Object result)
Log a method return with Level.FINER and message "RETURN" and return value appended


exiting

public java.lang.Object exiting(java.lang.String sourceClass,
                                java.lang.String sourceMethod,
                                java.lang.Object result)

throwing

public java.lang.Throwable throwing(java.lang.Throwable thrown)
Log an exception thrown with Level.FINER and message "THROW" and exception appended


throwing

public java.lang.Throwable throwing(java.lang.String sourceClass,
                                    java.lang.String sourceMethod,
                                    java.lang.Throwable thrown)

caught

public java.lang.Throwable caught(java.lang.Throwable thrown)
report that exception was caught with log message at FINER level and "CAUGHT" message


caught

public java.lang.Throwable caught(java.lang.String sourceClass,
                                  java.lang.String sourceMethod,
                                  java.lang.Throwable thrown)

severe

public void severe(java.lang.String msg)

warning

public void warning(java.lang.String msg)

info

public void info(java.lang.String msg)

config

public void config(java.lang.String msg)

fine

public void fine(java.lang.String msg)

finer

public void finer(java.lang.String msg)

finest

public void finest(java.lang.String msg)

log

public void log(MLogger.Level level,
                java.lang.String msg)

log

public void log(MLogger.Level level,
                java.lang.String msg,
                java.lang.Throwable thrown)

log

public void log(MLogger.Level level,
                java.lang.String msg,
                java.lang.Object param1)

log

public void log(MLogger.Level level,
                java.lang.String msg,
                java.lang.Object[] params)

severe

public void severe(java.lang.String msg,
                   java.lang.Throwable thrown)

warning

public void warning(java.lang.String msg,
                    java.lang.Throwable thrown)

info

public void info(java.lang.String msg,
                 java.lang.Throwable thrown)

config

public void config(java.lang.String msg,
                   java.lang.Throwable thrown)

fine

public void fine(java.lang.String msg,
                 java.lang.Throwable thrown)

finer

public void finer(java.lang.String msg,
                  java.lang.Throwable thrown)

finest

public void finest(java.lang.String msg,
                   java.lang.Throwable thrown)

getSink

public static java.io.PrintStream getSink()

setSink

public static void setSink(java.io.PrintStream ps)

logg

public void logg(MLogger.Level level,
                 java.lang.String msg)

logg

public void logg(MLogger.Level level,
                 java.lang.String msg,
                 java.lang.Throwable thrown)

logg

public void logg(MLogger.Level level,
                 java.lang.String msg,
                 java.lang.Throwable thrown,
                 int nestingLevel)

setCmdNames

public static void setCmdNames(java.lang.String names)
Enables list of loggers passed as string parameter. Format: [logger_name:LEVEL][,...] logger_name is package[.class] or any name that was given when creating logger with MLogger.getMLogger("name"); LEVEL -s execatly name of Level such as ALL, FINE, etc. (see Level class)


getMultiline

public static boolean getMultiline()

setMultiline

public static void setMultiline(boolean enable)

getWrapCol

public static int getWrapCol()

setWrapCol

public static void setWrapCol(int i)

getShowTime

public static boolean getShowTime()

setShowTime

public static void setShowTime(boolean enable)

formatTime

public static void formatTime(long time,
                              java.lang.StringBuffer buf)

toString

public java.lang.String toString()


IU Extreme! Lab (http://www.extreme.indiana.edu)