gpt4 book ai didi

node.js - 在没有自动日志的情况下运行 node.js

转载 作者:IT老高 更新时间:2023-10-28 23:26:12 25 4
gpt4 key购买 nike

我想在回答请求时运行我的 node.js 应用程序,而不使用它在终端中打印的自动日志(例如 127.0.0.1 - - [Wed, 20 Jun 2012 09:55:49 GMT] "GET/url HTTP/1.1"200 1559 "http://localhost:3020/url"...)。此外,如果可能,我希望 console.log() 中的日志仍然可见。

有人知道怎么做吗?我在 Node 上运行 express.js。

谢谢

最佳答案

就像布兰登所说,我认为您正在使用 logger middleware在您的代码中的某处。您应该禁用该部分,尤其是在 production mode 中。 .使用这样的东西:

app.configure(function(){
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(app.router);
});

app.configure('development', function(){
app.use(express.static(__dirname + '/public'));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
var oneYear = 31557600000;
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.errorHandler());
});

关于node.js - 在没有自动日志的情况下运行 node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11118116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com