logging-log4php-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Hammers (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LOG4PHP-84) undefined method getLoggerRepository() in LoggerLoggingEvent
Date Sun, 13 Sep 2009 21:46:57 GMT

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

Christian Hammers commented on LOG4PHP-84:
------------------------------------------

Here's a possible fix. At least it works for me. Below is a example that works with this patch
(the above example is totally buggy, it just happened to trigger the bug).

bye,

-christian-

Index: src/main/php/LoggerLoggingEvent.php
===================================================================
--- src/main/php/LoggerLoggingEvent.php (Revision 814339)
+++ src/main/php/LoggerLoggingEvent.php (Arbeitskopie)
@@ -260,13 +261,9 @@
                        if(is_string($this->message)) {
                                        $this->renderedMessage = $this->message;
                        } else {
-                               if($this->logger !== null) {
-                                       $repository = $this->logger->getLoggerRepository();
-                               } else {
-                                       $repository = Logger::getLoggerRepository();
-                               }
-                               if(method_exists($repository, 'getRendererMap')) {
-                                       $rendererMap = $repository->getRendererMap();
+                       $hierarchy = Logger::getHierarchy();
+                               if(method_exists($hierarchy, 'getRendererMap')) {
+                                       $rendererMap = $hierarchy->getRendererMap();
                                        $this->renderedMessage= $rendererMap->findAndRender($this->message);
                                } else {
                                        $this->renderedMessage = (string)$this->message;


require_once dirname(__FILE__).'/../../main/php/Logger.php';
Logger::configure(dirname(__FILE__).'/../resources/renderer_map.properties');

class Person {
    public $firstName = 'John';
    public $lastName = 'Doe';
}

class PersonRenderer implements LoggerRendererObject {
    public function render($o) {
        return $o->lastName.', '.$o->firstName;
    }
}

$person = new Person();

$logger = Logger::getRootLogger();
$logger->debug("Now comes the current MyClass object:");
$logger->debug($person);


$ cat src/examples/resources/renderer_map.properties
log4php.renderer.Person = PersonRenderer
log4php.appender.default = LoggerAppenderEcho
log4php.appender.default.layout = LoggerLayoutSimple
log4php.rootLogger = DEBUG, default


> undefined method getLoggerRepository() in LoggerLoggingEvent
> ------------------------------------------------------------
>
>                 Key: LOG4PHP-84
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-84
>             Project: Log4php
>          Issue Type: Bug
>          Components: Code
>            Reporter: Christian Hammers
>
> Hi
> LoggerRepositories were recently removed, or? One occurence in LoggerLoggingEvent is
still left.
> Fatal error: Call to undefined method LoggerRoot::getLoggerRepository() in /srv/home/james/workspace/log4php/src/main/php/LoggerLoggingEvent.php
on line 266
> Call Stack:
>     0.0007     123248   1. {main}() /srv/home/james/workspace/log4php/src/examples/php/renderer_default.php:0
>     0.0217    1035952   2. Logger->debug() /srv/home/james/workspace/log4php/src/examples/php/renderer_default.php:38
>     0.0217    1036280   3. Logger->logLevel() /srv/home/james/workspace/log4php/src/main/php/Logger.php:215
>     0.0217    1036664   4. Logger->forcedLog() /srv/home/james/workspace/log4php/src/main/php/Logger.php:330
>     0.0218    1039616   5. Logger->callAppenders() /srv/home/james/workspace/log4php/src/main/php/Logger.php:272
>     0.0218    1040432   6. LoggerAppender->doAppend() /srv/home/james/workspace/log4php/src/main/php/Logger.php:409
>     0.0218    1040688   7. LoggerAppenderEcho->append() /srv/home/james/workspace/log4php/src/main/php/LoggerAppender.php:134
>     0.0218    1040816   8. LoggerLayoutSimple->format() /srv/home/james/workspace/log4php/src/main/php/appenders/LoggerAppenderEcho.php:77
>     0.0219    1041136   9. LoggerLoggingEvent->getRenderedMessage() /srv/home/james/workspace/log4php/src/main/php/layouts/LoggerLayoutSimple.php:57
> Reproducable with:
> log4php.renderer.MyClass = MyClassRenderer
> log4php.appender.default = LoggerAppenderEcho
> log4php.appender.default.layout = LoggerLayoutSimple
> log4php.rootLogger = DEBUG, default
> and:
> require_once dirname(__FILE__).'/../../main/php/Logger.php';
> Logger::configure(dirname(__FILE__).'/../resources/renderer_default.properties');
> class Person {
>     public $firstName = 'John';
>     public $lastName = 'Doe';
> }
> class MyClassRenderer implements LoggerRendererObject {
>     public function render($o) {
>         return $o->lastName.', '.$o->firstName;
>     }
> }
> $person = new Person();
> $logger = Logger::getRootLogger();
> $logger->debug("Now comes the current person object:");
> $logger->debug($person);

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message