On Sep 7, 2006, at 4:13 PM, Curt Arnold wrote:
In log4j, the creation of LocationInfo parses out the method, file
and line number from a Throwable and discards it losing the rest of
the stack trace. Potential options to achieve your objective in
log4j include:
1. Create a private version of log4j where LocationInfo retains the
Throwable. Add a custom layout that wraps PatternLayout, delegate
the primary formatting to PatternLayout and have your custom layout
output the stack trace.
2. Create a utility class that adds a Throwable's stack trace to
the NDC if the level is enabled. Your code that currently looks like:
logger.debug("Hello, world");
would need to be changed using a regex to something like:
LogStack.debug(logger, "Hello, world");
the implementation of LogStack.debug would look like:
public class LogStack {
private static final FQCN = LogStack.class.getName();
private static String stackTrace() { ... }
public void debug(Logger logger, Object msg) {
if(logger.isDebugEnabled()) {
NDC.put(stackTrace());
logger.forceLog(Level.DEBUG, msg, FQCN);
NDC.pop();
}
}
}
3. Propose a modification to log4j to add the feature
4. Wait for somebody else who has already solved this problem using
log4j to respond.
5. If you aren't using AsyncAppender or another appender that would
defer processing, you could create a Throwable and capture its
stacktrace in a custom Layout. The stack trace on the Throwable
would have the stack trace of the logging call and all the internal
log4j methods between Logger.debug (for example) and your layout's
format method.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]