log4j - ThreadLocal cannot be set after redeploying the EJB on JBOSS -
i using jboss7. store information soap request in threadlocal variable in order adding log4j header.
my threadlocal class:
class mystorage private static final threadlocal<string> storage = new threadlocal<string>(); public static void setrequestid(string requestid) { storage.set(requestid); } public static string getrequestid() { return storage.get(); } ... } my log4j appender class:
public class myrollingfileappender extends rollingfileappender { @override public void append(loggingevent event) { string reqid = mystorage.getrequestid(); event.setproperty("reqid", reqid == null ? "unknown" : reqid); super.append(event); } } log4j.properties:
log4j.appender.throttling.layout.conversionpattern=[%d{hh:mm:ss,sss}] (%properties{reqid}) (%t) [%-5p] [%c]: %m%n when start jboss first , deploy ejb working fine. can see correct requestid in log header. when redeploy ejb see in log (i added system.out.println() methods of mystorage) correct value of requestid passed method mystorage.setrequestid(...) value of requestid in log header unknown. result of mystorage.getrequestid() null too.
if restart jboss working fine again until redeploy ejb. not quite sure why happening. or there better way of passing information log4j rollingfileappender threadlocal?
thanks, v.
the solution rid of log4j , use logback. tried use mdc in log4j had same result. in logback mdc works perfectly. myrollingfileappender being executed in different thread in log4j after redeploying...
Comments
Post a Comment