We are using zend framework 2 for a new application, i would like to have the same logging system of Rails or similar, i would like have a log for each request, is possible to do this in Zend?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
It depends what you want to log. If it is just an access log, you should try to use the webserver's log. The logs from Apache/nginx/IIS etc perform better than you will achieve in your ZF2 app.
If you need to log inside the ZF2 application, you have two choices. First option is at
bootstrap
. It's one of the earliest options you can use, so probably therefore the best. However, you can also look atroute
ordispatch
. Those two events are called during the "run" phase of the application. With these events, you have for example a route match available and therefore you know (or not) if your request did match any controller (or in case you don't have the match, it's a 404).Some examples. Let's assume you have a logger configured in the
ServiceManager
under thelogger
key. Then to log atbootstrap
:Or for example if you wait for
route
, you attach a listener for theroute
event:Sounds like you could attach a listener to the
dispatch
event onZend\Mvc\Application
.For reference, Rob Allen has created a handy list of ZF2 events.