How to log a string in a postgres plv8 procedure?

1.8k Views Asked by At

I am trying to print a sql query using plv8.elog() in a plv8 procedure.

plv8.elog(NOTICE, 'Notice:', str);

I don't know why but I am unable to see any output on the console. I searched for the possible solution and found a useful information that plv8 can print a string up to max length 512 characters. Link is given below.

http://code.google.com/p/plv8js/issues/detail?id=78

For verifying this I tried to print same string with str.slice

    plv8.elog(NOTICE, 'Notice:', str.slice(0,512));

This time I can see the log output as expected. Can someone please suggest, How can we log string having more than 512 characters?

1

There are 1 best solutions below

0
On

I use this function:

var logMaxL = 90;
function log () {//{{{
    var overflow = [];
    var args = Array.prototype.slice.call(arguments, 0).map(function(arg, i){
        if (arg instanceof Object) arg = JSON.stringify(arg);
        if (
            typeof arg == "string"
            && arg.length > logMaxL
        ) {
            overflow[i] = arg.substring(50);
            arg = arg.substring(0, 50);
        };
        return arg;
    });
    plv8.elog.apply(this, [NOTICE].concat(args));
    if (overflow.length) log.apply(this,overflow);
};//}}}

(Context: this Gist not yet updated. Sorry)

Hope could help...