You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-dev@logging.apache.org by "Sven Rautenberg (JIRA)" <ji...@apache.org> on 2012/06/23 10:46:42 UTC

[jira] [Commented] (LOG4PHP-177) logger writes every message twice

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

Sven Rautenberg commented on LOG4PHP-177:
-----------------------------------------

Sagi Mann: What are you trying to achieve? You describe what you do in very good detail, but the goal of your doing remains unclear. As you say yourself, this might be related to the log4php documentation being unclear, or related to a bug in the code, but from current knowledge, this cannot be decided.

If all you want to do is log all messages above and including warn level to the console once, no matter what logger was used, then only use one appender attached to the root logger.

Attaching more than one appender to a logger means that you want to log to different targets (e.g. syslog AND mail).
Attaching an appender explicitly to a logger different from the root logger means that certain sources of log messages should ALSO be logged somewhere else (e.g. root logs to syslog, and database log messages ADDITIONALLY are sent by mail). Deactivating the additivity of a logger means that the messages affected are sent to this loggers appender ONLY.

Do you think this issue can be closed?
                
> 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