On Wed, 2017-02-22 at 06:51 -0900, Dan Morphis wrote:
> Is there any way to log values inside the script? I tried
> console.log, and let logger = require('./logger'); to no avail.
Virtual parameter and provision scripts are sandbox and don't have
access to any Node.js functions. I plan to expose a log function for
use from scripts, but for now see the patch for a quick and dirty hack.
--
Zaid Abdulla <[email protected]>
diff --git a/lib/sandbox.js b/lib/sandbox.js
index 317f9cb..98c5872 100644
--- a/lib/sandbox.js
+++ b/lib/sandbox.js
@@ -220,6 +220,10 @@ Object.defineProperty(sandbox.context, 'clear', {value: clear});
Object.defineProperty(sandbox.context, 'commit', {value: commit});
Object.defineProperty(sandbox.context, 'ext', {value: ext});
+Object.defineProperty(sandbox.context, 'debug', {value: function debug(msg) {
+ console.log(require('util').inspect(msg, {depth: 20, colors: true}));
+}});
+
// Monkey-patch Math.random() to make it deterministic
sandbox.context.random = random;
vm.runInContext("Math.random = random;", sandbox.context);
_______________________________________________
Users mailing list
[email protected]
http://lists.genieacs.com/mailman/listinfo/users