Matrix Version: 5.5.2.2
Is there a way for me to write to log manager with SSJS?
Example;
Problem occurs -> Throw exception -> Catch & Handle Exception -> Write to log manager
Matrix Version: 5.5.2.2
Is there a way for me to write to log manager with SSJS?
Example;
Problem occurs -> Throw exception -> Catch & Handle Exception -> Write to log manager
No.
The V8 and Spidermonkey code paths are slightly different, but I can’t see anything that would let you do that. There’s nothing passed into the JS context, and there’s no way to emit errors that get logged without stopping the SSJS from being replaced by the output.
Any JS errors that are thrown by the SSJS process are automatically logged to the log manager (should be at least). They should appear under the Error log like this:
So just to confirm, Squiz Matrix will log all thrown exceptions, even ones that are caught and dealt with gracefully? Or I will need to cause quite a catastrophic uncaught-exception situation for it to log?
Sorry, not those ones. But if you are catching them, you could thrown them all into a global array var and then have a function that runs at the end of all your script inside a script tag that uses log="log_prefix"
attribute?
https://matrix.squiz.net/manuals/concepts/chapters/server-side-javascript#attributes
Yeah that’s not ideal as the ‘print()’ function within that context also outputs to the frontend for users so unless I do both that and force which seems super unmaintainable behaviour so I’ve just decided against it and shifted the code to a Lumen API.
Thanks for the information though.
True, you could maybe print it inside a tag so that it doesn’t show up on the frontend. It’d be a good feature to add though to support better debugging of SSJS code, so I’ll add it as user feedback for us to consider.