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.

CommentFileSizeAuthor
#4 635960.patch1.55 KBgdd
#3 642584.patch21.46 KBgdd

Comments

gdd’s picture

I 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?

skyredwang’s picture

Title: Logging hook » Logging hook and one more generic hook

This 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

gdd’s picture

Status: Active » Needs review
StatusFileSize
new21.46 KB

Here'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.

gdd’s picture

StatusFileSize
new1.55 KB

Argh wrong patch sorry

skyredwang’s picture

Status: Needs review » Reviewed & tested by the community

simple tested! hook_services_method_call, hook_services_error and hook_services_method_call_results work fine.

gdd’s picture

Status: Reviewed & tested by the community » Fixed

This has been committed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

natmchugh’s picture

Awesome work just found this again thanks a lot.

nd987’s picture

Did this or similar ever make it into the D7 version? Trying to setup detailed logging but can't figure out the hook to use.

kylebrowning’s picture

Yeah, 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

nd987’s picture

That 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.

nd987’s picture

After 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.