Using org.apache.log4j.jdbc.JDBCAppender, how can I get stracktraces logged with warn and error into the PatternLayout.
I’m logging like
logger.warn("warning description", e);
logger.error("error description", e);
I get the String descriptions into the table, but the Throwable’s stacktrace is now where. Is there another parameter that I can access via the PatternLayout. Currently I am using
"INSERT INTO app_logs (app, log_date, log_level, location, loc, message) VALUES ('my-apps-name', '%d{ISO8601}','%p', '%C.java', '%C{1}.java:%L', '%m')"
into a table
TABLE `app_logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`app` varchar(255) DEFAULT NULL,
`log_date` varchar(255) DEFAULT NULL,
`log_level` varchar(255) DEFAULT NULL,
`location` varchar(255) DEFAULT NULL,
`loc` varchar(255) DEFAULT NULL,
`message` text,
PRIMARY KEY (`id`)
)
I found the solution.
Replace the
PatternLayoutclass with theEnhancedPatternLayoutclass.org.apache.log4j.EnhancedPatternLayoutYou’ll also need to include the apache-log4j-extra dependency
Or include it in your pom:
You now have access to %throwable
I added to my table,
And updated my pattern to populate these columns.