Methods Summary |
---|
private void | _log(int level, java.lang.String method, java.lang.String msg, boolean logCaller)
if ((level <= m_level) && (level >= SEVERE))
{
final Class caller = logCaller ? ClassLoaderResolver.getCallerClass (2) : null;
final StringBuffer buf = new StringBuffer (m_prefix != null ? m_prefix + ": " : "");
if ((caller != null) || (method != null))
{
buf.append ("[");
if (caller != null) // if the caller could not be determined, s_classMask is ignored
{
String callerName = caller.getName ();
if (callerName.startsWith (PREFIX_TO_STRIP))
callerName = callerName.substring (PREFIX_TO_STRIP_LENGTH);
String parentName = callerName;
final int firstDollar = callerName.indexOf ('$");
if (firstDollar > 0) parentName = callerName.substring (0, firstDollar);
if ((m_classMask == null) || m_classMask.contains (parentName))
buf.append (callerName);
else
return;
}
if (method != null)
{
buf.append ("::");
buf.append (method);
}
buf.append ("] ");
}
final PrintWriter out = m_out;
if (msg != null) buf.append (msg);
out.println (buf);
if (FLUSH_LOG) out.flush ();
}
|
private void | _log(int level, java.lang.String method, java.lang.String msg, java.lang.Throwable throwable)
if ((level <= m_level) && (level >= SEVERE))
{
final Class caller = ClassLoaderResolver.getCallerClass (2);
final StringBuffer buf = new StringBuffer (m_prefix != null ? m_prefix + ": " : "");
if ((caller != null) || (method != null))
{
buf.append ("[");
if (caller != null) // if the caller could not be determined, s_classMask is ignored
{
String callerName = caller.getName ();
if (callerName.startsWith (PREFIX_TO_STRIP))
callerName = callerName.substring (PREFIX_TO_STRIP_LENGTH);
String parentName = callerName;
final int firstDollar = callerName.indexOf ('$");
if (firstDollar > 0) parentName = callerName.substring (0, firstDollar);
if ((m_classMask == null) || m_classMask.contains (parentName))
buf.append (callerName);
else
return;
}
if (method != null)
{
buf.append ("::");
buf.append (method);
}
buf.append ("] ");
}
final PrintWriter out = m_out;
if (msg != null) buf.append (msg);
if (throwable != null)
{
final StringWriter sw = new StringWriter ();
final PrintWriter pw = new PrintWriter (sw);
throwable.printStackTrace (pw);
pw.flush ();
buf.append (sw.toString ());
}
out.println (buf);
if (FLUSH_LOG) out.flush ();
}
|
public final boolean | atINFO()A convenience method equivalent to isLoggable(INFO).
return (INFO <= m_level);
|
public final boolean | atTRACE1()A convenience method equivalent to isLoggable(TRACE1).
return (TRACE1 <= m_level);
|
public final boolean | atTRACE2()A convenience method equivalent to isLoggable(TRACE2).
return (TRACE2 <= m_level);
|
public final boolean | atTRACE3()A convenience method equivalent to isLoggable(TRACE3).
return (TRACE3 <= m_level);
|
public final boolean | atVERBOSE()A convenience method equivalent to isLoggable(VERBOSE).
return (VERBOSE <= m_level);
|
private void | cleanup()
m_out.flush ();
|
public static com.vladium.logging.Logger | create(int level, java.io.PrintWriter out, java.lang.String prefix, java.util.Set classMask)
if ((level < NONE) || (level > ALL))
throw new IllegalArgumentException ("invalid log level: " + level);
if ((out == null) || out.checkError ())
throw new IllegalArgumentException ("null or corrupt input: out");
return new Logger (level, out, prefix, classMask);
|
public static com.vladium.logging.Logger | create(int level, java.io.PrintWriter out, java.lang.String prefix, java.util.Set classMask, com.vladium.logging.Logger base)This works as a cloning creator of sorts.
if (base == null)
{
return create (level, out, prefix, classMask);
}
else
{
final int _level = level >= NONE
? level
: base.m_level;
final PrintWriter _out = (out != null) && ! out.checkError ()
? out
: base.m_out;
// TODO: do a better job of logger cloning
final String _prefix = prefix;
// final String _prefix = prefix != null
// ? prefix
// : base.m_prefix;
final Set _classMask = classMask != null
? classMask
: base.m_classMask;
return new Logger (_level, _out, _prefix, _classMask);
}
|
public static com.vladium.logging.Logger | getLogger()Returns the current top of the thread-local logger stack or the static
Logger instance scoped to Logger.class if the stack is empty.
final LinkedList stack = (LinkedList) THREAD_LOCAL_STACK.get ();
// [assertion: stack != null]
if (stack.isEmpty ())
{
return STATIC_LOGGER;
}
else
{
return (Logger) stack.getLast ();
}
|
public java.io.PrintWriter | getWriter()Provides direct access to the PrintWriter used by this Logger.
return m_out;
|
public final void | info(java.lang.String msg)A convenience method to log 'msg' from an anonymous calling method
at INFO level.
_log (INFO, null, msg, false);
|
public final boolean | isLoggable(int level)A quick method to determine if logging is enabled at a given level.
This method acquires no monitors and should be used when calling one of
log() or convenience logging methods directly incurs significant
parameter construction overhead.
return (level <= m_level);
|
public final void | log(int level, java.lang.String msg, boolean logCaller)Logs 'msg' from an unnamed calling method.
_log (level, null, msg, logCaller);
|
public final void | log(int level, java.lang.String method, java.lang.String msg, boolean logCaller)Logs 'msg' from a given calling method.
_log (level, method, msg, logCaller);
|
public final void | log(int level, java.lang.String msg, java.lang.Throwable throwable)Logs 'msg' from an unnamed calling method followed by the 'throwable' stack
trace dump.
_log (level, null, msg, throwable);
|
public final void | log(int level, java.lang.String method, java.lang.String msg, java.lang.Throwable throwable)Logs 'msg' from a given calling method followed by the 'throwable' stack
trace dump.
_log (level, method, msg, throwable);
|
public static void | pop(com.vladium.logging.Logger ctx)Requiring a context parameter here helps enforce correct push/pop
nesting in the caller code.
// TODO: add guards for making sure only the pushing thread is allowed to
// execute this
final LinkedList stack = (LinkedList) THREAD_LOCAL_STACK.get ();
try
{
final Logger current = (Logger) stack.getLast ();
if (current != ctx)
throw new IllegalStateException ("invalid context being popped: " + ctx);
stack.removeLast ();
current.cleanup ();
}
catch (NoSuchElementException nsee)
{
throw new IllegalStateException ("empty logger context stack on thread [" + Thread.currentThread () + "]: " + nsee);
}
|
public static void | push(com.vladium.logging.Logger ctx)
if (ctx == null)
throw new IllegalArgumentException ("null input: ctx");
final LinkedList stack = (LinkedList) THREAD_LOCAL_STACK.get ();
stack.addLast (ctx);
|
public static int | stringToLevel(java.lang.String level)
if (ILogLevels.SEVERE_STRING.equalsIgnoreCase (level) || ILogLevels.SILENT_STRING.equalsIgnoreCase (level))
return ILogLevels.SEVERE;
else if (ILogLevels.WARNING_STRING.equalsIgnoreCase (level) || ILogLevels.QUIET_STRING.equalsIgnoreCase (level))
return ILogLevels.WARNING;
else if (ILogLevels.INFO_STRING.equalsIgnoreCase (level))
return ILogLevels.INFO;
else if (ILogLevels.VERBOSE_STRING.equalsIgnoreCase (level))
return ILogLevels.VERBOSE;
else if (ILogLevels.TRACE1_STRING.equalsIgnoreCase (level))
return ILogLevels.TRACE1;
else if (ILogLevels.TRACE2_STRING.equalsIgnoreCase (level))
return ILogLevels.TRACE2;
else if (ILogLevels.TRACE3_STRING.equalsIgnoreCase (level))
return ILogLevels.TRACE3;
else if (ILogLevels.NONE_STRING.equalsIgnoreCase (level))
return ILogLevels.NONE;
else if (ILogLevels.ALL_STRING.equalsIgnoreCase (level))
return ILogLevels.ALL;
else
{
int _level = Integer.MIN_VALUE;
try
{
_level = Integer.parseInt (level);
}
catch (Exception ignore) {}
if ((_level >= ILogLevels.NONE) && (_level <= ILogLevels.ALL))
return _level;
else
return ILogLevels.INFO; // default to something middle of the ground
}
|
public final void | trace1(java.lang.String method, java.lang.String msg)A convenience method equivalent to log(TRACE1, method, msg).
_log (TRACE1, method, msg, true);
|
public final void | trace2(java.lang.String method, java.lang.String msg)A convenience method equivalent to log(TRACE2, method, msg).
_log (TRACE2, method, msg, true);
|
public final void | trace3(java.lang.String method, java.lang.String msg)A convenience method equivalent to log(TRACE3, method, msg).
_log (TRACE3, method, msg, true);
|
public final void | verbose(java.lang.String msg)A convenience method to log 'msg' from an anonymous calling method
at VERBOSE level.
_log (VERBOSE, null, msg, false);
|
public final void | warning(java.lang.String msg)A convenience method to log 'msg' from an anonymous calling method
at WARNING level.
_log (WARNING, null, msg, false);
|