我有一个启用了Winston日志记录的项目,该项目使用HAPI。我有以下代码:
logger.js
---------
var winston = require('winston');
winston.emitErrs = true;
var logger = new winston.Logger({
transports: [
new winston.transports.Console({
level: 'debug',
json: false,
colorize: true
})
],
exitOnError: false
});
module.exports = logger;
module.exports.stream = {
write: function(message, encoding){
logger.info(message);
}
};
server.js
---------
var Hapi = require('hapi');
var logger = require('./conf/logger.js');
var server = new Hapi.Server({
});
server.connection({
port: 3000
});
server.register([require('./modules/healthcheck.js'), require('vision')], (err) => {
if (err) {
console.error('Failed to load a plugin:', err);
}
});
server.start(function () {
logger.info('Server started at ' + server.info.uri);
});
healthcheck.js
--------------
var logger = require('./conf/logger.js');
var healthchkPlugin = {
register: function (server, options, next) {
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
logger.info("health check api invoked");
reply("gateway up and running");
}
});
next();
}
}
healthchkPlugin.register.attributes = {
name: 'healthchkPlugin',
version: '0.0.1'
};
module.exports = healthchkPlugin;
当我运行server.js并使用GET请求点击结束点时,控制台显示以下内容:
info:服务器位于http://<>:3000
但我希望它能显示GET处理程序中指定的info语句。我在这里做错了什么?