What is the best way to log messages from JavaScript code? Can we call message logging policy from JavaScript?

Not applicable
 
Solved Solved
1 4 5,210
1 ACCEPTED SOLUTION

adas
New Member

If you do console.log that should print to the system.log file. Alternately, you can prepare the logging payload in the JavaScript using a flow variable and then use that flow variable in a message logging policy following the JavaScript policy. You cannot call the msg logging policy from within the JavaScript policy.

You can also write your custom logger in the JavaScript policy, to do all this in the policy.

View solution in original post

4 REPLIES 4

adas
New Member

If you do console.log that should print to the system.log file. Alternately, you can prepare the logging payload in the JavaScript using a flow variable and then use that flow variable in a message logging policy following the JavaScript policy. You cannot call the msg logging policy from within the JavaScript policy.

You can also write your custom logger in the JavaScript policy, to do all this in the policy.

Hi @arghya das,

Is there a plan to introduce a JS log feature in future? I ask this because, most of the Edge proxies I have come across depend heavily on JS Callouts. It will be a very good idea to segregate all JS logs into one place.

Thanks,

Abhishek

@Abhishek Subramanya

I don't think there are any "near term" plans to support this and segregate JS logs into a single place. Like @Dino mentioned, there are ways to get this information and print it in the console (and view in trace). On the other hand for node.js proxies we do support "node.js logs" which can be seen in the management UI by clicking the "Node.js Logs" button on the proxy details page.

Keep in mind you can call print() from within a JS callout.

This shows up in the Trace window. Near the bottom you can find the "Output from all transactions" .

This does not segregate out[put from JS... from output from nodejs. But it is a nice way to view output at runtime.

1797-output-from-transactions.png