Can't make IntelliJ see my log4j.properties file

I'm running a little console app from IntelliJ using the Run->Run menu.  I have a log4j.properties file in a folder called resouces.  I can't get IntelliJ to see this file.  When I run my app, I do not get the logging in the console window I expect.   When I remove my log4j.properties file, I do not get the typical "you must configure log4j properly" warning.  All signs point to another log4j.properties file being in the classpath.  But there isn't one.  I've tried putting my properties file in the src directory, making resources a source directory from project properties, making the resources folder a library module, and specifying the file using -D on the VM line.

I'm new to 9.* and am using the 'community version' of IntelliJ here at home.

I'm using a Mac.

I'm out of ideas.  Any suggestions?

10 comments

When something seems insane, check your assumptions.

1

When I read a log4j file from the class path I just add the directory that contains the file to the classpath via a Module Library (although your post says you have already tried that).

At the risk of stating the obvious, I assume you are trying to read in the file like this?

    PropertyConfigurator.configure(YourClass.class.getClassLoader().getResource("log4j.properties"));

0

No, I have never had to explicity read a log4j.properties file before.

This is how I create the logger:

private final static Logger log = Logger.getLogger(ExTest.class.getName());

Logger is likely reading the file.

0

Also, try taking log4j out of the equation and see if you can load the property file yourself:

       Properties props = new Properties();         try {             final InputStream inStream = YourClass.class.getClassLoader().getResourceAsStream("log4j.properties");             if (inStream != null) {                 props.load(inStream);             } else {                 System.out.println("not on classpath");             }         } catch (IOException e) {             logger.error("Exception ", e);         }         for (Map.Entry<Object, Object> entry : props.entrySet()) {             System.out.println(entry);         }

0

That code displays my log4j.properties file as we'd expect it to.  Perhaps my properties file is hosed and Log4J is using a default configuration.

How did you format the code to make it look like that?

0

I usually explicitly read in the file so there are no surprises.

You can try the code snippet to at least see if it your log4j.properties is on the classpath.

Also, make sure you haven't set the system property "log4j.defaultInitOverride" to something other than false (that will cause log4j's default configuration procedure to be skipped)

0

Click on the double arrows and you will see this:

Screen shot 2010-09-22 at 9.50.01 AM.png

0

Ok, I am a moron indeed.  I had imported the stock Logger, not log4j.  They are similar enough that the code compiles but obviously the stock logger doesn't read the log4j.properties file.

Sorry to waste your time.

0

Don't worry, you aren't the first one that has happened to:) (I was going to mention to make sure you hadn't accidentally imported java.util.Logger but then forgot to)

Usually it happens if you use Logger before you have added log4j to the project's classpath.

If you are using Intellij9 it has a very nice feature to prevent this. Under Settings->Editor->Auto Import there is a Exclude from Import and Completion option where you can tell it to ignore java.util.loggin  (believe this was introduced in 9.x). My settings:

Screen shot 2010-09-22 at 10.02.40 AM.png

0

Basically you can say, "This package is so disruptive that I never want to add it to my project" :^O

0

Please sign in to leave a comment.