如何在postgres plv8程序中记录字符串?

时间:2022-09-15 19:52:05

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

我试图在plv8过程中使用plv8.elog()打印SQL查询。

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.

我不知道为什么,但我无法在控制台上看到任何输出。我搜索了可能的解决方案,并找到了一个有用的信息,plv8可以打印最大长度为512个字符的字符串。链接如下。

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

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

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

为了验证这一点,我试图用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?

这次我可以按预期看到日志输出。有人可以建议,我们如何记录超过512个字符的字符串?

1 个解决方案

#1


2  

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...

希望可以帮助......

#1


2  

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...

希望可以帮助......