5 Replies Latest reply on Jul 8, 2009 8:18 AM by brettcave

    log4j config file behaviour

    brettcave

      In jboss-log4j.conf, how does defining categories affect which appenders are used. E.g. If I have something like:

      <category name="com.mycompany.package1">
       <priority value="ERROR" />
       <appender-ref ref="CONSOLE" />
      </category>
      
      <category name="com.mycompany.package2">
       <priority value="ERROR" />
      </category>
      
      <root>
       <priority value="INFO" />
       <appender-ref ref="SMTP" />
       <appender-ref ref="CONSOLE" />
       <appender-ref ref="FILE" />
      </root>
      



      Will com.mycompany.package1 only log ERROR to console?
      Will com.mycompany.package2 log ERROR to all appenders in the root?


        • 1. Re: log4j config file behaviour
          peterj

          Setting a priority for a category limits which log messages are forwarded to the appenders. Thus, for both com.mycompany.package1 and com.mycompany.package2 only ERROR messages get logged.

          The root definition identifies the appenders to use for all log messages, thus all messages are sent to SMTP, CONSOLE and FILE. In addition, log messages for com.mycompany.package1 are sent a second time to CONSOLE - the messages were sent the first time to CONSOLE because all categories inherit from root. This point confused me the first time I ran into it also.

          • 2. Re: log4j config file behaviour
            brettcave

            ah, ok makes sense.

            There isnt a way to override appenders on a per-category basis then? Ideally, I want to log ERROR to SMTP, CONSOLE and FILE for everything except for 1 or 2 categories, which I only want logged to CONSOLE / FILE - would have to have a more verbose config to achieve this then?

            • 3. Re: log4j config file behaviour
              jaikiran

               

              "brettcave" wrote:


              Ideally, I want to log ERROR to SMTP, CONSOLE and FILE for everything except for 1 or 2 categories, which I only want logged to CONSOLE / FILE


              The "additivity" flag on a category will help in achieving this. Ex:

              <category name="com.mycompany.package1" additivity="false">
               <priority value="ERROR" />
               <appender-ref ref="CONSOLE" />
              </category>
              
              <category name="com.mycompany.package2">
               <priority value="ERROR" />
              </category>
              
              <root>
               <priority value="INFO" />
               <appender-ref ref="SMTP" />
               <appender-ref ref="CONSOLE" />
               <appender-ref ref="FILE" />
              </root>
              


              Here com.mycompany.package1 will log only to the CONSOLE because the additivity flag is set to false. That flag can be used to specify that the log messages of a particular category are not to be propagated to the parent categories (the root in this case).


              • 4. Re: log4j config file behaviour
                brettcave

                instant reply seems broken :( or theres something funky in my cache.

                • 5. Re: log4j config file behaviour
                  brettcave

                  thanks jaikiran