forked from blockchain/service-my-wallet-v3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (41 loc) · 1.34 KB
/
index.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
'use strict';
var winston = require('winston');
winston.level = process.env.LOGLEVEL || 'info';
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, { timestamp: Date.now });
// handle top level exceptions
process.on('uncaughtException', winston.error);
var server = require('./src/server')
, rpc = require('./src/rpc-server');
var extractWsError = /Websocket error: could not parse message data as JSON: ([^\^]+)/;
var consolelog = console.log.bind(console);
console.log = function (msg) {
if (
// "noise" messages, do not log
stringContains(msg, 'Server Time offset') ||
stringContains(msg, 'SAVE CALLED...') ||
stringContains(msg, 'published') ||
stringContains(msg, 'No free outputs to spend') ||
stringContains(msg && msg.initial_error, 'Connectivity error')
) return;
if (stringContains(msg, 'Websocket error:')) {
winston.error('WebSocketError', { message: msg.match(extractWsError)[1] });
return;
}
if (
stringContains(msg, 'Maximum concurrent requests') ||
stringContains(msg, 'Unknown API Key')
) {
winston.error(msg);
return;
}
consolelog.apply(this, arguments);
};
function stringContains(str0, str1) {
if (!str0 || !str1) return false;
return str0.toString().indexOf(str1) > -1;
}
module.exports = {
start: server.start,
startRPC: rpc.start
};