关于 debug包使用的问题!!!!
新手,debug包不会用!!!
在windows下,试一下官方示例:
var debug = require('debug')('http')
, http = require('http')
, name = 'My App';
// fake app
debug('booting %s', name);
http.createServer(function(req, res){
debug(req.method + req.url);
res.end('hello\n');
}).listen(3000, function(){
debug('listening');
});
设置了 debug=*,-not_this
输出的内容:
2015年3月30日 08:33:12 GMT https booting My App
2015年3月30日 08:33:12 GMT https listening
2015年3月30日 08:33:51 GMT https GET/favicon.ico
请问, 1)这个和普通的console.log()有什么区别? 2)require(‘debug’)(‘http’)中的 (‘http’)有什么作用??
7 回复
- console.log 必须 设置条件或者注释才能 显示或不显示,很麻烦,deubg设置DEBUG环境变量即可
- DEBUG环境变量决定输出哪块的信息: export DEBUG=‘http’ (linux 命令), 即输出 ‘http’ 的 信息
简单地说: 可以让你 从 手动 console.log 解脱出来(如果你不想看到console.log还要注释一下),自由决定查看 某个部分的debug信息 (设置DEBUG变量即可)
刚刚才用了debug,回复下