Last active
October 6, 2016 13:18
-
-
Save bitifet/64fdefc8903b3323ffa8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Handy plv8 console object (debugging) | |
var console = (function(){ | |
var columns = 100; | |
function logString(level, str) { | |
var chunk = str.substring(0, columns); | |
var overflow = str.substring(columns); | |
plv8.elog(level, chunk); | |
if (overflow.length) logString(level, " | "+overflow); | |
}; | |
function log(level) { | |
var args = [].slice.call(arguments, 1) | |
return logString( | |
level | |
, "-> "+args.map(function(input){ | |
return typeof input == "object" ? JSON.stringify(input) : String(input); | |
}).join(" ") | |
); | |
}; | |
function logger(level){ | |
return function(){return log.apply(this, [level].concat([].slice.call(arguments)));}; | |
}; | |
// Valid levels: DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, LOG, INFO, NOTICE, WARNING, ERROR | |
return { | |
log: logger(NOTICE), | |
warning: logger(WARNING), | |
error: logger(ERROR), | |
}; | |
})(); | |
// Comment out below line to use it inside plv8_startup procedure making it available to | |
// all plv8 procedures having acces to its schema: | |
// this.console = console; | |
// For more details, see also: | |
// * http://pgxn.org/dist/plv8/doc/plv8.html#Start-up.procedure | |
// * https://gist.github.com/bitifet/bb02bb0aae4d7cab2c1d#file-perschema_plv8_init-js-sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment