13 Replies Latest reply on Nov 21, 2011 8:38 AM by Prasad Deshpande

    AS7 Logging configuration

    Prasad Deshpande Expert

      Hi Guys,

       

      I might be missing something in my configuration, could anyone please tell me exactly what do I need to do in following case?

       

      I have a class in a war file which has a logger defined as

       

      private static Log mylogger = LogFactory.getLog("myLogger");

       

      and in configuration I've specified handler as

       

              <periodic-rotating-file-handler name="XMLFILE" autoflush="true">
                  <level name="DEBUG"/>
                  <formatter>
                      <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                  </formatter>
                  <file relative-to="jboss.server.log.dir" path="my-xml.log"/>
                  <suffix value=".yyyy-MM-dd"/>
              </periodic-rotating-file-handler>

       

      & logger as

       

              <logger category="myLogger">
                  <level name="DEBUG"/>
                  <handlers>
                      <handler name="XMLFILE"/>
                  </handlers>
              </logger>

       

      I can see file my-xml.log is getting created in log directory, but I don't get any contents in it after excuting mylogger.debug(METHOD_NAME + "inside Document:\n");

       

      PS: I'm using log4j

       

      Is there anything obvious am I missing?

       

      Thank you,

      Prasad

        • 2. Re: AS7 Logging configuration
          jaikiran pai Master

          LogFactory is apache commons logging? Can you attach app reproducing this?

          • 3. Re: AS7 Logging configuration
            Prasad Deshpande Expert

            I can't reproduce this issue on it's own, but just noticed one thing, I had this jboss-log4j.xml from AS5 & that used to work. Any reference to migrate that part to AS7?

             

            if I remove log4j.jar from classpath, then it logs into the file, but I can't change my application at teh moment. Any ideas?

            • 4. Re: AS7 Logging configuration
              jaikiran pai Master

              Prasad Deshpande wrote:

               

              but just noticed one thing, I had this jboss-log4j.xml from AS5 & that used to work. Any reference to migrate that part to AS7?

               

               

              Did you miss posting the jboss-log4j.xml snippet that you might be talking about?

               

               

              Prasad Deshpande wrote:

               

               

              if I remove log4j.jar from classpath, then it logs into the file, but I can't change my application at teh moment. Any ideas?

              I'm not too sure what's going on. But maybe it's falling back on log4j and not finding the log4j.xml or log4j.properties in the classpath of the application and hence not logging anything.

              • 5. Re: AS7 Logging configuration
                Prasad Deshpande Expert

                Here is the log4j.xml that is used in AS5.1. I've just stripped of "jboss-" infront of the name. I tried to put his one in ear classpath/standalone/lib, doesn't help either way.

                 

                Category I'm talking here about is


                <logger name="webXMLDocument" additivity="false">


                <level value="DEBUG"/>


                <appender-ref ref="XMLFILE"/>

                </logger>

                 

                 

                Now, I know that there are 2 things here, one, Logging subsystem in standalone.xml & another is log4j.xml. Is there any way to just place this log4j.xml in application/jboss classpath & make it work?

                • 6. Re: AS7 Logging configuration
                  Prasad Deshpande Expert

                  At last I managed to reproduce problem that I was facing, just deploy this attached ear file & access following url. http://localhost:8080/startup/StartupServlet

                   

                  I've defined logging conf  in standalone.xml as follows:

                   

                          <periodic-rotating-file-handler name="XMLFILE" autoflush="true">
                              <level name="DEBUG"/>
                              <formatter>
                                  <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                              </formatter>
                              <file relative-to="jboss.server.log.dir" path="efp-xml.xml"/>
                              <suffix value=".yyyy-MM-dd"/>
                          </periodic-rotating-file-handler>

                   

                   

                          <logger category="webXMLDocument">
                              <level name="DEBUG"/>
                              <handlers>
                                  <handler name="XMLFILE"/>
                              </handlers>
                          </logger>

                   

                  defined logger category can not be used in application unless I put log4j.xml in the classpath of application.

                   

                  My question is How do I use logging configuration defined in standalone.xml without changing code (I don't want to put log4j.xml in application as I want to define loggers in standalone.xml)?

                  • 7. Re: AS7 Logging configuration
                    jaikiran pai Master

                    Prasad Deshpande wrote:

                     

                    defined logger category can not be used in application unless I put log4j.xml in the classpath of application.

                     

                    My question is How do I use logging configuration defined in standalone.xml without changing code (I don't want to put log4j.xml in application as I want to define loggers in standalone.xml)?

                    I don't think that's possible. Each logging implementation like log4j expects its own configuration file to be available for configuring logger. I don't think you can configure those categories in the jboss-logging.xml and let log4j pick those configurations from there. You'll need a log4j.xml or log4j.properties. However, I'm not logging expert so I might be wrong.

                    • 8. Re: AS7 Logging configuration
                      Oved Ourfali Newbie

                      I looked at this discussion, and some other discussions as well, in order to understand how I can make my configuration from EAP5 (jboss-log4j.xml file in the conf directory) in AS7.

                       

                      Is there any way to do that?

                      • 9. Re: AS7 Logging configuration
                        Prasad Deshpande Expert

                        The way I did was, convert jboss-log4j.xml to log4j.xml/log4j.properties (you may just rename it if the format is same) & then make your XML avaialbe to your application by putting it in your application classpath with log4j jars & application will pick up your defined loggers in log4j.xml.

                         

                        Please note, there is no connection between what you defined in standalone.xml & log4j.xml, so don't expect loggers to be available to application by defining in standalone.xml.

                        • 10. Re: AS7 Logging configuration
                          Oved Ourfali Newbie

                          So the format is different between the versions?

                          Just taking the same configuration (renaming it, of course) won't wotk?

                          • 11. Re: AS7 Logging configuration
                            Prasad Deshpande Expert

                            In most cases it should work simply by renaming & adding to application classpath. But worth cross checking..

                            • 12. Re: AS7 Logging configuration
                              Oved Ourfali Newbie

                              My application is deployed as an EAR.

                              I tried to put the log4j jar and the log4j.xml file in EAR/lib and it didn't work.

                               

                              I'll keep on trying, but if you have any ideas let me know.

                               

                              Thank you very much.

                              Oved

                              • 13. Re: AS7 Logging configuration
                                Prasad Deshpande Expert

                                the most obvious thing to miss is package log4j.xml in a JAR. Classloader won't pick log4j.jar on it's own... I think you can create a simple jar with log4j.xml at the root of it..