cancel
Showing results for 
Search instead for 
Did you mean: 

How to print from XSJS to Console

Former Member
0 Kudos

Hello Experts,

I have some code in XSJS to populate/Update my Hana DB based on some conditions. I am looking for a mechanism where I can print few comments to console or to some log file.

I know i can use console.log(); for normal javascript on web browser but it does not work on XSJS. Some other implementation of Server Side JS like node.js gives echo command. Is there something similar for XSJS ?

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You should use the trace API : $.trace

JSDoc: Namespace: trace

Former Member
0 Kudos

Thanks for this information. I tried a very simple xsjs to test this but its not working for me. Could you please tell me what am I doing wrong here ?

my test.xsjs

function testTrace () {

     $.trace.info('My name is Raghuveer');

}

testTrace();

my .xsaccess file

{

    "anonymous_connection": "<package name>::incognito",

    "authentication" : null,

    "cors" : [{ "enabled":true }],

    "cache_control" : "must-revalidate",

    "exposed": true

}

Then I hit the URL in a web browser to execute this xsjs.

I looked at the server trace logs by going to location: <servername>:<port>/sap/hana/xs/ide/trace/ and then clicked on both the trc logs corresponding to my server name and tried searching for 'Raghuveer' as a keyword but no result was returned.

Then I went to <servername>:<port>/sap/hana/xs/security/ to verify my permissions. I am attaching the screenshot of all the permission i have for this user. I have the debugger role assigned also but still i dont see the trace to print anything in the log.

Could you please suggest what am I missing ?

Thanks in advance.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Here is from the SAP HANA Developers Guide (Section 8.8 Server-Side JavaScript Tracing):

The SAP HANA XS server-side JavaScript API provides tracing functions that enable your application to write predefined messages in the form of application-specific trace output in the xsengine trace files (xsengine*.trc) according to the trace level you specify, for example, “info”(information) or “error”.

If you use the server-side JavaScript API to enable your application to write trace output, you can choose from the

following trace levels:

● debug

● info

● warning

● fatal

For example, to enable debug-level tracing for your JavaScript application:

$.trace.debug("request path: " + $.request.path);

Note

You can view the xsengine*.trace files in the Diagnosis Files tab page in the Administration perspective of the SAP HANA studio.

It sounds as though the WebIDE with its greatly reduced number of trace files might not show you these. Have you tried using the HANA Studio as described in the online help?

Former Member
0 Kudos

Thanks for the pointer. I followed the  "8.8.1 Tracing Server-Side JavaScript Applications" from developer's guide.

Answers (0)