[ 
https://issues.apache.org/jira/browse/LOG4PHP-177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13437379#comment-13437379
 ] 

Ivan Habunek commented on LOG4PHP-177:
--------------------------------------

Sagi, 

I agree that this behaviour is somewhat inconsistent. You cannot attach an 
appender to a logger multiple times through configuration (although you can 
programatically).

In this case, the appender is attached to MyClass logger and the root logger 
(only once per logger). When root logger logs a message, it also forwards it to 
any parent loggers (which in this case is the root logger) because of the 
additivity rules. There is no check to see if the parent logger's appenders are 
also attached to MyClass logger. That's why the message gets logged twice by 
the same appender.

While I'm not sure that this behaviour is 100% desirable, I don't see that it 
causes a problem which cannot fixed by a simple change in configuration, as you 
demonstrated. Therefore, I'm not inclined to start complicating the code to fix 
this.

Perhaps this issue can best be solved by documenting the behaviour in question.
                
> logger writes every message twice
> ---------------------------------
>
>                 Key: LOG4PHP-177
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-177
>             Project: Log4php
>          Issue Type: Bug
>          Components: Code
>    Affects Versions: 2.2.1
>         Environment: windows 7, php 5.3 (bundled with xampp)
>            Reporter: Sagi Mann
>            Priority: Minor
>
> The following code and configuration logs everything twice, but is not 
> expected to. This was attempted with both LoggerAppenderConsole and 
> LoggerAppenderFile, maybe reproducible with other appenders as well. If I 
> remove the <appender_ref> tag from the <logger name="MyClass"> element below, 
> the issue no longer occurs, but AFAIU, this kind of workaround should not be 
> required.
> log4php.xml:
> <configuration xmlns="http://logging.apache.org/log4php/";>
>     <appender name="myAppender" class="LoggerAppenderConsole">
>     </appender>
>     <root>
>         <level value="WARN" />
>         <appender_ref ref="myAppender" />
>     </root>
>     <logger name="MyClass">
>         <level value="WARN" />
>         <appender_ref ref="myAppender" />
>     </logger>
> </configuration>
> index.php:
> Logger::configure('log4php.xml');
> class MyClass {
>       protected $logger = null;
>       public function __construct() { $this->logger = 
> Logger::getLogger(get_class($this)); }
>       public function f() { $this->logger->warn("f"); }
> }
> $cls = new MyClass();
> $cls->f();
> output:
> WARN - f
> WARN - f

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to