Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 调整Sock.js的记录器详细级别,如在Socket.io中_Javascript_Node.js_Logging_Sockjs - Fatal编程技术网

Javascript 调整Sock.js的记录器详细级别,如在Socket.io中

Javascript 调整Sock.js的记录器详细级别,如在Socket.io中,javascript,node.js,logging,sockjs,Javascript,Node.js,Logging,Sockjs,在Socket.IO中,我可以通过编辑日志级别选项来调整记录器的“详细程度”: The amount of detail that the server should output to the logger. 0 - error 1 - warn 2 - info 3 - debug 现在我正在使用Sock.js。我的日志文件由以下消息填充: POST /733/o1q4zdmo/xhr_send?t=1380900035633 5ms 204 POST /733/o1q4zdmo/xhr_

在Socket.IO中,我可以通过编辑
日志级别
选项来调整记录器的“详细程度”:

The amount of detail that the server should output to the logger.
0 - error
1 - warn
2 - info
3 - debug
现在我正在使用Sock.js。我的日志文件由以下消息填充:

POST /733/o1q4zdmo/xhr_send?t=1380900035633 5ms 204
POST /733/o1q4zdmo/xhr_send?t=1380900036926 6ms 204
POST /733/o1q4zdmo/xhr_send?t=1380900041212 4ms 204
POST /733/o1q4zdmo/xhr_send?t=1380900045510 1ms 204 

我想过滤它们。如何在Sock.js中执行此操作?唯一的解决方案是重写日志函数?(使用
log
设置),然后使用
开关
过滤具有严重性的消息?

我通过自定义日志功能解决了此问题:

// return a function that ouputs log messages from socks.js, filtered on
//  verbosity level. With a value of 0 it prints only errors, 1 info messages 
//  too, and to print everything, including debug messages, use a value of 2.

function make_socks_log(verbosity) {
    return function(severity, message) {
         /* Severity could be the following values:
          *  - `debug` (miscellaneous logs), 
          *  - `info` (requests logs), 
          *  - `error` (serious errors, consider filing an issue).
          */
          switch(severity) {
              case 'debug':
                if(verbosity >= 2) {
                    console.log(message);
                }
                break;
              case 'info':
                if(verbosity >= 1) {
                    console.log(message);
                }
                break;
              case 'error':
                console.log(message);
                break;
          }
    }
}
创建socks.js服务器时:

socksjs_server = sockjs.createServer({
    log: make_socks_log(0) // only error messages will be logged
});