forked from tarun1475/Nodejs-Bittrex-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.js
74 lines (61 loc) · 2.02 KB
/
logging.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
var defaultLoggingLevel = 3;
var isLoggingEnabled = true;
var levels = {
trace : 0,
debug : 1,
info : 2,
warn : 3,
error : 4
};
exports.trace = trace;
exports.debug = debug;
exports.info = info;
exports.warn = warn;
exports.error = error;
exports.logDatabaseQuery = logDatabaseQuery;
// A variadic function to log the stuff
function log(loggingLevel, loggingParameters) {
var handlingInfo = loggingParameters[0];
var apiModule = handlingInfo.apiModule;
var apiHandler = handlingInfo.apiHandler;
// We need to log all the errors
if(loggingLevel !== levels.error && (!isLoggingEnabled || loggingLevel > defaultLoggingLevel)) {
return;
}
var stream = process.stdout;
if(loggingLevel === levels.error) {
stream = process.stderr;
}
for(var i = 1; i < loggingParameters.length; i++) {
stream.write(apiModule+ " ::: " + apiHandler + " ::: " + JSON.stringify(loggingParameters[i]) + "\n");
}
}
function trace(/* arguments */) {
log(levels.trace, arguments);
}
function debug(/* arguments */) {
log(levels.debug, arguments);
}
function info(/* arguments */) {
log(levels.info, arguments);
}
function warn(/* arguments */) {
log(levels.warn, arguments);
}
function error(/* arguments */) {
log(levels.error, arguments);
}
function logDatabaseQuery(handlerInfo, eventFired, error, result, query) {
if(error) {
if(typeof query !== 'undefined')
module.exports.error(handlerInfo, {event: eventFired}, {error: error}, {result : result}, {query : query});
else
module.exports.error(handlerInfo, {event: eventFired}, {error: error}, {result: result});
}
else {
if(typeof query !== 'undefined')
module.exports.trace(handlerInfo, {event: eventFired}, {error: error}, {result: result}, {query: query});
else
module.exports.trace(handlerInfo, {event: eventFired}, {error: error}, {result: result});
}
}