简体   繁体   English

除去node.js中的这些日志消息

[英]Get rid of these log messages in node.js

How could I suppress these log messages: 我如何抑制这些日志消息:

GET /stylesheets/style.css 500 451ms-1.08kb获取/scripts/script.js 200985ms-91b

Or atleast get them to not change my console's background and foreground colors. 或者至少让他们不要更改控制台的背景和前景色。

0) remove the logger middleware 0)删除记录器中间件

Comment out app.use(express.logger()) from your code...or make it conditional on your node environment settings so you get stuff in dev but not in production. 从您的代码中注释出app.use(express.logger()) …或使其取决于您的节点环境设置,这样您就可以在开发人员中获取东西,而不能在生产环境中获取东西。

1) Use a different logger 1)使用其他记录器

You can search around for this in npm and you'll find things like express-winston . 您可以在npm中搜索该内容,并且会找到express-winston之类的东西。

2) Write your own logger 2)编写自己的记录器

If what you need is simple, here's the example that's straight from the docs: 如果您需要的很简单,那么下面的示例直接来自于文档:

app.use(function(req, res, next){
  console.log('%s %s', req.method, req.url);
  next();
});

Remove express.logger 删除express.logger

app.set('view engine', 'jade')
app.configure(function() {
 // ̶a̶p̶p̶.̶u̶s̶e̶(̶e̶x̶p̶r̶e̶s̶s̶.̶l̶o̶g̶g̶e̶r̶(̶'̶d̶e̶v̶'̶)̶)̶;
    app.use(stylus.middleware({

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM