0

I am new to log4j! I am using IntelliJ Idea. I am deployng EAR app on Jboss 7.1.1 Final. My EAR app contains EJB and WAR packages.

So the question is - Where to put log4j.properties or log4j.xml? And do I need to initialize it in code or not?

4 Answers4

2

You can specify log4j.xml which you want to use during jvm startup by using parameter -Dlog4j.configuration=\path\to\file

Sam
  • 1,298
  • 6
  • 30
  • 65
  • it should be 'configuration' instead of 'confiuration', but it doesn't seem to work for me.. Probably, I am doing something wrong – Zhenya Mar 30 '15 at 12:12
1

you need to put it in any 'classpath' location. And use it like in the example

package com.foo;

import org.apache.log4j.Logger;

public class Bar {
   
    static Logger logger = Logger.getLogger(Bar.class);

    public void doIt() {
        logger.debug("Did it again!");
    }
}
Dred
  • 1,076
  • 8
  • 24
0

There is no need to include a log4j.xml or logging.properties configuration file with your application if you're using JBoss AS 7. The only reason to do that would be to use an appender that is not included in the JBoss AS 7 logging subsystem.

James R. Perkins
  • 16,800
  • 44
  • 60
  • How to onfigure JBoss AS 7 logging subsystem. Can it log to Database for exabple? Can I configure two or more appenders? One to file and one to Database? –  Feb 08 '13 at 09:47
  • 1
    There is no database handler (appender), but you can define as many handlers as you'd like. You can access the configuration through the web console or CLI. There is some documentation here https://docs.jboss.org/author/display/AS71/Logging+Configuration and some examples of CLI here https://docs.jboss.org/author/display/AS71/How+To – James R. Perkins Feb 08 '13 at 18:24
0

I found that a java project in intellij (not spring) must have the log4j.xml (or properties) at myproject/src/main/resources/log4j.xml

I just created the resources directory there. No other location appears to work.

I believe the reason is that the properties then get included in the build and the .jar

Richard Keene
  • 398
  • 3
  • 14