Setting up log4j with jboss-as-7.1.1

I have read a lot on this forum, jboss docs and online to successfully configure log4j to work with jboss as 7.1.1, I don't want to use the logging subsystem in jboss. I want to use my own log4j config. My jboss server is configured offline. The following is what I did to set up the docs-based log4j:

Despite all this, I cannot get the application to log according to my log4j configuration.

My reason to use my own log4j config instead of the logging subsystem is to be able to use a custom copied file for the file size-rotate handler, as I want the rotated files to have a timestamp bound to the file name.

Help assess,

So I created a class MyHandler.java that extends from SizeRotatingFileHandler.java and I am overriding the preWrite method. MyHandler.java is in the abc package I create a subdirectory under the modules a / b / c and inside the c directory I add a jar which only has the Myhandler.class file. I add module.xml

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="a.b.c">
     <resources>
           <resource-root path="RotatingHandler.jar"/>
          <!-- Insert resources here -->
     </resources>
     <dependencies>
          <module name="org.jboss.logging"/>
     </dependencies>
</module>

      

Then in the standalone.xml file I added an entry for the custom handler

<custom-handler name="FILE3" class="a.b.c.MyHandler" module="a.b.c">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </formatter>
        <file relative-to="jboss.server.log.dir" path="srveree.log"/>
    </custom-handler>

      

When I run Jboss, it says it cannot find the abcMyHandler class. How do I resolve this error?

UPDATE: I resolved this error. There was a problem with the package structure inside the module. However, I'll still go back to the original question about setting up log4j with jboss-as-7.1.1.Final.

+3


source to share


3 answers


I was able to set up log4j using jboss. It turns out that you need to separately add exceptions for each of the satellite deployments inside the main deployment. For example, I have an ear that is jammed with banks and war files. So I added separate entries for each one in jboss-deployment-structure.xml and it worked.



<sub-deployment name="your-subdeployment.jar">
    <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>

      

+2


source


One thing you didn't mention is whether you've added the log4j library to your folder EAR/lib

. I am guessing that you probably have at least or should see other errors.

I'm not sure if log4j will have a log4j.xml

JAR inside your EAR, to be honest. I think that EAR/META-INF

would be a more appropriate place for your log4j config file.



In this case, there is no real reason to remove the registration subsystem. Also, I'm not trying to convince you to use it, but you can create your own handler easily enough to do what you want to do. You can create it on SizeRotatingFileHandler and then just add a suffix to rename .

+1


source


Consider the configuration in your standalone.xml at

<subsystem xmlns="urn:jboss:domain:logging:1.1">

      

Here you can set

<console-handler name="CONSOLE">
            <level name="DEBUG"/>
...
        <logger category="com.myCompany">
            <level name="DEBUG"/>
        </logger>
...

      

Means: Your registrar in your classes, which are in the com.myCompany package, must register with the DEBUG level.

0


source







All Articles