How can 2 jar libraries use log4j independently? How can 2 jar libraries use log4j independently? hadoop hadoop

How can 2 jar libraries use log4j independently?


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);


You say you are using Hadoop. Are you running this on an HDFS? If so Hadoop is configured to use the log4j properties file located on HDFS. So you would need to update that log file.

In general, log4j.properties contained within jar files are ignored. This is because it is the driving application that should have control of what logging it wants done regardless of what logging the libraries that it uses want. If I am creating an app I don't have a log file created for every library I use. I use a single log4j config file and from there can control the logging of all libraries.


as you said the application which you are creating has log4j, that doesnt matter when you are making it into jar, because jar wont have your log4j while devloping , once you convert it to jar. all you need to know aware is , that you need use logger same as the application which your jar will be added as dependency.

let us if it war and your jar will be part of it, then you jar will use the log4j property which war uses. so you need to check whether you use same log4j which your target application uses, and also check the log property file and it logger file, you may get your jar logs there may be, i mean the different log file location than what you have configure in you jar log4j file property