Reputation: 17930
My application runs on Jboss AS 7.1.1.final. I needed logs to be written to DB so i wrote a custom handler: public class DataSourceHandler extends java.util.logging.Handler
.
Everything works fine but i need to get the line number and the name of the class where this log was called from and also the stacktrace if there was an error.
Before we upgraded to Jboss 7 we used log4j and we managed to get it using:
org.apache.log4j.spi.LocationInfo locationInfo = new org.apache.log4j.spi.LocationInfo(event.getThrown(), event.getSourceClassName());
org.apache.log4j.spi.ThrowableInformation throwableInfo = new org.apache.log4j.spi.ThrowableInformation(event.getThrown());
if (locationInfo != null) {
fileName = locationInfo.getFileName();
lineNumber = locationInfo.getLineNumber();
}
if (throwableInfo != null) {
String[] exceptionArray = throwableInfo.getThrowableStrRep();
for (String line : exceptionArray) {
exceptionBuffer.append(line).append(NEW_LINE);
}
info = extractInfo(exceptionBuffer);
}
How can i do it now?
Upvotes: 0
Views: 485
Reputation: 17770
That information is not provided by J.U.L. If you don't mind having a dependency on jboss-logmanger you could extend org.jboss.logmanager.ExtHandler
instead of the J.U.L. handler. That will provide you with the a org.jboss.logmanager.ExtLogRecord
that will provide that information.
You would just override the doPublish(ExtLogRecord)
instead of the J.U.L. publish method.
JBoss AS 7 uses JBoss Logging and JBoss Log Manager so that dependency would already be provided for you.
Upvotes: 1