1 2 Previous Next 16 Replies Latest reply: May 28, 2013 7:09 PM by Victor Torrez Campos RSS

Log4j setting when using JBoss as 7.1.1.Final

hantsy bai Master

I also encouterned the log4j configuration in JBoss 7.1.1.Final, no doubt I had read the related reference doc and forum posts. but i can not find the solution for my project,

 

 

 

1. I want to use log4j and slf4j together in my project, and I want to use standalone log4j configuration for my project. so I do not want to config it in the JBoss AS.

 

2. I excluded log4j in the jboss deplyment file in my project as described in the user gudie.

 

2. my config file conftent is :

    #### Use two appenders, one to log to console, another to log to a file  
    log4j.rootCategory=INFO, stdout, R  
      
    #### First appender writes to console  
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender  
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  
      
    # Pattern to output the caller's file name and line number.  
    log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F%L) - %m%n  
      
    #### Second appender writes to a file  
    log4j.appender.R=org.apache.log4j.RollingFileAppender  
    log4j.appender.R.File=tickler-project.log  
      
    # Control the maximum log file size  
    log4j.appender.R.MaxFileSize=10000KB  
    # Archive log files (one backup file here)  
    log4j.appender.R.MaxBackupIndex=10  
      
    log4j.appender.R.layout=org.apache.log4j.PatternLayout  
    log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n  
    
    log4j.logger.com.company=DEBUG
    log4j.logger.org.apache.velocity=INFO

 

 

The result is it alwasy using "INFO" level in my project.

 

My purpose is using "DEBUG" in my classes, and otthers are using "INFO"....

 

log4j.logger.com.company=DEBUG

 

I used the similar configurations in serveral projects, run on tomcat or JBoss 7.0.x, it worked well.

 

Is this is a bug or I omitted something some where?

  • 1. Re: Log4j setting when using JBoss as 7.1.1.Final
    James Perkins Master

    Can you paste an example of the log? My guess would be your seeing the stdout wrapped in an INFO messages. My guess is you're seeing something like the following.

     

    08:21:01,648 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) log4j:DEBUG Some message
    

     

    If that's the case there is not a lot you can do. You could define a logger with a category stdout and give it a format of "%s%n". It seems it should work, though I admit I didn't test it.

     

    --

    James R. Perkins

  • 2. Re: Log4j setting when using JBoss as 7.1.1.Final
    hantsy bai Master

    yes...it printed out the INFO message...

     

     

    10:23:00,418 INFO  [com.company.security.TicklerAuthenticator] (http-localhost-127.0.0.1-8080-2) Logging in hantsy
    

     

     

    But the DEBUG messages for my project is not printed out.

     

     

    Regards

    hantsy

  • 3. Re: Log4j setting when using JBoss as 7.1.1.Final
    James Perkins Master

    In that case it doesn't look like your log4j configuration is being picked up. Is this a WAR or EAR? Where is the log4j configuration file located?

     

    Also make sure you included a log4j library in your deployment. There is some information on the documentation too.

     

    --

    James R. Perkins

  • 4. Re: Log4j setting when using JBoss as 7.1.1.Final
    hantsy bai Master

    it worked...but only print the INFO level info...I included two INFO message in my project, one for ApplciationInitializer and one for logged in, I saw the two messages when it was deployed into JBoss AS.

     

    I have read the JBoss AS docuement, excluded the log4j dependencies in the deployment file, and added my log4j in my proejct.

     

    My project is WAR packing. log4j.properties is in the classpath(src/main/resources), jboss-deployment-structure is in WEB-INF.

  • 5. Re: Log4j setting when using JBoss as 7.1.1.Final
    James Perkins Master

    It looks like the messages aren't using log4j's log manager. The pattern in the message you provided doesn't match the pattern in your log4j configuration file.

     

    Try moving the jboss-deployment-structure.xml to the META-INF directory.

     

    --

    James R. Perkins

  • 6. Re: Log4j setting when using JBoss as 7.1.1.Final
    hantsy bai Master

    the same result...

     

    The jbosss deployment strcuture, either I put it into /META-INF or /WEB-INF or /WEB-INF/classes/META-INF, I got the same result.

     

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

     

    the log4.properties file, I think I must put into into the class path...I put it into /src/main/resouces, finally deployed into /WEB-INF/classes. if put it into the  /WEB-INF/lib, I will got an error from Prettyfaces. I do not understand what is the "lib" in the JBoss documentation.

     

     

    Log4j dependencies delcaration in pom.xml.

     

    <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.6.2</version>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.16</version>
                <scope>runtime</scope>
            </dependency>
    
  • 7. Re: Log4j setting when using JBoss as 7.1.1.Final
    James Perkins Master

    Hmmm... ...I'm not to sure what it could be. Is the WAR in an EAR by chance?

     

    --

    James R. Perkins

  • 8. Re: Log4j setting when using JBoss as 7.1.1.Final
    hantsy bai Master

    A war package for the whole project, not EAR.

  • 9. Re: Log4j setting when using JBoss as 7.1.1.Final
    James Perkins Master

    Short of actually trying to deploy the same application I'm not sure what the issue could be. It seems like everything is setup okay, so I'm just not sure. I've successfully tested apps before with log4j.

     

    --

    James R. Perkins

  • 10. Re: Log4j setting when using JBoss as 7.1.1.Final
    hantsy bai Master

    OK...I am not sure if this can be considered as a bug ...I have just updated my seam3-sandbox project on github, added deployment for jboss 7.1.1.Final.

     

    https://github.com/hantsy/seam3-sandbox

     

    I have just tried in JBoss 7.0.2.Final and JBoss 7.1.1.Final.

     

    For jboss 7.0.2.Final:

     

    mvn clean packaget jboss-as:deploy -Pjboss7
    

     

    For JBoss 7.1.1.Final:

     

    mvn clean package jboss-as:deploy -Pjboss71
    

     

    If this is a bug, I will a new issue on JBoss JIRA.

     

    BTW, the sandbox is a sample project where I was trying to use JBoss seam3 projects...do not care about the code quaulity here, care the logging only.

  • 11. Re: Log4j setting when using JBoss as 7.1.1.Final
    James Perkins Master

    Got it. You also need to exclude slf4j.

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

     

     

    That seemed to do the trick for me.

     

    --

    James R. Perkins

  • 12. Re: Log4j setting when using JBoss as 7.1.1.Final
    hantsy bai Master

    Exactly, thanks

  • 13. Re: Log4j setting when using JBoss as 7.1.1.Final
    Victor Torrez Campos Newbie

    Hi, sorry I ran into the same problem, try following the steps but still I can not fix it
    I create a file jboss-deployment-structure.xml in the / META-INF but still do not show the debug, the info if the log shows
    I think my project has the same structure and I think my problem would be solved in the same way, but maybe I'm missing some step
    They could tell me what to do step by step to solve this problem, I'm new in this

    Thanks in advance

  • 14. Re: Log4j setting when using JBoss as 7.1.1.Final
    James Perkins Master

    Are you using JBoss AS 7.1.1.Final as well? Excluding the logging dependencies should be all you need to do with JBoss AS 7.1.x.Final. If you have other logging dependencies, like commons-logging, you might need to exclude those as well.

     

    Also if it's an EAR you would need to exclude the logging dependencies for each subdeployment as well.

     

    --

    James R. Perkins

1 2 Previous Next