Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Log formatters shouldn't override referenced values #3853

Closed
youngguns-nl opened this issue Feb 21, 2013 · 3 comments
Closed

Log formatters shouldn't override referenced values #3853

youngguns-nl opened this issue Feb 21, 2013 · 3 comments
Milestone

Comments

@youngguns-nl
Copy link
Contributor

When you use multiple writers with different formatters, the formatter of the next writer gets the formatted event from the first writer (and so on). The reason this happens is, of course, references.

In my opinion the formatters shouldn't actually change the original values, but just return a formatted "local" version of the event. If you guys agree I can create a PR for this, but first want to discuss the possible solutions here. So any thoughts?

@youngguns-nl
Copy link
Contributor Author

After some more debugging, forget about the different writers and formatters, even with one writer and formatter things get messed up :-)

$logger = new Zend\Log\Logger();
Zend\Log\Logger::registerErrorHandler($logger);
$streamWriter = new Zend\Log\Writer\Stream('/tmp/test.log');
$streamWriter->setFormatter(new Zend\Log\Formatter\Simple());

$logger->addWriter($streamWriter);

$testArray = array(
    'foo' => 'testing',
    'bar' => array(
        'lorum' => array(
            'ipsum',
            'dolar sit',
        )
    )
);

var_dump(gettype($testArray)); //output: string 'array' (length=5)
trigger_error('foobar');
var_dump(gettype($testArray)); //output: string 'string' (length=6)

So somehow the test array is converted into an json encoded string.

@youngguns-nl youngguns-nl reopened this Feb 21, 2013
@marc-mabe
Copy link
Member

Interesting, your example results in an infinite loop using the current master branch

@gws
Copy link
Contributor

gws commented Jun 8, 2013

This looks related to #4503 as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants