zendframework / zend-log

Log component from Zend Framework
BSD 3-Clause "New" or "Revised" License
62 stars 51 forks source link

Issues with consecutive log calls #29

Closed jonathangreco closed 8 years ago

jonathangreco commented 8 years ago

Hi,

I tried to implements in my architecture a service wich log some things.

I have a factory wich give in a dependancy my Logger (with the PSR3 adapter) This part works.

class LoggerFactory implements FactoryInterface
{
    /**
     * @param  ServiceLocatorInterface $serviceLocator
     * @return Application\Service\Logger
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /**
         * @var Logger
         */
        $logger = new Logger;

        /**
         * @var PsrLoggerAdapter
         */
        $psrLogger = new PsrLoggerAdapter($logger);

        return new MyLogger($psrLogger);
    }
}

So in a controller for testing purposes, I tried to do some consecutive logs :

public function testAction() {
        $this->logger->log(\Psr\Log\LogLevel::EMERGENCY, 'urgent fix me !',
            array("source" => get_class() . ':' . __LINE__, "variables" => array($tata, $xd)));

        $this->logger->log(\Psr\Log\LogLevel::INFO, 'a screen alert');

        $this->logger->log(\Psr\Log\LogLevel::NOTICE, 'Contact an admin : {email}',
            array('email' => "toto@sample.com"));
}

My problem is, the second log is Inserted twice, one by itself, and the second time, when Notice's log comes out. Because my service has a single instance of the logger and INFO & NOTICE are registered in the same file.

I tried then to shutdown those writers after I insert the log, no luck!

When I reopen the same file https://github.com/zendframework/zend-log/blob/master/src/Writer/Stream.php#L82 this line stored for me the old resource wich not exist anymore due to the shutdown call.

The error I got is :

fwrite(): 751 is not a valid stream resource

And a screen of my var dump in the stream.php's file log

You can see in the last line that $this->stream has 751 in place of 753.

Thanks in advance for you advice / help.

Ocramius commented 8 years ago

Is this issue supposed to be closed? Was it resolved?

jonathangreco commented 8 years ago

Hi Ocramius.

I solved this by configuring writers into the constructor which I didn't do . This problem was an architecture issue from my project.

For me this issue deserves to be closed and forgotten ^^'

I don't know how zend-log was supposed to work, so I've posted an issue without asking myself if I've implemented it the right way. I thought that a writer could be removed easily which is not the case.

Ocramius commented 8 years ago

@jonathangreco alright!

For me this issue deserves to be closed and forgotten ^^'

That's actually why I asked. While it may have been a mistake on your end, this issue may still help others.