1 2 Previous Next 19 Replies Latest reply on Apr 20, 2012 5:24 PM by apodgorsek

    Log4j properties file not working

    apodgorsek

      Hi. I can not get log4j to work on JBoss 7.1.1.Final. I have defined a fileappender and while it creates the log file correctly, but with 0bytes and everything goes to server.log instead of application.log file

       

      My pom config is as follows

       

      <dependency>

                            <groupId>log4j</groupId>

                            <artifactId>log4j</artifactId>

                            <version>1.2.14</version>

                           </dependency>

       

      and I've also added something I found on forums

       

      <build>

            <plugins>

               <plugin>

                  <artifactId>maven-war-plugin</artifactId>

                  <version>2.1.1</version>

                  <configuration>

                     <!-- Java EE 6 doesn't require web.xml, Maven needs to catch

                        up! -->

                        <archive>

                                                                  <manifestEntries>

                                                                             <Dependencies>org.apache.log4j</Dependencies>

                                                                  </manifestEntries>

                                                        </archive>

                     <failOnMissingWebXml>false</failOnMissingWebXml>

                  </configuration>

               </plugin>

            </plugins>

         </build>

       

      Ive also found something on topic of jboss-deployment-structure.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <jboss-deployment-structure>

        <deployment>

          <exclusions>

              <module name="org.apache.log4j" />

          </exclusions>

        </deployment>

      </jboss-deployment-structure>

       

      And the external properties file which I can see in logs is read and also creates C:/logs/project/project.log

       

      log4j.rootCategory=INFO, file

      log4j.appender.file=org.apache.log4j.FileAppender

      log4j.appender.file.layout=org.apache.log4j.PatternLayout

       

      log4j.appender.file.layout.ConversionPattern=%d %-5p (%13F:%L) %3x => %m%n

      log4j.appender.file.File=C:/logs/project/project.log

      log4j.category.com.myorganisation=INFO

        • 1. Re: Log4j properties file not working
          apodgorsek

          Anyone please?

          • 2. Re: Log4j properties file not working
            ctomc

            Hi,

             

            so what do you have? log4j.jar in your app or is log4j imported via dependancy? you have posted both... that might give you problems...

             

             

            --

            tomaz

            • 3. Re: Log4j properties file not working
              sfcoy

              A few questions:

              1. Is this a WAR file only deployment, with your log4j.jar in the WEB-INF/lib directory?
              2. What mechanism are you using to tell log4j where your "external" properties file is located?
              3. Have you verified that there are no other copies of log4j.properties lying around in the classpath, such as in the WEB-INF/classes directory?
              • 4. Re: Log4j properties file not working
                apodgorsek

                I would prefer using the default one, which comes with jboss if possible...i really dont care about versions. But as I have emphasized, it takes log4j.properties from the location and creates the log file specified in it, it just doesnt print in it anything...only in server log. And If i go in the debug mode in log4j. properties it also maked debug messages about jboss internals in console, so the server log gets to 50+mb easily.

                 

                A sample maven war or ear with a servlet which logs into file that is specified in a log4j.properties destination, would be appriciated.

                • 5. Re: Log4j properties file not working
                  ctomc

                  Hi,

                   

                  why don't you manage logging configuration centraly aka in loggin subsystem?

                  You can configure all you want to achive you will have centralized configuration which is easier to mentain.

                   

                  Just remove log4j.properties and import log4j/slf4j via dependancies and make sure you dont ship your own log4j/slf4j and it will work as charm

                   

                  --

                  tomaz

                  • 6. Re: Log4j properties file not working
                    apodgorsek

                    Any sample archetype/war?

                    • 7. Re: Log4j properties file not working
                      ctomc

                      no example needed, all you need is to remove log4j/slf4j/whatever jar from your war.

                       

                      and import it via dependancies

                      for instance:

                      <manifestEntries>

                        <Dependencies>org.apache.log4j</Dependencies>

                      <manifestEntries>

                      and that is it. configuration is then done in standalone.xml (or whatever you use) or console, where you can define new logger(aka category in log4j) and new appenders.

                      that is it.

                       

                      for more about how to configure logging: https://docs.jboss.org/author/display/AS71/Logging+Configuration

                       

                      --

                      tomaz

                      • 8. Re: Log4j properties file not working
                        thinksteep

                        Hi All,

                         

                        I am having similar issue. My case is little bit complex and we are using log4j.xml. I copied log4j.jar in my EAR/lib and app-log4j.xml. It seems initiation and things are going fine, but log file is with size ZERO. Everything logged to server.log.

                         

                        We have initiation class where we are loading app-log4j.xml to create logger.  I have created another for my issue. Could some one help me?

                         

                        https://community.jboss.org/thread/197945

                         

                        Thanks for your time and help.

                        • 9. Re: Log4j properties file not working
                          thinksteep

                          Never mind. I fixed it. It was issue with log4j module exclusion from jboss-deployment-structure.xml.

                          • 10. Re: Log4j properties file not working
                            apodgorsek

                            I've attached a sample of webapp which just prints out empty .log file...everything after that is just put to console appender (instead of file which is on path C:\\log\\... with log4j properties also).

                             

                            Can you also elaborate about jboss-deployment what was the solution configuration for you?

                             

                            I must stress out it is crucial for me, for configuration to be done via external .properties file which is on filesystem.

                            • 11. Re: Log4j properties file not working
                              jamezp

                              Andrej,

                              Have a look at the logging documentation, https://docs.jboss.org/author/display/AS71/How+To#HowTo-HowdoIuselog4j.propertiesorlog4j.xmlinsteadofusingtheloggingsubsystemconfiguration%3F. That should do the trick to exclude the servers log4j library. Note though that using a log4j.properties file does not allow you to change your logging configuration for your application at runtime like using the logging subsystem would.

                              • 12. Re: Log4j properties file not working
                                apodgorsek

                                As I can get it work in a simple, one module web application, it seems not to work in a multi module (web,ear,...) project.

                                 

                                Here is an example, where I also get just an empty .log file. Properties file is from a sample above.

                                • 13. Re: Log4j properties file not working
                                  apodgorsek

                                  It is rather interesting that it doesn't work in multi module project.

                                   

                                  Any help would be appriciated!

                                  • 14. Re: Log4j properties file not working
                                    sfcoy

                                    You need to make a couple of changes to fix your example:

                                     

                                    1. Remove the redundant log4j.jar file by updating to version 2.7 of the maven-ear-plugin and configure it to build skinny wars. This removes jars from the WEB-INF/lib directory that are also in the EAR/lib directory.
                                      • {code:xml}

                                                 <plugin>

                                                    <groupId>org.apache.maven.plugins</groupId>

                                                    <artifactId>maven-ear-plugin</artifactId>

                                                    <version>2.7</version>

                                                    <configuration>

                                                       <version>6</version>

                                                        <defaultLibBundleDir>lib</defaultLibBundleDir>

                                                       <skinnyWars>true</skinnyWars>

                                                       <modules>

                                                          <webModule>

                                                             <groupId>Grp</groupId>

                                                             <artifactId>Test-web</artifactId>

                                                             <contextRoot>/Test</contextRoot>

                                                          </webModule>

                                                       </modules>

                                                    </configuration>

                                                 </plugin>

                                        {code}

                                    2. Move the jboss-deployment-structure.xml file from the EJB jar to the META-INF directory of the EAR file. The maven-ear-plugin expects to find it in /src/main/application/META-INF. Note that the documentation kindly provided by James Perkins mentions placing this file only in EAR files and WAR files.
                                    1 2 Previous Next