我在快递中制作了一条路线,下面的代码片段是:
在 app.js 中,我添加了:
var generateOrders = require('./routes/generateOrders');
app.use('/generate-orders', generateOrders);
在 generateOrders.js :
var express = require('express');
var router = express.Router();
var generateOrdersServices = require('../services/generateOrders')
router.get('/get-orders', function (req, res) {
generateOrdersServices.getOrders(function (errGenerateOrders, responseGenerateOrders) {
if(errGenerateOrders){
console.log(errGenerateOrders);
res.render(errGenerateOrders);
return;
}
else{
console.log(responseGenerateOrders);
res.render(responseGenerateOrders);
return;
}
})
})
现在,当我点击http://localhost:4000/generate-orders/get-orders时,它永远不会停止。 我的代码生成了一个日志文件,我在其中添加了所有输入,当我点击这条路线时,它不断地一次又一次地将输出添加到日志文件中。在终端中,所有内容都会一次又一次地继续打印。
下面是我用来为我的控制台输出生成日志文件的代码:
/*************************Log Console **********************/
var log_file = fs.createWriteStream(base_log_path+'/getorders/getorders'+year+'-'+month+'-'+day+'-'+hours+'-'+minutes+'-'+seconds+'.log', {flags : 'w'});
var log_stdout = process.stdout;
console.log = function(d) { //
log_file.write(util.format(d) + '\n');
log_stdout.write(util.format(d) + '\n');
};
/*************************Log Console **********************/
请提出一些解决方案。
更新
generateOrdersServices.getOrders:
var getOrders = function(callback){
exportedTradeIds(storename,function(err_processedList, tradeIds){
if(err_processedList){
console.log("Error in getting Processed trade ids from exported table error is: "+err);
return callback('Error in getting Processed trade ids from exported table error is: '+err);
}
else if(tradeIds == 0)
{
console.log('No exported trade Ids');
return callback('No exported trade Ids');
}
else
{
jdp_tb_trade.getJstTrades('WAIT_BUYER_CONFIRM_GOODS', 900, 30, 'tmall_i18n', tradeIds, function(err_jdp, jdp_tb_trades){
if(err_jdp)
{
callback('Error in jdp_trade_response. Error is: '+err_jdp);
return;
}
if(!jdp_tb_trades)
{
callback(null, 'No result found from remote database.');
return;
}
else
{
for ( i in jdp_tb_trades) {
if(i == 1)
{
processConsign(jdp_tb_trades[i].tid,
function (err_process_consign, lpnumber) {
if (err_process_consign) {
console.log("Some error occurred in processConsign. Error is:" + err_process_consign);
var jdp_response_json_parsed = JSON.parse(jdp_tb_trades[i].jdp_response);
//Check if generate XML is enabled from admin end.
configuration.getOneByKey('generateXml', function (err_configuration, result_configuration) {
if (err_configuration) {
console.log('[generateXml]: generate xml enabled/disabled - No response.')
}
else
{
if (result_configuration.value == 'true') {
console.log('[generateXml]: generate xml enabled.')
generateXml(jdp_tb_trades[i].tid, jdp_response_json_parsed, lpnumber, function (err_generate_xml, success_generate_xml) {
if (err_generate_xml) {
return callback(err_generate_xml);
}
else {
return callback(null, success_generate_xml);
}
});
}
else{
console.log('[generateXml]: generate xml disabled.');
}
}
});
}
else
{
console.log("response from processConsign:Lpnumber" + lpnumber);
var jdp_response_json_parsed = JSON.parse(jdp_tb_trades[i].jdp_response);
//Check if generate XML is enabled.
configuration.getOneByKey(
'generateXml',
function (err_configuration, result_configuration) {
if (err_configuration) {
console.log('[generateXml]: generate xml enabled/disabled - No response.')
}
else {
if (result_configuration.value == 'true')
{
console.log('[generateXml]: generate xml enabled.')
generateXml(jdp_tb_trades[i].tid, jdp_response_json_parsed, lpnumber, function (err_generate_xml, success_generate_xml) {
if (err_generate_xml)
{
return callback(err_generate_xml);
}
else
{
return callback(null, success_generate_xml);
}
});
}
else
{
console.log('[generateXml]: generate xml disabled.');
}
}
});
}
});
}
}
}
});
}
})
};
module.exports = {
getOrders: function (callback) {
getOrders(function(err_getOrders, getOrdersResponse){
if(err_getOrders){
console.log("generate Order process error:"+err_getOrders);
return callback(err_getOrders);
}
else{
console.log("generate Order process success:"+getOrdersResponse);
return callback(null, getOrdersResponse);
}
});
},
}
我省略了 generateOrdersServices.getOrders 中的一些代码,因为这里不允许发布那么多代码。