-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy patherror.js
More file actions
117 lines (103 loc) · 4.35 KB
/
Copy patherror.js
File metadata and controls
117 lines (103 loc) · 4.35 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var url = require('url'),
os = require('os'),
helpers = require('./helpers'),
CONFIG = require('../config/config'),
// object that contains all the errors and their numbers logged during the current minute
errorStorage = {};
module.exports = {
/**
* Check for duplicate error messages. If the same error message logged more than configured limit in one minute
* don't push it to the queue
*/
checkErrorLimitMessage : function checkErrorLimitMessage(ex) {
var d = new Date(),
min = d.getFullYear().toString() + d.getMonth().toString() + d.getDate().toString()
+ d.getHours().toString() + d.getMinutes().toString(),
key;
if (!ex) {
return true;
}
key = ex.Error.Message + ex.Error.ErrorType + ex.Error.SourceMethod;
if (errorStorage[min]) {
if (errorStorage[min][key]) {
errorStorage[min][key] += 1;
} else {
errorStorage[min][key] = 1;
}
} else {
errorStorage = {};
errorStorage[min] = {};
errorStorage[min][key] = 1;
}
return errorStorage[min][key] <= CONFIG.MSG.MAX_DUP_ERROR_PER_MINUTE;
},
// getting source method and source method line of code, not_direct is a flag indicating if the message was sent via direct logger
getStackTraceItem: function getStackTraceItem(err, not_direct) {
var trace = helpers.getTrace(err),
result = {},
lastElement = trace[trace.length - 1];
if (not_direct) {
if (lastElement) {
if (lastElement.CodeFileName === 'module.js') {
result.SrcMethod = trace[trace.length - 2].Method;
result.SrcLine = trace[trace.length - 2].LineNum;
} else {
result.SrcMethod = lastElement.Method;
result.SrcLine = lastElement.LineNum;
}
}
} else {
result.SrcMethod = trace[0].Method;
result.SrcLine = trace[0].LineNum;
}
return result;
},
// create the exception details object
formatEx : function formatEx(err, req, msg) {
var trace = helpers.getTrace(err),
ex = {
EnvironmentDetail: {
DeviceName: os.hostname(),
AppName: CONFIG.APPNAME,
AppLocation: process.env.PWD,
ConfiguredAppName: CONFIG.APPNAME,
ConfiguredEnvironmentName: CONFIG.APP_DETAILS ? CONFIG.APP_DETAILS.ENV : null
},
OccurredEpochMillis: Date.now(),
Error: {
Message: msg || err.message,
ErrorType: msg ? 'StringException' : err.name,
ErrorTypeCode: null,
SourceMethod: (trace && trace[0] && trace[0].Method) ? trace[0].Method : '',
StackTrace: trace,
InnerError: null
},
ServerVariables: CONFIG.LOG_SERVER_VARIABLES ? process.env : null
},
href;
// add web request details if req object is passed
if (req) {
href = url.parse(helpers.getURL(req), true);
ex.WebRequestDetail = {
UserIPAddress : req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress ||
req.connection.socket.remoteAddress,
HttpMethod: req.method,
RequestProtocol: req.connection.encrypted ? 'HTTPS' : 'HTTP',
RequestUrl: (req.connection.encrypted ? 'https://' : 'http://') + href.hostname + href.pathname,
RequestUrlRoot: href.hostname,
ReferralUrl: req.headers.referer,
Headers: req.headers,
Cookies: helpers.getCookies(req),
QueryString: href.query,
PostData: helpers.getPostData(req)
};
// mask certain headers so data is not sent to Stackify
["cookie", "authorization"].forEach(function(elm){
if (req.headers[elm]) {
ex.WebRequestDetail.Headers[elm] = CONFIG.COOKIE_MASK;
}
});
}
return ex;
}
};