java - Intercepting Log4J entries -
one of our systems build wrapper around third party customized work flow product cannot change.
recently got request capture user activity data persisted else in application logs. these logs files quite few spreading across multiple machines analyzing logs extract required info relatively complex task.
creating aspects audit user actions considered ran out giving amount of third party code need decompile , at. there security restrictions activating load-time weaving on production application servers.
my initial idea redirect log outputs interested in different file (actually files) , analyze files process data. seems doable when start considering things find lot of issues deal when working files: logs rollover, no transactions, keeping track of processed , not, etc.
my second thought implement custom pattern layout , configure used logs interested in. easy write, keeping away third party code in addition sending message log file save log entry table. once in table can want starting there. code fragment below:
public class custompatternlayout extends layout { private final patternlayout patternlayout; private simplejdbctemplate simplejdbctemplate; public custompatternlayout() { system.out.println("creating custompatternlayout instance"); patternlayout = new patternlayout("%m%n"); simplejdbctemplate = new simplejdbctemplate(...); } ... protected patternparser createpatternparser(string pattern) { system.out.println("custompatternlayout: returning pattern parser"); return new patternparser(pattern); } public string format(loggingevent event) { string log = patternlayout.format(event); system.out.println("custompatternlayout: write log entry database: " + log); simplejdbctemplate.update("insert my_login_tracker (log_entry) values (?)", log); return log; }
once done added log4j.properties
log4j.appender.file=org.apache.log4j.rollingfileappender log4j.appender.file.layout=my.org.utils.logging.custompatternlayout
and can see in logs system out entries sign custom pattern layout created , configured. actual format
method never gets invoked , consequently nothing saved in table. there still lots of log entries in logs , looks custom pattern layout not used.
i used strategy before make possible output thread id in logs , worked perfectly. admit standalone java application opposed 1 running on webshere application server.
any idea cause , how address it? alternative approach job without involving lots of technologies?
thank in advance inputs.
Comments
Post a Comment