Morgan日志没有在keystone应用中工作

时间:2021-04-02 22:03:41

I am running a keystone.js express based app. I am trying to integrate Morgan logging but it is not working when any HTTP requests hit the site. I just see the normal output in my console. What could I possibly be doing wrong?

我正在运行一个梯形。基于js express的应用程序。我正在尝试集成Morgan logging,但是当任何HTTP请求到达站点时,它就不能工作了。我只是看到了控制台的正常输出。我可能做错了什么?

Here is my routes/index.js file

这是我的路线/索引。js文件

var keystone = require('keystone'),
    middleware = require('./middleware'),
    importRoutes = keystone.importer(__dirname);

var morgan = require('morgan');


// Common Middleware
keystone.pre('routes', middleware.initLocals);
keystone.pre('render', middleware.flashMessages);

// Import Route Controllers
var routes = {
    views: importRoutes('./views')
};

// Setup Route Bindings
exports = module.exports = function(app) {

    //Logging
    app.use(morgan('combined'));

    // Views
    app.get('/',middleware.ensureLatestBrowser, routes.views.index);
    app.get('/blog/:category?',middleware.ensureLatestBrowser, routes.views.blog);
    app.get('/blog/post/:post',middleware.ensureLatestBrowser, routes.views.post);
    app.all('/contact', middleware.ensureLatestBrowser,routes.views.contact);
    app.all('/software',middleware.ensureLatestBrowser, routes.views.software);


};

1 个解决方案

#1


3  

This is because Keystone already loads an instance of morgan (which loads before yours). The default format used by Keystone is :method :url :status :response-time ms.

这是因为Keystone已经加载了一个morgan实例(它在您的实例之前加载)。Keystone使用的默认格式是:方法:url:状态:响应时间ms。

Keystone allows you to customize the format by using the logger option.

Keystone允许您使用logger选项自定义格式。

keystone.init({
   ...
   'logger': 'combined'
   ...
});

The above example will set the output format for morgan to combined.

上面的示例将设置morgan的输出格式。


EDIT

The above is true as of Keystone 0.3.x, when Keystone migrated to Express 4.x and morgan as the Express logger. Pre-0.3.x versions of Keystone use Express 3.x with express.logger.

以上是Keystone 0.3的真实情况。当Keystone迁移到Express 4时。x和morgan作为快递员。pre - 0.3。x版本的Keystone使用Express 3。与express.logger x。

#1


3  

This is because Keystone already loads an instance of morgan (which loads before yours). The default format used by Keystone is :method :url :status :response-time ms.

这是因为Keystone已经加载了一个morgan实例(它在您的实例之前加载)。Keystone使用的默认格式是:方法:url:状态:响应时间ms。

Keystone allows you to customize the format by using the logger option.

Keystone允许您使用logger选项自定义格式。

keystone.init({
   ...
   'logger': 'combined'
   ...
});

The above example will set the output format for morgan to combined.

上面的示例将设置morgan的输出格式。


EDIT

The above is true as of Keystone 0.3.x, when Keystone migrated to Express 4.x and morgan as the Express logger. Pre-0.3.x versions of Keystone use Express 3.x with express.logger.

以上是Keystone 0.3的真实情况。当Keystone迁移到Express 4时。x和morgan作为快递员。pre - 0.3。x版本的Keystone使用Express 3。与express.logger x。