Commit 62ef7a7f by Иван Кубота

logs

parent 306b2a1f
Pipeline #551 canceled with stage
......@@ -65,6 +65,47 @@ const parseArgs = function(req, res, opts) {
return args;
};
var logStream = fs.createWriteStream("/var/log/kus-quizard.txt", {flags:'a'});
function getDate(date){
if(date instanceof Date) {
return {
day: date.getDate(),
month: date.getMonth(),
//monthName: months[date.getMonth()],
year: date.getFullYear(),
date: date
};
}else if(date === null || date === void 0){
return null;
}else{
return date;
}
}
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'Jule',
'August',
'September',
'October',
'November',
'December'
];
const shortMonths = months.map(function(name) {
return name.substr(0,3);
});
shortMonths[8] = 'Sept';
function humanDate(date) {
let d = getDate(date);
return [d.day, shortMonths[d.month], d.year].join(' ');
}
module.exports = {
api2html: function(apis) {
var out = [];
......@@ -112,11 +153,17 @@ ${opt.required?'<span class="api-option-required">Required</span>': '<span class
try{
let result = await api.fn(args, req, res);
// fs.writeFileSync('./data/tmp/full.json', JSON.stringify(data, null, 2))
logStream.write(`${humanDate(new Date())} ${api.method}: ${key} ${JSON.stringify(args)}`)
logStream.write(`${JSON.stringify(result.log, null,1)}\n`);
res.end(typeof result === 'string' ? result : JSON.stringify(result, null,1), 'utf-8');
clearTimeout(timeout)
}catch(e){
debugger
logStream.write(`${humanDate(new Date())} ${api.method}: ${key} ${JSON.stringify(args)}`)
logStream.write(`ERROR: ${e.message+'\n'+e.stack}\n\n`)
res.end(e.message+'\n'+e.stack)
}
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment