1

I am learning ZF2 and trying to set up a restful web services architecture using ZF2. I am having a problem creating log file.

Here's my module configuration:

'service_manager' => array(
    'factories' => array(
        'loggingService' => function(\Zend\ServiceManager\ServiceManager $serviceManager) {
            $logger = new \Zend\Log\Logger();
            $writer = new \Zend\Log\Writer\Stream('/home/mani/logs/forum.log');
            $logger->addWriter($writer);
            return $logger;
        }
    )
)

Here I created a logger as a service and trying to inject logginService using constructor in controllers.

public function createService(ServiceLocatorInterface $serviceLocator) {

    $coreServiceLocator = $serviceLocator->getServiceLocator();
    $loggingService = $coreServiceLocator->get('loggingService');

    return new QuestionController($loggingService);
}

I think it will work, but ZF2 cannot create a log file showing me this message:

fopen(/home/mani/logs/forum.log): failed to open stream: No such file or directory

So my confusion is can ZF2 create log file or do we have to create it manually?

Nick Bondarenko
  • 6,211
  • 4
  • 35
  • 56
Mani Rai
  • 665
  • 2
  • 9
  • 22
  • 1
    Is your /home/mani/logs/ directory exists and writable by the http user? – edigu Dec 12 '15 at 12:12
  • Yes I tried with creating directory too and I can't understand what http user mean. I am developing application in my local pc using mani account and I was supposed to have permission to create any directory or file under /home/mani. – Mani Rai Dec 13 '15 at 12:43

2 Answers2

0

In my opinion you have a problem of permission, try to change the path with /tmp/app.log for example.

Thanks

GianArb
  • 1,604
  • 1
  • 14
  • 17
  • I don't have permission problem because I running everything (apache, ide, mysql) using mani account and trying to create log file under /home/mani directory. I would have got permission denied message, if it would have been permission problem. I also tried /tmp/app.log but same error message was produced. Thanks for your support. – Mani Rai Dec 13 '15 at 12:50
  • Hello, did you try into the /tmp? Thanks! – GianArb Dec 13 '15 at 19:48
  • Yes I did. I think if it would be the problem, I would have got message regarding permission. Thanks – Mani Rai Dec 14 '15 at 14:17
0

Please check whether /home/mani/logs exists, because in other case it would not be created and the same error will be thrown. Also give 777 to the dorectory.

Gennadiy Litvinyuk
  • 1,536
  • 12
  • 21