4 Replies Latest reply on May 14, 2008 1:31 PM by genman

    Logging into separate Files

    groscurth

      Hi,

      i want to log the web applications into separate files. I found the documentation about how to do that in the jboss wiki and it works.

      <appender name="App1Log" class="org.apache.log4j.FileAppender">
       <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
       <param name="Append" value="false"/>
       <param name="File" value="${jboss.server.home.dir}/log/app1.log"/>
       <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
       </layout>
       <filter class="org.jboss.logging.filter.TCLFilter">
       <param name="AcceptOnMatch" value="true"/>
       <param name="DeployURL" value="app1.ear"/>
       </filter>
       </appender>
      
      ...
      
       <root>
       <appender-ref ref="CONSOLE"/>
       <appender-ref ref="FILE"/>
       <appender-ref ref="App1Log"/>
       </root>


      The problem is - it still logs on the console (server.log respectively).

      What do i have to do that it logs only in the given file (using categories is not possible, because several applications using shared libraries) ?

      And how do i set the log level in that system ?

      Thanks

        • 1. Re: Logging into separate Files
          peterj

          Are you trying to, for instance, log only your code to the new log file? If so, you need to also add something like this:

          <category name="my.package.name">
           <priority value="DEBUG"/>
           <appender-ref ref="App1Log" />
           </category>
          


          And remove the < appender-ref ref="App1Log" > from within < root >

          If you are attempting to prevent *any* logging to the console. remove the < appender-ref ref="CONSOLE" > line.


          • 2. Re: Logging into separate Files
            groscurth

            thanks for your answer peter.

            the problem is that different web applications deployed on the jboss share same classes/libraries.

            So if App1 and App2 both uses Library1, how to define in categorys that Library1 once has to log into App1Log file and another time in App2Log file.

            Therefore the category system does not work for me :(

            And actually I dont intend to remove ALL logs in the console - jboss system logs shall occur of course, but non of the web application logs....

            is this then possible at all?

            • 3. Re: Logging into separate Files
              peterj

              You are asking for log4j to somehow know when to log a message from a particular class to one log file in one circumstance and under another circumstance to log it to another log file. Sorry, but log4j just will not do that.

              • 4. Re: Logging into separate Files
                genman

                You can use a thread local, e.g. MDC and filter on that, assuming the library is going to be run from the same application's threads. Search for "MDC filter" in google.