0

I am using Eclipse Oxygen 2 and I have a Maven project that I am trying to run as a JAR via a shell script on a RHEL server. It runs ok but the logging is not working.

I am getting these warnings when I run the JAR.

log4j:WARN No appenders could be found for logger (com.foo.bar.foo.bar).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

I am using the log4j as a Maven dependency on my local Eclipse repo so could that be the problem? If so how would I get the jar working with my tool on the RHEL server?

MR JACKPOT
  • 206
  • 1
  • 3
  • 15
  • What about the path permissions ? – Joe Oct 02 '18 at 12:16
  • @Joe would this be the path to the log file, or the jar? – MR JACKPOT Oct 02 '18 at 12:17
  • This is a possibility, I'm not sure the problem is the path permission, anyway it worth a shot, take a look at [this answer](https://stackoverflow.com/a/7390591/3627279) and change the path to a non-root directory, and see what happens. Let me know what is the result bro. – Joe Oct 02 '18 at 13:07
  • Have you read http://logging.apache.org/log4j/1.2/faq.html#noconfig yet? Using log4j requires two config files: log4j.properties and log4j.xml. Are they present and in the right place in your deployed instance? – CPerkins Oct 02 '18 at 13:07
  • @CPerkins it works fine on Eclipse without the log4j.xml. I only have the properties file – MR JACKPOT Oct 02 '18 at 13:09
  • @CPerkins only one of these files is required; either log4j.properties or log4j.xml – sticky_elbows Oct 08 '18 at 07:38

1 Answers1

0

That error is common when you don't have a configuration file for log4j library. The library is indeed working (it is it that emits that error message, but as it says, only ERROR (and up) messages will be shown (on stderr) only). Just create a valid configuration file and put it anywhere in the classpath of your application, and you'll get the best from log4j.

By the way, the library recommends you to visit the apache site for more documentation. Have you been there? I learned all about the library from Apache site.

Luis Colorado
  • 10,974
  • 1
  • 16
  • 31
  • Hi thanks for the answer. My log4j.properties works fine when I run it on eclipse locally, but when I extract the jar of my project and run it on a Linux box, that is where I am getting the error. Do I need to put the log4j jar in the server or something? – MR JACKPOT Oct 05 '18 at 13:47
  • Put it in the classpath. for example in the META-INF directory of your project. Or in the main directory of the project (to run it from eclipse). By the way, it is asking for a `com.foo.bar.foo.bar` Do you have a Root Logger? Do you have that class/package defined in your code? – Luis Colorado Oct 05 '18 at 16:45
  • I had it in /src/main/resources and I'm sure I added that to the classpath – MR JACKPOT Oct 05 '18 at 16:48
  • try to put it above, in `/src`, in the main directory of the project. The source folders are not included in the classpath in Linux. I don't use Windows... but Linux, and I have it in.... `/src` or in `/test`. – Luis Colorado Oct 05 '18 at 16:48
  • it is somewhat weird to get to the right directory... try the base directories of the sources, the main directory, and a META-INF directory, case you have one. – Luis Colorado Oct 05 '18 at 16:52
  • Apache doc says it has to be in the classpath, but I don't have a precise idea of what the classpath is, inside eclipse. I've found the discrepancies you talk about. – Luis Colorado Oct 05 '18 at 16:54
  • Ok thanks I will try putting it under the main classpath. That foo.bar is the first class that uses log4j, so I think that is where the error comes up first. – MR JACKPOT Oct 05 '18 at 17:04
  • for testing and packagin purposes, I had it in two different directories, so I made a symbolic link for the same file to be included in the .jar file and to be used to test it inside eclipse. Cannot test it now, as I'm not in the office. sorry. – Luis Colorado Oct 05 '18 at 17:10
  • neither am I. Excited to try your solution on Monday. Cheers! – MR JACKPOT Oct 05 '18 at 17:33
  • Ok, I'll check... I see in your error message that it lacks an Appender, have you specified a non-file appender (e.g. syslog, socket) that could need a JNI library load to be able to run? – Luis Colorado Oct 05 '18 at 17:36