Is there a console to debug server side scripts?

Hello,

I was just playing a round a little bit with the server side scripting capabilities of DSP.

Having done some frontend Javascript Development I’m relying on the browser console a lot of times in order to quickly debug/test my code (e.g. showing the result of modifications to an object etc.).

Since the JS interpretation and execution takes place on the server. I was wondering if there exists a way to patch eventual output of the V8 engine through to my browser console or if there is such a thing as a server-side console available.

Best regards, Matthias

1 Like

There’s a blog post that shows how to write to your DSP’s log file https://blog.dreamfactory.com/build-your-own-web-services-using-dreamfactory-custom-scripts

You can also have the script return data back to the client in JSON format.

result.debugInfo = “whatever”;
return result;

Or you can have the script throw an exception, which can pass data back to the client.

From the blog post…

Scripts can also write to the DSP’s log file which is useful for debugging. The PHP functions print, print_r, and var_dump are available to be called from the Javascript engine. By default the output of these will go to the log file in your DSP’s /log directory. On a Bitnami OS X installation that directory would be something like

/Applications/dreamfactory-1.7.8-0/apps/dreamfactory/htdocs/log

Adding the following line to the script would write to your log file. Please use logging sparingly as it does negatively affect script performance.

print(event.n1 + " + " + event.n2 + " = " + result);

The output would look like this.

[2014-09-03 16:37:53] app.INFO: Script User Script "add" output:
4 + 2 = 6
 [] []

Hello Ben,

thanks for that information. I haven’t seen that blog post.

Regards, Matthias

Hi Ben,

I might be asking a followup question on this very lately. Sorry for that.
Even though I use print statement, nothing is being displayed in the log. Is there any setting we should do?

Please suggest.

Thanks
Krishna

try var_dump, like this for example:

var result = platform.api.get("mongodb/_table/contact", params); var_dump("dumping result"); var_dump(result);

Hi Ben,

Thank you for the suggestion. I used var_dump as well. The log is not capturing any of these messages. I am always getting the message as follows in the log:

[2016-03-16 03:43:09] local.DEBUG: Resource event: srdb.table.FirstTable.post.postprocess
Even
adding var_dump(“Starting”) step in the post or pre process of processing event, none of these messages are being displayed.

Please suggest.I a trying to do this since for 1 week.

Best Regards
Krishna G

The following is working OK from PHP script code:
error_log( print_r( $var_to_dump, true ) );

You will need to have debug logging turned on in order for dumping from scripts to work.

https://wiki.dreamfactory.com/DreamFactory/Troubleshooting

1 Like