Sign In Register

How can we help you today?

Start a new topic
Answered

How can I log/print output in the test harness?

I am using the Test Harness for my cloud code scripts logic. 

I would like to see (without using the debugger), the output of various variables for easy reference.


How can I write/add to the output in the test harness?


For instance, I'd like to do something like...


console.log("The total count was : " + myCount);


But console.log is not recognised. Is there a way to do this?


Best Answer

Hi Andrew,


You can use scriptData to do this. In your script use Spark.setScriptData("result", value) to do it. Replace the values with whatever is relevant to you. You'll see the scriptData in the test harness inspectors response. 


Regards,

Liam


Hi Greg,


We have a way of logging debug messages that will be saved in the rumtime collection "log".


You can simply put:


Spark.getLog().debug(<Your Debug Message here>)


to capture whatever it is you want to debug. Then through the NoSQL Explorer, do a find on the log collection. Your most recent logs will appear at the bottom. If you'd like to make logs show up at the top, simply put {ts:-1} in the "Sort" box.



Hope this answers your question, let me know if you have any more issues.


-Pádraig

That works, but it's a slow workflow process, having to go in and out of the DB, query all, dig out what you want, then delete the log, each time you run. Would be much better if there were some convenient way to output to a window or something.

Andrew

 

Answer

Hi Andrew,


You can use scriptData to do this. In your script use Spark.setScriptData("result", value) to do it. Replace the values with whatever is relevant to you. You'll see the scriptData in the test harness inspectors response. 


Regards,

Liam

But what if I have more than one piece of data? It means I'd have to build up an array of result text... Which is possible, but it seems a little hacky ;)
Ideally there'd be something like:

TestHarness.log()

Of course I don't know what your system is architected like under the hood, so maybe that's just not possible without a massive rewrite... ?

Cheers,
Andrew

 

Hey Andrew,

You can use use Spark.setScriptData multiple times in a script so long as the value is different.
 
Sean

 

Login to post a comment