Could a hook be introduced on a function like services_method_call to allow the implementation of logging on each services method call. At the moment there is very little way of telling whether a services was called or not and if so with what data.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 635960.patch | 1.55 KB | gdd |
| #3 | 642584.patch | 21.46 KB | gdd |
Comments
Comment #1
gddI think this is a good idea. I was looking around the code and I think it makes sense to have three hooks
hook_services_log_call() - When the service is called, with all parameters
hook_services_log_call_results() - When the call has completed, with all parameters plus results
hook_services_log_error() - For anything that passes through services_error()
How does this sound?
Comment #2
skyredwangThis is a great idea. I am wondering if we could make the hook name a little bit more generic?
Or create an additional one called hook_services_api(); I want to use this hook_services_api() to call Google Analytics Server side script. see issue #635576: Google Analytics for Mobile service
Comment #3
gddHere's a rough first attempt patch at this. I actually am doing a lot of Services at work right now so I have some need for this too.
Comment #4
gddArgh wrong patch sorry
Comment #5
skyredwangsimple tested! hook_services_method_call, hook_services_error and hook_services_method_call_results work fine.
Comment #6
gddThis has been committed. Thanks!
Comment #8
natmchugh commentedAwesome work just found this again thanks a lot.
Comment #9
nd987 commentedDid this or similar ever make it into the D7 version? Trying to setup detailed logging but can't figure out the hook to use.
Comment #10
kylebrowning commentedYeah, look at
drupal_alter('services_request_preprocess', $controller, $args);
drupal_alter('services_request_postprocess', $controller, $args, $result);
and make sure you understand how the drupal_alter works
http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/7
Comment #11
nd987 commentedThat almost gets me there, however for failed requests, those hooks aren't triggered. For example, if my request is 404, the request is interrupted somewhere in the services_resource chain (maybe the access callback?), and neither my preprocess or postprocess hooks are triggered. I need to be able to log everything, including failed requests.
Also, there doesn't seem to be a way to get the response status code out of those hooks. The $results var only has the array/object to be encoded, no information about the status.
Comment #12
nd987 commentedAfter looking at the source code of the D7 version, I see that the services_request_preprocess alter function is called on line 152 in services.runtime.inc, which is after several error handlers which can stop execution.
What would be the harm in moving that up to line 98 or so, to be the first thing? Seems like you'd want it to alter before any logic started happening anyway.