4 Replies Latest reply on Aug 15, 2014 11:17 AM by davidpadilha

    My log is not working

    davidpadilha

      Hello folks!

       

      I have a jar file inside the war file that contains a log4j.properties inside META-INF ( already have tried to put one level above META-INF ):

       

      # Root logger option
      log4j.rootLogger=INFO, file
      
      # Direct log messages to a log file
      log4j.appender.file=org.apache.log4j.RollingFileAppender
      
      #Redirect to Tomcat logs folder
      #log4j.appender.file.File=${catalina.home}/logs/logging.log
      
      log4j.appender.file.File=c:\\export\\logs\mylog.log
      log4j.appender.file.MaxFileSize=10MB
      log4j.appender.file.MaxBackupIndex=10
      log4j.appender.file.layout=org.apache.log4j.PatternLayout
      log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
      

       

      When i run maven to compile my projects, it runs unit tests and the log messages goes to file "mylog.log" but when i deploy on Wildfly 8.0 and try to log something, it only logs on server.log.

       

      I'm missing some configuration but i couldn't figure what is missing.

       

      I have read the documentation and added the tag <use-deployment-logging-config value="false"/> to standalone.xml but still not working. I already have tried to put the log4j.properties inside the war file but still not working.

       

      Anyone could give me a hand to make my log works?

       

      Thank in advance.

        • 1. Re: My log is not working
          jaysensharma

          Hello,

           

             Can you attach a sample application which demonstrate your issue.  I tested with a simple WAR [1] which has a simple servlet with log4j.properties and it is able to log properly in it's own custom log.

             The WAR which i used has the following structure.

           

          Log4j2DemoWebApp.war

          |-- index.jsp

          `-- WEB-INF

              |-- classes

              |   |-- log4j.properties

              |   |-- MyServlet.java

              |   `-- servlets

              |       `-- MyServlet.class

              |-- jboss-deployment-structure.xml

              |-- lib

              |   `-- log4j-1.2.16.jar

              `-- web.xml

           

          The jboss-deployment-structure.xml  is used in order to exclude the log4j APIs which are offered by WildFly and to use the log4j jar which is placed inside the WEB-INF/lib.

           

          <jboss-deployment-structure>
            <deployment>
              <exclusions>
                <module name="org.apache.log4j"/>
              </exclusions>
            </deployment>
          </jboss-deployment-structure>
          

           

          The log4j.properties us as following:

           

          log4j.rootLogger=INFO, file

          # Direct log messages to a log file

          log4j.appender.file=org.apache.log4j.RollingFileAppender

          log4j.appender.file.File=${jboss.server.log.dir}/test.log

          log4j.appender.file.MaxFileSize=10MB

          log4j.appender.file.MaxBackupIndex=10

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

          log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

           

           

          [1] MiddlewareMagicDemos/Log4j2DemoWebApp.war at master · jaysensharma/MiddlewareMagicDemos · GitHub

          • 2. Re: My log is not working
            jamezp

            I think you're misunderstanding the use-deployment-logging-config attribute. Setting that to false tells the logging subsystem not to scan your deployment for your log4j.properties file. From what it looks like if you were to place your log4j.properties WAR/META-INF or WAR/WEB-INF/classes directory then it should work and leave the use-deployment-logging-config set to true it should work.

             

            Also make sure you're not including log4j in your WAR/WEB-INF/lib directory either.

             

            --

            James R. Perkins

            1 of 1 people found this helpful
            • 3. Re: Re: My log is not working
              jamezp
              1 of 1 people found this helpful
              • 4. Re: My log is not working
                davidpadilha

                I've done all the process again and now it's working.

                 

                I was trying to make it work only using a log4j.properties inside the jar that is a dependency from my war. When i have moved the log4j.properties to war file, everything works.

                 

                Thanks for the help.