-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
77 lines (68 loc) · 2.81 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var fs = require('fs');
var success = function (url, method, functionName, time, response, sessionid ,res) {
var filename = '/' + sessionid + '_Success_Log.txt'
var date = new Date().getFullYear() + '-' + (new Date().getMonth()+1) + '-' + new Date().getDate();
if (fs.existsSync('logs/' + date)) {
if (fs.existsSync('logs/'+ date + filename)) {
successFunction(date, method, functionName, url, time, response, filename);
}
else {
fs.createWriteStream('logs/' + date + filename, { flag: 'a' });
successFunction(date, method, functionName, url, time, response, filename);
}
}
else {
fs.mkdirSync('logs/' + date);
if (fs.existsSync('logs/' + date + filename)) {
successFunction(date, method, functionName, url, time, response, filename);
}
else {
fs.createWriteStream('logs/' + date + filename, { flag: 'a' });
successFunction(date, method, functionName, url, time, response ,filename);
}
}
res.json({
success: true,
status: 200,
body: response
});
}
var failed = function (url, method, functionName, time, error, sessionid, res) {
var date = new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate();
var filename = '/' + sessionid + '_Error_Log.txt'
if (fs.existsSync('logs/' + date)) {
if (fs.existsSync('logs/' + date + filename)) {
failedFunction(date, method, functionName, url, time, error, filename);
}
else {
fs.createWriteStream('logs/' + date + filename, { flag: 'a' });
failedFunction(date, method, functionName, url, time, error, filename);
}
}
else {
fs.mkdirSync('logs/' + date);
if (fs.existsSync('logs/' + date + filename)) {
failedFunction(date, method, functionName, url, time, error, filename);
}
else {
fs.createWriteStream('logs/' + date + filename, { flag: 'a' });
failedFunction(date, method, functionName, url, time, error, filename);
}
}
res.json({
success: false,
status: 404,
body: error
});
}
function successFunction (date ,method , functionName, url, time, response, filename) {
fs.appendFileSync('logs/' + date + filename, 'Method: '
+ method + ' || Function Name: ' + functionName + ' || Url: ' + url
+ ' || Time: ' + time + ' || Response:' + JSON.stringify(response) + '\n');
}
function failedFunction(date, method, functionName, url, time, error, filename) {
fs.appendFileSync('logs/' + date + filename, 'Method: '
+ method + ' || Function Name: ' + functionName + ' || Url: ' + url
+ ' || Time: ' + time + ' || Response:' + JSON.stringify(error) + '\n');
}
module.exports = { failed, success }