11 Replies Latest reply on Jan 6, 2011 12:55 PM by aslak

    Redirect log jboss-logging messages to maven console possible?

    sunfire

      My test classes reproduce some logging messages with jboss-logging. Now when I run the test with Arquillian the log messages are written to the AS log/console. For tests it would be quite helpful to redirect the logging from the test classes to the maven console so saving them in e.g. Hudson build logs. Right now I only see the servermanager messages in the maven console.

       

      Is it possible to somehow redirect the log output generated by the test classes to the same console as used by the servermanager?

        • 1. Re: Redirect log jboss-logging messages to maven console possible?
          aslak

          We do have a open issue on that, research how:  https://issues.jboss.org/browse/ARQ-53

           

          It should be possible using log4js SimpleSocketServer / SocketAppender. Configuring the log4j.properties in your deployment to use the SocketAppender, while writing a little Arquillian extensionn that registeres a EventHandler on BeforeSuite to start the SimpleSocketServer and shuting it down in AfterSuite.

           

          Let me know if you want to try it, I'll guide you through the steps..

          • 2. Re: Redirect log jboss-logging messages to maven console possible?
            sunfire

            Sounds fair to me. The only thing I don't know how to do would be writing an Arqullian extension. If you could point me into the right direction I'll try implement this solution.

             

            Thanks

            • 3. Re: Redirect log jboss-logging messages to maven console possible?
              aslak

              Create a EventHandler that can startup the SimpleSocketServer in a new Thread.

              Create a EventHandler that can shutdown the SimpleSocketServer

               

               

              Register these handlers into Arquillian core by creating a impl of the SuiteContextAppender SPI alla:

              https://github.com/arquillian/arquillian/blob/master/extensions/selenium/src/main/java/org/jboss/arquillian/selenium/event/SeleniumServerContextAppender.java

              https://github.com/arquillian/arquillian/blob/master/extensions/selenium/src/main/resources/META-INF/services/org.jboss.arquillian.spi.SuiteContextAppender

               

              That should get you started, whne that is up and running, we can look into auto adding the log4j.properties file to the deployment, making a optional extensions configuration so we can configure the listener ip/port (in case someone gets a conflict with the default) and auto bundle the needed classes for the server side to do the callback.

              1 of 1 people found this helpful
              • 4. Re: Redirect log jboss-logging messages to maven console possible?
                sunfire

                I have had a few minutes now and hacked something together.

                 

                There are a few issues I am facing now:

                 

                1. for some reason SuiteContextAppender is called twice. For rapid prototyping sake I had to set a static marker in order to only register the handlers once.

                2. seems like the AfterSuite event is never fired or at least the shutdown handler is never called. So right now I can't gracefully shutdown the socketserver.

                3. the last but strangest issue is setting up the SocketAppender on-the-fly on the server. For now I just used following code:

                 

                @Test
                public void socketAppenderTest() {

                 

                        final SocketAppender socketAppender = new SocketAppender("127.0.0.1", 9876);
                        socketAppender.setName("foobar");
                       
                        Logger.getRootLogger().addAppender(socketAppender);
                       
                        if(Logger.getRootLogger().isAttached(socketAppender)) {
                            LOGGER.debug("SocketAppender attached!");
                        }
                   
                        LOGGER.debug("!!!!!!TEST!!!!!!");

                 

                        socketAppender.close();
                        Logger.getRootLogger().removeAppender(socketAppender);

                 

                }

                 

                Now it seems that the SocketAppender is connecting to the SocketServer I am starting up in the BeforeSuite handler (I reimplemented log4j SocketServer and SocketNode classes in order to make it gracefully stoppable in AfterSuite handler):

                 

                Here is the maven console log showing the incoming ClientAppender connection from 127.0.0.1 and the new thread witing for incoming log messages:

                16662 [Thread-4] INFO  Log4JSocketServer  - Connected to client at /127.0.0.1
                16662 [Thread-4] INFO  Log4JSocketServer  - Starting new socket node.
                16663 [Thread-4] INFO  Log4JSocketServer  - Waiting to accept a new client.
                16663 [Thread-6] DEBUG Log4JSocketServer  - Waiting for object message

                 

                BUT the message "SocketAppender attached!" is never logged anywhere. Neither on the AS console nor on the SocketServer. "!!!!!!TEST!!!!!!" is logged to AS console tho.

                 

                Matter of fact nothing is ever sent to the SocketServer... no Idea why.

                 

                So the summary of the problem ist that the programmatically added SocketAppender is connecting to the SocketServer fine but nothing is ever sent to it no matter what loglevel I set/use anywhere (I verified that with tcpdump).

                 

                Any thoughts what I may be doing wrong? It seems to me that the addAppender() is not working right but there is not expetion or error anywhere to be seen indicating what may be the problem.

                • 5. Re: Redirect log jboss-logging messages to maven console possible?
                  aslak

                  Which JBoss AS v are you using? JBoss 6 does not use log4j so i think it should accept what ever you use in your deployment, JBoss AS 5 use log4j, so it might be that the logging service is overriding your settings..

                  • 6. Re: Redirect log jboss-logging messages to maven console possible?
                    sunfire

                    Yes, I do use AS 6 but when I do import log4j classes for regular logging in my EJB's it just works as it has been in AS 5:

                     

                    import org.apache.log4j.Logger;

                     

                    private final static Logger LOGGER = Logger.getLogger(SomeBeanTest.class);

                     

                    So I assume log4j is still present and working in AS 6, no?

                    • 7. Re: Redirect log jboss-logging messages to maven console possible?
                      aslak

                      Have you tried adding a log4j.xml file to the deployment defining the socketappender and initialize Log4j like you normally would? e..g Logger log = Logger....get..  ?

                      • 8. Re: Redirect log jboss-logging messages to maven console possible?
                        sunfire

                        Yes I did add a log4j.properties with a configured SocketAppender to the test deployment but without success.

                        When I add it to the deployment the logger doesn't even connect to the SocketServer anymore.

                         

                        Well I guess for the moment I'll just write a little shell script for Hudson that will add the test AS logfile to the build logs.

                         

                        Thanks for helping anyways - certainly teached me some new ways of how to extend Arquillian.

                        • 9. Re: Redirect log jboss-logging messages to maven console possible?
                          aslak

                          It's probably easier to write a little arq specific logger that does what we need, instead of trying to rely on 50 diff interpetations of how logging is done inside a container.

                          • 10. Re: Redirect log jboss-logging messages to maven console possible?
                            sunfire

                            That is true and I was already thinking about it. The drawback and reason why I was deciding against it was that such a solution would only cover log messages explicitly written to the ARQ logger instance within the test classes. Log messages written within the tested classes that are using the regular container mechanisms (Logger.getLogger()) would still only log to the container.

                            • 11. Re: Redirect log jboss-logging messages to maven console possible?
                              aslak

                              true, good point..