Reputation: 4392
I try to create log file with Zend Framework 2. I found the solution by using Zend\Log\Logger and Zend\Log\Writer\Stream. In fact, it works fine. But the problem is that I need to use that code in every action method and in every controller class.
Does anybody know how to create log file for the whole website WITHOUT writing the same code in every action method and in every controller class? Thank you for your answer!
Upvotes: 0
Views: 247
Reputation: 16455
You would use the EventManager
for this kind of feature. Anytime there's an error you'd trigger a specific Error-Event which you define. Then you have your LogingModule
which would hook in to each and every Event you want to Log.
You'd have to pass the Exception/ErrorMessage into the Event of course.
TL/DR the EventManager is what you should be looking for.
Upvotes: 2