10 Replies Latest reply on Oct 3, 2012 8:54 AM by guinotphil

    Log4jAppenderHandler usage

    Michal Linhard Newbie

      Hi,

       

      Is there a way to plug log4j's SocketHubAppender for all AS7 logging ? I'd like to connect log output of various AS7 instances to Chainsaw.

       

      I've found org.jboss.logmanager.log4j.handlers.Log4jAppenderHandler in the project


      <groupId>org.jboss.logmanager</groupId>

      <artifactId>jboss-logmanager-log4j</artifactId>

      <version>1.0.0.GA</version>

      it's something that seems to be doing what I want but I can't use it as custom-handler

       

      <custom-handler name="CHAINSAW" module="org.jboss.logmanager.log4j" class="org.jboss.logmanager.log4j.handlers.Log4jAppenderHandler" />

       

      because I can't instantiate it without giving it the appender object.

       

      any ideas?

       

      Michal.

        • 1. Re: Log4jAppenderHandler usage
          Georges Berscheid Newbie

          Hi,

           

          I was just wondering the exact same thing. I'm trying to delegate to org.apache.log4j.net.SyslogAppender. The XSD does not allow any appender to be added directly to the logger configuration in the standalone.xml or domain.xml files.

          I looks like you're gonna have to use http://community.jboss.org/wiki/CustomLogHandlersOn701 to create your custom log handler and then delegate them to Log4jAppenderHandler.

          Also, for some reason Log4jAppenderHandler is final, so you can't extend it, which means you need to wrap it in your SocketHubHandler and delegate calls to publish, close, flush, and setFormatter manually.

          Log4jAppenderHandler uses ExtLogRecord.getMessage() to display the log message, which causes message parameters not to be substituted.

           

          Here's my custom handler: http://pastebin.com/L1QWpzkK. It's not pretty but it works. Here's the module.xml that goes with it: http://pastebin.com/MrQbkX6h

           

          Good luck,

          Georges

          • 2. Re: Log4jAppenderHandler usage
            guinotphil Apprentice

            Hello,

             

            What does replace Log4jAppenderHandler in AS 7.1.2.Final ?

            • 3. Re: Log4jAppenderHandler usage
              James Perkins Master

              The custom handlers will only accept a java.util.logging.Handler which is why it won't work for an appender. In the 7.1.2.Final tag and any newer releases we're replacing jboss-logmanager-log4j with log4j-jboss-logmanager. Confused yet?

               

              This has been renamed because log4j is now handled very differently. Instead of just being a bridge between jboss-logmanager and log4j; the library now uses the maven-shade-plugin to bring in all of log4j. The only parts replaced in this are the parts that use the log4j log manger. The project is on GitHub if you're interested.

               

              So essentially you cannot configure log4j from the logging subsystem. That will likely always be the case as log4j does not implement any of java.util.logging.

               

              --

              James R. Perkins

              • 4. Re: Log4jAppenderHandler usage
                guinotphil Apprentice

                Yeah I understand, thank you.

                 

                However in the previous AS 7 versions the class Log4jAppenderHandler allowed us to wrap a Log4j Appender into a JUL Handler. It's a shame that such a feature is not longer available.

                 

                I use a org.apache.log4j.net.SMTPAppender instance in my logging configuration, and such a feature is not available within JUL. So, it means some migration cost to another 3rd party implementation, hoping it got all the features I need.

                 

                 

                • 5. Re: Log4jAppenderHandler usage
                  David Lloyd Master

                  The custom-handler code is supposed to transparently accept log4j appenders as well - this is definitely a bug.

                  • 6. Re: Log4jAppenderHandler usage
                    David Lloyd Master

                    guinotphil wrote:

                     

                    Yeah I understand, thank you.

                     

                    However in the previous AS 7 versions the class Log4jAppenderHandler allowed us to wrap a Log4j Appender into a JUL Handler. It's a shame that such a feature is not longer available.

                     

                    I use a org.apache.log4j.net.SMTPAppender instance in my logging configuration, and such a feature is not available within JUL. So, it means some migration cost to another 3rd party implementation, hoping it got all the features I need.

                     

                     

                    This was accidental - the bridge classes are not supposed to be visible.  Instead it should be happening automatically when you configure a log4j appender in there.

                    • 7. Re: Log4jAppenderHandler usage
                      guinotphil Apprentice

                      Thank you.. I'll give it a try then...

                       

                      For the moment I considered using http://smtphandler.sourceforge.net/ instead of Log4j's SMTP Appender.

                       

                       

                      By the way, I've got another issue. Most of my code use log4's facade (or Seam 2's logger, but it relies on log4j). And using console appender in configuration.xml for my categories, I see in my console the following line

                       

                      11:51:30,009 INFO  [stdout] (MSC service thread 1-3) 11:51:30,009 INFO  [org.jboss.seam.init.Initialization] two components with same name, higher precedence wins: ................

                       

                      where it should have been / used to be on AS 7.1.1

                       

                      11:51:30,009 INFO  [org.jboss.seam.init.Initialization] two components with same name, higher precedence wins: .......

                       

                      It looks like that instead of going to the real console stdout, it goes into JBoss IO's stdout (which is then correctly handler as 'stdout' category)

                       

                      Thanks for your help

                      • 8. Re: Log4jAppenderHandler usage
                        guinotphil Apprentice

                        Looks that I'll be able to use my Log4j's appenders again soon : https://issues.jboss.org/browse/AS7-4925

                         

                        By the way, any idea abouy my console issue ?

                         

                        Regards,

                        • 9. Re: Log4jAppenderHandler usage
                          James Perkins Master

                          You would have to change one of the format patterns. On the JBoss AS side you would have to define a category as stdout and just use a %s%n for the pattern. Of course anything written to standard out would be written as is at that point.

                          • 10. Re: Log4jAppenderHandler usage
                            guinotphil Apprentice

                            Hi,

                             

                            I've just been testing JBoss AS 7.1.3 and I still got some logging issues.

                             

                            First of all, thanks to AS7-4925, I've been able to add a smtp log4j appender as a custom-handler. Great.

                             

                            Without any custom-handler defined, the logging system works fine. But when I add one or many (let's say n) custom appenders, my console is full of stdout log in addition to the standard console output.

                             

                            Where I should have only:

                            2012-10-03 14:48:53,206 ERROR [parent.child1.child2.child3] (http-/0.0.0.0:80-1) Test

                             

                            I have;

                            2012-10-03 14:48:53,206 INFO  [stdout] (http-/0.0.0.0:80-1) 45324 [http-/0.0.0.0:80-1] ERROR parent.child1.child2.child3  - Test                   x n

                            2012-10-03 14:48:53,206 ERROR [parent.child1.child2.child3] (http-/0.0.0.0:80-1) Test

                             

                            Here is my logging configuration

                             

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

                                        <console-handler name="CONSOLE">

                                            <level name="DEBUG"/>

                                            <formatter>

                                                <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                                            </formatter>

                                        </console-handler>

                                        <custom-handler name="EMAIL" class="org.apache.log4j.net.SMTPAppender" module="org.apache.log4j">

                                            <level name="INFO"/>

                                            <formatter>

                                                <pattern-formatter pattern="%d %-5p [%c] %m%n"/>

                                            </formatter>

                                            <properties>

                                                <property name="BufferSize" value="5"/>

                                                <property name="SMTPHost" value="127.0.0.1"/>

                                                <property name="From" value="root@127.0.0.1"/>

                                                <property name="To" value="root@127.0.0.1"/>

                                                <property name="Subject" value="Log"/>

                                            </properties>

                                        </custom-handler>

                                        <periodic-rotating-file-handler name="FILE">

                                            <level name="INFO"/>

                                            <formatter>

                                                <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %X{context}[%c] (%t) %s%E%n"/>

                                            </formatter>

                                            <file relative-to="jboss.server.log.dir" path="server.log"/>

                                            <suffix value=".yyyy-MM-dd-a"/>

                                            <append value="true"/>

                                        </periodic-rotating-file-handler>

                                        <root-logger>

                                            <level name="INFO"/>

                                            <handlers>

                                                <handler name="CONSOLE"/>

                                                <handler name="FILE"/>

                                            </handlers>

                                        </root-logger>

                                    </subsystem>

                             

                             

                            As you can see, I even don't use the EMAIL handler. But just the definition of it, make those console outputs ! It seems that's because of the org.apache.log4j.BasicConfigurator.configure() method that is called by org.jboss.as.logging.handlers.custom.PropertiesConfigurator constructor , and add a console appender to the root logger. Is there a reason for that ?

                             

                            Thank you for reading