5 Replies Latest reply on Dec 16, 2009 7:46 AM by thomas.diesler

    JBoss OSGi logging policy

    thomas.diesler

      Logging in JBoss OSGi is done through multiple logging frameworks. There are bundles that use commons-logging, slf4j and of course jboss-logging. Ultimately all logging is routed to log4j.

      For surefire tests this is the same.

      Every (reactor) module contains a log4j configuration in

      src/test/resources/log4j.xml
      


      All surefire tests MUST write their their test log to

      target/test.log
      


      This file is processed by hudson jobs after the surefire test run.

      The log4.xml files contain these settings

       <appender name="FILE" class="org.apache.log4j.FileAppender">
       <param name="File" value="${log4j.output.dir}/test.log"/>
       ...
       </appender>
      
       <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
       <param name="Target" value="System.out" />
       <param name="Threshold" value="INFO" />
       ...
       </appender>
      
       <root>
       <!--appender-ref ref="CONSOLE"/-->
       <appender-ref ref="FILE"/>
       </root>
      


      There are many projects under the JBoss OSGi umbrella. For log file consistency and meaningful hudson console output, please respect this policy and do not change the log configuration light heartedly.

      cheers

        • 1. Re: JBoss OSGi logging policy

          We really need to sort this out. The current log4j config is unusable for me.

          I can't run tests from inside eclipse without modifying it and I'm going to
          forget to revert it from time to time on commits.

          This coupled with all the refactoring and other braindeaths is making this project
          a real problem to work on.

          • 2. Re: JBoss OSGi logging policy
            thomas.diesler

             


            I can't run tests from inside eclipse without modifying it and I'm going to
            forget to revert it from time to time on commits.


            In every projects pom there is a comment that tells you what properties to set in the eclipse test configurations to achieve the same runtime behaviour as from the command line.

            For the Framework that would be

            -Dlog4j.output.dir=${workspace_loc:jboss-osgi-framework/target}
            -Dorg.jboss.osgi.framework.launch.bootstrapPath=bootstrap/jboss-osgi-bootstrap.xml
            


            This is needed because the system properties that are defined on the surefire plugin are unfortunately not used by the eclipse test runs, which is a general problem that applies to all system properties that should be available at test runtime.

            I've seen test cases that duplicate the settings from the pom and hard code them into the test. This IMHO is not so good. Instead system properties should go into the eclipse test configuration.

            I also run tests from eclipse on a daily basis, once the props are set in eclipse its should be all good.

            • 3. Re: JBoss OSGi logging policy

              There is more to it than just setting system properties,
              and I don't start eclipse from the command line anyway.

              I also want to be able run tests and see the logging in the console.
              It's inefficient in my opinion to have to shell out to a file to inspect the logging.
              e.g. can't click on a stacktrace and go straight to the line of code that caused the problem.

              As I've said, it should be Hudson or Maven that redirects logging to a file
              using the log4j.configuration system property.

              It shouldn't automatically go there using hardwired rules embedded in the change log
              that are not suitable for everybody's working practices.

              • 4. Re: JBoss OSGi logging policy
                thomas.diesler

                 


                As I've said, it should be Hudson or Maven that redirects logging to a file using the log4j.configuration system property.


                yes, I've tried that by setting the surefire system properties. It worked for some test cases but not all. I didn't look into the log4j initialization to find out why it did not work for all cases.

                In another attempt to make you happy, I now added log4j-console.xml to the test resources.

                Please put the log4j.configuration property in your test setup like shown below. This should produce eclipse console logging.

                http://drop.io/sfodign

                • 5. Re: JBoss OSGi logging policy
                  thomas.diesler
                       You can set these VM properties in your IDE debugger to direct log4j output to a logfile or the console
                      
                          -Dlog4j.output.dir=${workspace_loc:jboss-osgi-framework/target}
                       or
                          -Dlog4j.configuration=log4j-console.xml