1 2 Previous Next 15 Replies Latest reply: Dec 13, 2012 2:22 PM by Remus Vitan RSS

Jboss 7 AS and log4j.xml

Newbie

Hi,

I'm migrating an ear-File from AS 4 to AS 7. Everything but log4j is working.

I get the error:

 

16:58:26,828 ERROR [stderr] (MSC service thread 1-3) log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).

 

16:58:26,828 ERROR [stderr] (MSC service thread 1-3) log4j:WARN Please initialize the log4j system properly.

 

16:58:47,484 INFO  [org.jboss.web] (MSC service thread 1-3) registering web context: /myapp

16:58:47,875 INFO  [org.jboss.as.server.controller] (HttpManagementService-threads - 4) Deployed "myapp.ear"

 

Problem: I don't know how to do the configuration of log4j with JBoss AS 7.

 

The issue is that log4j needs a configuration file (log4j.properties?).

I have a     log4j-1.2.14.jar in myapp.ear/lib and

                log4j-1.2.16.jar in modules\org\apache\log4j\main

. Maybe they are conflicting i.e the server is using the second one wth no configuration?

 

 

What are the things you guys would try to do to fix it?

Shall I try to create a log4j.properties and what is the correct location? What can I do with my old jboss-log4j.xml? Pack it in a *.jar and copy it to /lib?

 

I tried to exlude log4j from modules\org\apache\log4j\main that JBoss uses my log4j with the configuration.

Therefore I tried to add an jboss-deployment-structure.xml in ear/META_INF:

 

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

<deployment>

   <exclusions>

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

   </exclusions>

<deployment>

</jboss-deployment-structure>

 

Any other suggestions?

