1 Reply Latest reply on Jul 20, 2005 2:38 AM by Vishal Sharma

    log4j appends to console too

    Laszlo Graf Newbie

      Hi all

      To separate the log from my application I made the suggested modifications (http://wiki.jboss.org/wiki/Wiki.jsp?page=Logging). I created a new appender is

      -appender name="myapp" 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/myapp.log"/-
      -layout class="org.apache.log4j.PatternLayout"-
      -param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/-
      -filter class="org.jboss.logging.filter.TCLFilter"-
      -param name="AcceptOnMatch" value="true"/-
      -param name="DeployURL" value="exlybris.ear"/-

      the new category is

      -category name="gl.myapp"-
      -appender-ref ref="myapp"/-

      and the ref in root is

      -appender-ref ref="myapp"/-.

      My problem is that, the logged message appears on console once and in my log file twice. How can I configure log4j to log only in my log file, without console?

      Thank you.

        • 1. Re: log4j appends to console too
          Vishal Sharma Expert

          If i understood right,
          then take out the reference of yr appender from the root logger, as every logger inherits from root logger.

          Also it wll be good to set additivity flag to false.

          <category name="gl.myapp" additivity="false">

          Note on appender additivity - The output of a log statement of some logger L is forwarded to all the appenders in L and its ancestors. This is the meaning of the term appender additivity.
          However if and ancestor of Logger L, say, P has its additivity flag set to false then, L's output will be directed to all the appenders in L and its ancestors upto and including P. bit not the appenders in any of the the ancestors. of P.
          Loggers have their additivity set to true by default.