I did an application that makes use of log4j. Everything works fine, however, when I make a jar of that application and attach it to another application the logging stops working (no log file is created). I think the problem is that this last application also includes another jar (besides mine) that already use log4j. By the way, this other jar is hadoop, and I think it is taking the log context. My log4j properties file is in classpath, as well as in the root of the jar:
log4j.logger.a.b.c=DEBUG, A1
log4j.appender.A1=org.apache.log4j.FileAppender log4j.appender.A1.File=my-log.log log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
What can I do to sort this out?
Thanks.
Firstly, what I can think of is that may be HBase's or Hadoop's log4j.properties is shadowing your log4j.properties file that's in your resources directory as, HBase is using it's own log4j.properties file first already in the classpath.
In the log4j.properties used by HBase or Hadoop, you probably don't have your 'A1' appender set which can actually log to 'my-log.log'
Secondly, If you are not configuring log4j using PropertyConfigurator.configure(path to your customLog4j.properties);
at the beginning of your application, then it's more likely that log4j.properties of the HBase or Hadoop is being picked up.
Finally, what I can suggest to experiment, if you already have not tried with PropertyConfigurator.configure()
, is to rename your application specific log4j.properties file to something else say mylog4j.properties and try using that in PropertyConfigurator as PropertyConfigurator.configure(mylog4j.properties);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With