Jonas

  • 2. Re: Jboss 7 AS and log4j.xml
    Newbie

    solved by packing the log4j.xml into a jar file.

    Then I put the jarf-file into ear/lib and the server found it.

  • 3. Re: Jboss 7 AS and log4j.xml
    matvei Newbie

    UPDATE, just for info, the problem was sold using the solution described here:

    https://community.jboss.org/message/725292#725292

     

    I'm just completely frustrated with jboss 7.1.1 Final and I can not understand how to make the log4j.xml working.

    It works perfect with Jboss 7.1.0.CR1b but it does not work with the last one release.

     

    I just want to have a logging config file inside EAR... no way with 7.1.1.Final.

    I've tried to put this log4j.xml in every possible place inside EAR file without success. Anyone found the difference between this 2 versions? In 7.1.0.CR1b I have problems with oracle connection, but log4j is working. Unfortunately I need both: oracle and log4j and can not use the older version.

  • 4. Re: Jboss 7 AS and log4j.xml
    Remus Vitan Newbie

    hello, have you found a solution to make it work  ?

    i refer to the use of log4j.xml in inside ear with 7.1.1 final

  • 5. Re: Jboss 7 AS and log4j.xml
    matvei Newbie

    as answered before you have to modify your deployment descriptor to exclude jboss log4j und use your own:

    http://community.jboss.org/message/622614#622614

  • 6. Re: Jboss 7 AS and log4j.xml
    Remus Vitan Newbie

    thank you for your reply ,

    i have already tried that (actually that thread contains info about log4j format and location, but that issue is solved for me  since my ear and log4j work ok in jboss as 7.1.0)

     

    i have tried exclusion with jboss-deployment-structure in a few forms found on threads around here, my log4j.xml is found in the lib dir (inside jar file)

    i have even tried with some minor modifications in standalone.xml like

    <subsystem xmlns="urn:jboss:domain:ee:1.0">

               <ear-subdeployments-isolated>false</ear-subdeployments-isolated>

    </subsystem>

     

    still, it does not work

    you have also stated that :...

    <<<

    I'm just completely frustrated with jboss 7.1.1 Final and I can not understand how to make the log4j.xml working.

    It works perfect with Jboss 7.1.0.CR1b but it does not work with the last one release.

    >>>

    have you succeded it ?

    if yes, could you please post a minimal ear that runs ok ?

  • 7. Re: Jboss 7 AS and log4j.xml
    matvei Newbie

    It works with 7.1.1, but I am on vacation at the moment, so I can not give you exact code examples. The code you wrote does not help, it's important but not anough. You have log4j automatically included in your classpath (and therefore your log4j system initilized before and your log4j.xml will be just ignored) untill you excpicitly disable it inside jboss deployment descriptor.

     

    use that code as an example:

     

    from: https://docs.jboss.org/author/display/AS7/How+do+I+migrate+my+application+from+AS5+or+AS6+to+AS7

     

    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
      <deployment>
          <dependencies>
              <module name="javax.faces.api" slot="1.2" export="true"/>
                  <module name="com.sun.jsf-impl" slot="1.2" export="true"/>
            </ dependencies>
      </deployment>
      <sub-deployment name="jboss-seam-booking.war">
        <exclusions>
              <module name="javax.faces.api" slot="main"/>
                  <module name="com.sun.jsf-impl" slot="main"/>
            </exclusions>
            <dependencies>
              <module name="javax.faces.api" slot="1.2"/>
                  <module name="com.sun.jsf-impl" slot="1.2"/>
            </dependencies>
      </sub-deployment>
    </jboss-deployment-structure>
    
    
  • 8. Re: Jboss 7 AS and log4j.xml
    Remus Vitan Newbie

    Thanks again for your clues,

    yet, i still haven't managed to get it done ...

     

    i have retried all the variants again, and also using the info provided by you, but mostly the info from :

    https://community.jboss.org/message/725292#725292#725292    (most important answers: 4, 11, 12)

     

    still, no luck ...

     

    Best Regards,

    Remus

  • 9. Re: Jboss 7 AS and log4j.xml
    Remus Vitan Newbie

    Finally ,i have made it thru

    it turns out that i forgot to mention i use slf4j, which also need to be excluded in order for it to use the binding to the log4j module from the ear/lib directory.

     

    For anyone else that has a similar problem i recomend to remove the jar from the lib dir and make the jboss-deployment-structure file.

    When you will have a good deployment structure your deployment will fail with ClassNotFound exception because exclusion of default modules will work and the jar will be missing, then you can add the jar file .

     

    In my case org.apache.log4j was never missed since org.slf4j was loaded from "implicit modules dependency" ()

    and it was already binded to the implicit module org.apache.log4j.

     

    info used:

    https://docs.jboss.org/author/display/AS7/How+do+I+migrate+my+application+from+AS5+or+AS6+to+AS7

    https://docs.jboss.org/author/display/AS7/Implicit+module+dependencies+for+deployments

     

    Thanks a lot for all your help,

    Remus

  • 10. Re: Jboss 7 AS and log4j.xml
    Stylianos Koussouris Newbie

    Remu,
    would you mind sharing
    a) the jars related to logging in your EAR/lib
    b) the jboss-deployment-structure.xml from the EAR
    c) confirm log4j.xml and jboss-deployment-structure.xml are both inside EAR/META-INF
    d) have you got any entries to those jars in the EAR/META-INF/MANIFEST.MF

    I think I am hitting a similar issue here (AS 7.1.2). My distributable is as follows:

    EAR
      -- META-INF
         -- jboss-deployment-structure.xml (content below)
      -- log4j.xml
      -- lib
         -- log4j-1.2.16
         -- perf4j-0.9.16
         -- slf4j-api-1.6.6
         -- slf4j-log4j12-1.6.6
         -- jcl-over-slf4j-1.6.6
      -- soap-ws.war
         -- impl.jar
      -- spec.jar
      -- rest-ws.war
    


     
    the jarr/wars make use of slf4j and perf4j for logging and appenders defined in the log4j.xml in the EAR

    however I get

    17:36:39,992 ERROR [stderr] (MSC service thread 1-7) log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
    17:36:39,992 ERROR [stderr] (MSC service thread 1-7) log4j:WARN Please initialize the log4j system properly.
    17:36:39,992 ERROR [stderr] (MSC service thread 1-7) log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
    


    jboss-structure-deployment.xml
    ------------------------------

    <deployment>
      <exclusions>
                <module name="org.apache.log4j"/>
                <module name="org.slf4j" />
                <module name="org.apache.commons.logging"/>
                <module name="org.log4j"/>  
                <module name="org.jboss.logging"/>   
      </exclusions>
    </deployment>
    <sub-deployment name="soap-ws.war">
            <exclusions>
                <module name="org.apache.log4j"/>
                <module name="org.slf4j" />
                <module name="org.apache.commons.logging"/>
                <module name="org.log4j"/>  
                <module name="org.jboss.logging"/>      
         </exclusions>
    </sub-deployment>
    <sub-deployment name="rest-ws.war">
            <exclusions>
                <module name="org.apache.log4j"/>
                <module name="org.slf4j" />
                <module name="org.apache.commons.logging"/>
                <module name="org.log4j"/>  
                <module name="org.jboss.logging"/>      
         </exclusions>
    </sub-deployment> 
    
  • 11. Re: Jboss 7 AS and log4j.xml
    Suman Ghosh Newbie

    Hi Folks,

     

    I'm trying to deploy my application on JBoss AS 7.1.1, and am facing a peculiar problem with logging. I have my own log4j.xml file bundled in my application, which adds 3 appenders to the root logger. Also, I have the logging subsystem configured in standalone.xml - where CONSOLE and FILE appenders are added to the root logger.

     

    But when I try to iterate through all the appenders in my java code using Logger.getRootLogger().getAllAppenders() - I find that only the 3 appenders added in the log4j.xml file. The CONSOLE & FILE appenders added in standalone.xml are NOT present in the list returned by getAllAppenders().

     

    Can someone guide me with what am I doing wrong here?

     

    Thanks & Regards,

    Suman.

  • 12. Re: Jboss 7 AS and log4j.xml
    matvei Newbie

    You simply have 2 independend logging subsystems: the first one from jboss itself (initialized upon start) and the second one - yours, initialized with your log4.xml.

  • 13. Re: Jboss 7 AS and log4j.xml
    Suman Ghosh Newbie

    Thanks Matteo! But then how do I get the root-logger for the jboss logging subsystem? By using Logger.getRootLogger() I get the root logger for the log4j logging subystem, as far as I can see it.

  • 14. Re: Jboss 7 AS and log4j.xml
    Stylianos Koussouris Newbie

    In 7.1.1 in order for your own logging system to work (based on your provided log4j.xml) to work you most probably have excluded (via jboss-deployment-structure.xml) the logging system provided by JBoss hence your app has not got access to that. After 7.1.2 you don't have to exclude anything manually as the server does it automatically if it finds log4j.xml, jboss-log4j.xml, log4j.properties files in your distributable. Check for some discussions about it below:

     

    JBoss AS 7: Logging

                http://stackoverflow.com/questions/9769000/jboss-as-7-logging

    Per-deployment logging configuration

                https://issues.jboss.org/browse/AS7-514

    Application log is cut off after switching to 7.1.2/7.2.0    

                https://community.jboss.org/thread/199923?start=15&tstart=0

    JBoss AS 7: Logging Configuration            

                https://docs.jboss.org/author/display/AS72/Logging+Configuration

1 2 Previous Next