8 Replies Latest reply on Mar 15, 2011 5:29 PM by Peter Johnson

    logging problem 5.1.0

    aodhan hoffman Newbie

      I'm running jboss 5.1.0 w/ jdk 1.6.0_18 and have a jsp page which calls a backend servlet. I want to servlet to log to a separate file, but while I am able to see the log messages in the server.log and console, I don't see them in the log I've defined. While the log file is created, nothing is added to it. It remains empty. Can someone explain as to why? Thanks.

       

      Here's my addition to the default jboss-log4j.xml config file:

       

       

            <appender name="FOO" class="org.jboss.logging.appender.RollingFileAppender">

              <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>

              <param name="File" value="${jboss.server.log.dir}/foo.log"/>

              <param name="Append" value="false"/>

              <param name="MaxFileSize" value="500KB"/>

              <param name="MaxBackupIndex" value="1"/>

       

              <layout class="org.apache.log4j.PatternLayout">

                <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>

              </layout>

         </appender>

       

         <!-- ================ -->

         <!-- Limit categories -->

         <!-- ================ -->

       

            <category name="com.boeing">

               <appender-ref ref="FOO"/>

               <priority value="DEBUG"/>

            </category>

       

      foo.log is created when I run the jsp but nothing is appended to it.

        • 1. logging problem 5.1.0
          Peter Johnson Master

          I don't see anything wrong with this configuration. I checked against mine and mine is the same (details differ, such as different category name). Are you sure that your logging code is using "com.boeing" as a prefix? And that you are logging at debug or higher? Could you post the servlet source code (you can remove the parts that don't concern logging).

          • 2. logging problem 5.1.0
            aodhan hoffman Newbie

            Here's the front facing class:

             

            import org.jboss.logging.Logger;

            import org.xml.sax.SAXException;

             

            import com.boeing.ntpm.smartnet.reportGen.DataCompiler;

             

            public class ReportGen

            {

                private static final Logger log = Logger.getLogger(ReportGen.class);

             

                public static String generateReport()

                    throws IOException, InvocationTargetException, SAXException, SQLException, InterruptedException, NamingException

                {

             

                    Context env = (Context) new InitialContext().lookup("java:comp/env");

                    String propPath = (String) env.lookup("propPath");

                    String filesPath = (String) env.lookup("filesPath");

                    Properties config = new Properties();

             

             

                    log.info( "Report starting... " + new Date().toString() );

                    log.debug( "propPath: " + propPath );

                    log.debug( "filesPath: " + filesPath );

            ...

             

            The result that shows up in the server.log file is:

             

            2011-03-15 11:25:16,686 INFO  [STDOUT] (http-127.0.0.1-8080-1) 11:25:16,686 INFO  [ReportGen] Report starting... Tue Mar 15 11:25:16 PDT 2011

            2011-03-15 11:25:16,686 INFO  [STDOUT] (http-127.0.0.1-8080-1) 11:25:16,686 INFO  [ReportGen] No properties file provided specified, using default location.

            2011-03-15 11:25:16,686 INFO  [STDOUT] (http-127.0.0.1-8080-1) 11:25:16,686 ERROR [DataCompiler] Report starting... Tue Mar 15 11:25:16 PDT 2011

            2011-03-15 11:25:16,702 INFO  [STDOUT] (http-127.0.0.1-8080-1) 11:25:16,702 FATAL [DataCompiler] Looking for nodes file at: C:/jboss-5.1.0.GA/server/default/deploy/NetDevRepWeb.war/files//nodes2.xml

            ...

             

            I guess I am also confused by the fact that the debug statements aren't coming out either. The JBoss config items are all set to INFO, but it seems that everything is going to server.log and only INFO and above is being sent there as if my additional appendor and category is being totally ignored.

            • 3. Re: logging problem 5.1.0
              Peter Johnson Master

              The problem is that your logging config says to log things starting with "com.boeing" but the entire name passed to Logger is "ReportGen". It appears that you forgot to include a package statement for your class.

               

              Also, the server log by default logs only at the INFO level, that is why the debug entries are not appearing there.

              • 4. logging problem 5.1.0
                aodhan hoffman Newbie

                My bad, I left that off along with many of the import statements:

                 

                package com.boeing.ntpm.smartnet.bean;

                 

                import java.io.BufferedInputStream;

                import java.io.FileInputStream;

                import java.io.IOException;

                import java.lang.reflect.InvocationTargetException;

                import java.sql.SQLException;

                import java.util.Date;

                import java.util.Properties;

                 

                import javax.naming.Context;

                import javax.naming.InitialContext;

                import javax.naming.NamingException;

                 

                import org.jboss.logging.Logger;

                import org.xml.sax.SAXException;

                 

                import com.boeing.ntpm.smartnet.reportGen.DataCompiler;

                 

                public class ReportGen

                ...

                • 5. logging problem 5.1.0
                  Peter Johnson Master

                  A few questions for you:

                   

                  1) Why are you using the the jboss logger instead of commons-logging? (Actually, you could use the log4j logger, but commons-logging is a better bet.)

                   

                  2) You say that you posted content from the server.log. Did you modify the logging configuration for the server log in any way? I ask because by default the server log shows the full classname, including packaging. But I see only the basic classname in the log entries. (I am wondering if the jboss logger is stripping the package name off of the classname when setting the logger name.)

                  • 6. logging problem 5.1.0
                    aodhan hoffman Newbie

                    I should clarify. I already had the full package name statement, so I am reasonably sure that is not the issue. What I am not sure of is whether I am using the correct package name in my category declaration.

                    • 7. logging problem 5.1.0
                      aodhan hoffman Newbie

                      re #1) I am using the org.jboss.logging.Logger class because I assumed it was native for the JBoss environment. I can try the apach commons logger instead and see if that works, but would that need a separate logger config file?

                       

                      re #2) I left the jboss config as default with the exception of the two entries noted at the beginning.

                      The server.log appender ('FILE') looks like this:

                       

                      <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

                       

                         <!-- ================================= -->

                         <!-- Preserve messages in a local file -->

                         <!-- ================================= -->

                       

                         <!-- A time/date based rolling appender -->

                         <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">

                            <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>

                            <param name="File" value="${jboss.server.log.dir}/server.log"/>

                            <param name="Append" value="true"/>

                            <!-- In AS 5.0.x the server log threshold was set by a system

                                 property. In 5.1 and later we are instead using the system

                                 property to set the priority on the root logger (see <root/> below)

                            <param name="Threshold" value="${jboss.server.log.threshold}"/>

                            -->

                       

                            <!-- Rollover at midnight each day -->

                            <param name="DatePattern" value="'.'yyyy-MM-dd"/>

                       

                            <!-- Rollover at the top of each hour

                            <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>

                            -->

                       

                            <layout class="org.apache.log4j.PatternLayout">

                               <!-- The default pattern: Date Priority [Category] (Thread) Message\n -->

                               <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>

                       

                               <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n

                               <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>

                                -->

                            </layout>

                         </appender>

                      ...

                       

                      Thanks!

                      • 8. logging problem 5.1.0
                        Peter Johnson Master

                        1) You don't need a separate config file to use commons-logging. I use only commons-logging in my code.

                         

                        2) The conversionPattern shows the full logging categroy being printed. So the only thing I can come up with is that the jboss logging class is removing the package name, which explains why you are not getting the log entries in your file.