gpt4 book ai didi

AWS EC2 Node.js Application with Winston Logger Integration Resulting in 502 Error for Specific Route(带有Winston Logger集成的AWS EC2 Node.js应用程序导致特定路径出现502错误)

翻译 作者:bug小助手 更新时间:2023-10-26 22:45:44 30 4
gpt4 key购买 nike



I'm facing a perplexing issue with my Node.js application running on an AWS EC2 instance. After integrating the Winston logger into my application, I started encountering a 502 error, but only for a specific route. To narrow it down, I added a simple log statement (logger.info('Login request')) within that particular route.

我的Node.js应用程序在AWS EC2实例上运行,我面临着一个令人困惑的问题。在将Winston记录器集成到我的应用程序中后,我开始遇到502错误,但只针对特定的路线。为了缩小范围,我在该特定路由中添加了一个简单的日志语句(logger.info(‘Login Request’))。


Here's the strange part: The 502 error only occurs for this specific route, while the rest of the application works flawlessly. However, when I check the AWS logs, I can see that the log message ("Login request") is indeed present. Additionally, the same codebase, with the Winston logger integration, runs perfectly without any errors when deployed on Heroku with a test domain.

奇怪的是:502错误只出现在这条特定的路线上,而应用程序的其余部分则可以完美地工作。但是,当我查看AWS日志时,我可以看到日志消息(“登录请求”)确实存在。此外,相同的代码库,与Winston记录器集成,当部署在带有测试域的Heroku上时,运行良好,没有任何错误。


I'm baffled by this issue and would greatly appreciate any insights or suggestions on how to resolve it. It's essential for me to have logging properly functioning on AWS EC2, as it is in the Heroku environment.

我对这个问题感到困惑,如果有任何关于如何解决它的见解或建议,我将非常感激。像在Heroku环境中一样,在AWS EC2上正确运行日志记录对我来说是至关重要的。


Thank you in advance for your help!

提前感谢您的帮助!


Winston Code:

温斯顿代码:


const winston = require("winston");
const { combine, timestamp, errors, splat, json, colorize, simple } = winston.format
require('winston-daily-rotate-file');
const appRoot = require("app-root-path");

var transport = new winston.transports.DailyRotateFile({
filename: appRoot + '/logs/log-%DATE%.log',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
const logger = winston.createLogger({
level: "silly",
format: combine(
timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
errors({ stack: true }),
splat(),
json()
),
transports: [
transport
]
});

if (process.env.NODE_ENV == "development") {

logger.add(new winston.transports.Console({
format: combine(
colorize(),
simple()
)
}));
}

Router code:

路由器代码:


router.get('/patient/login',forwardAuthenticated, patientAuth.patientloginoptimized);

Request handler:

请求处理程序:


exports.patientloginoptimized = (req, res, next) => {
logger.info('Patient login request')
res.render('patientViews/patientFront/patient-login-optimized', {
title: "",
})
}

更多回答

Does the application have permission to appRoot + '/logs/log-%DATE%.log'1? Can you check with a Console transport alone and see if the issue persists?

应用程序是否具有appRoot+‘/Logs/log-%Date%.log’1的权限?您是否可以单独检查控制台传输器,并查看问题是否仍然存在?

Yes, it has, even though the log file is being created along with the text I logged into that specific route.

是的,它有,即使日志文件是随着我登录到该特定路由的文本一起创建的。

Share the code of your lambda. Probably nothing to do with your logger then

分享您的lambda的代码。可能跟你的记录器没什么关系

@RobinThomas Here's the router code: router.get('/patient/login',forwardAuthenticated, patientAuth.patientloginoptimized); and here's the handler: exports.patientloginoptimized = (req, res, next) => { logger.info('Patient login request') res.render('patientViews/patientFront/patient-login-optimized', { title: "", }) }

@RobinThomas这是路由器代码:router.get(‘/Patient/Login’,ForwardAuthenticated,patientAuth.patientloginOptimized);这是处理程序:exports.patientloginOptimized=(req,res,Next)=>{logger.info(‘患者登录请求’)res.render(‘patientViews/patientFront/patient-login-optimized’,{标题:“”,})

Please add it to the question.

请把它加到问题中。

优秀答案推荐
更多回答

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