Skip to content

Commit 1424559

Browse files
committed
Adding pino logger to hub
1 parent 41342a3 commit 1424559

File tree

5 files changed

+69
-23
lines changed

5 files changed

+69
-23
lines changed

packages/hyperproxy-hub/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "WebRTC hub for hyperproxy browser.",
55
"main": "index.js",
66
"bin": {
7-
"hyperproxy-hub": "./index.js"
7+
"hyperproxy-hub": "./index.js"
88
},
99
"scripts": {
1010
"start": "node lib/index.js",
@@ -26,6 +26,7 @@
2626
"bufferutil": "^3.0.3",
2727
"hyperproxy-config": "^1.0.0",
2828
"hyperproxy-node": "^1.0.0",
29+
"pino": "^4.16.1",
2930
"utf-8-validate": "^4.0.0",
3031
"uws": "^9.14.0"
3132
},

packages/hyperproxy-hub/src/index.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Pino from 'pino';
12
import WebSocket from 'uws';
23

34
import {HUB_PORT as port, HUB_MSG_TYPE} from 'hyperproxy-config';
@@ -7,18 +8,19 @@ const datMap = new Map();
78

89
const wss = new WebSocket.Server({port});
910

11+
const pretty = Pino.pretty();
12+
pretty.pipe(process.stdout);
13+
const logger = Pino({
14+
name: 'hyperproxy-hub',
15+
safe: true
16+
}, pretty);
17+
1018
function onConnection(ws) {
1119

1220
// Data token
13-
const app = ws
14-
.upgradeReq
15-
.url
16-
.split('?')[0]
17-
.split('#')[0]
18-
.substring(1)
19-
.split('/');
21+
const app = ws.upgradeReq.url.split('?')[0].split('#')[0].substring(1).split('/');
2022

21-
console.log('CONNECTED TO APP: ', app);
23+
logger.info(app, 'CONNECTED TO APP');
2224

2325
ws.app = app[app.length - 1];
2426

@@ -27,33 +29,32 @@ function onConnection(ws) {
2729
try {
2830
jsond = JSON.parse(data);
2931
} catch (e) {
30-
console.error(e.message);
32+
logger.error(e.message);
3133
return;
3234
}
3335

34-
console.log('Got message', jsond);
36+
logger.info(jsond, 'NEW WEBSOCKET MESSAGE');
3537

3638
// if not all channel and no HyperProxy-node has been assigned
3739
if (jsond.channel !== 'all' && jsond.message.type === HUB_MSG_TYPE.JOIN) {
3840
if (!datMap[jsond.channel]) {
41+
logger.info(jsond.channel, 'SPAWN NEW HYPERPROXY NODE');
3942
datMap[jsond.channel] = new HyperProxyNode(jsond.channel);
4043
}
4144

4245
return;
4346
}
4447

45-
wss
46-
.clients
47-
.forEach((client) => {
48-
if (jsond.app === client.app) {
49-
console.log('Broadcasting on app: %s', client.app);
50-
client.send(data);
51-
}
52-
});
48+
wss.clients.forEach((client) => {
49+
if (jsond.app === client.app) {
50+
logger.info('BROADCASTING ON APP: %s', client.app);
51+
client.send(data);
52+
}
53+
});
5354
});
5455
}
5556

5657
wss.on('connection', onConnection);
5758
wss.on('listening', function() {
58-
console.log(`HyperProxy Hub running on ${port}`);
59+
logger.info(`HyperProxy Hub running on ${port}`);
5960
});

packages/hyperproxy-node/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"dependencies": {
3030
"dat-node": "^3.5.8",
3131
"hyperproxy-config": "^1.0.0",
32+
"pino": "^4.16.1",
3233
"wrtc": "^0.1.1"
3334
}
3435
}

packages/hyperproxy-node/src/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
import Pino from 'pino';
12
import Dat from 'dat-node';
23
import Swarm from 'webrtc-swarm';
34
import SignalHub from 'signalhubws';
4-
import HyperproxyHubClient from 'hyperproxy-hub-client';
55
import Wrtc from 'wrtc';
66
import {w3cwebsocket as WebSocket} from 'websocket';
77

8+
import HyperproxyHubClient from 'hyperproxy-hub-client';
89
import {HUB_MSG_TYPE} from 'hyperproxy-config';
910

11+
const pretty = Pino.pretty();
12+
pretty.pipe(process.stdout);
13+
const logger = Pino({
14+
name: 'hyperproxy-node',
15+
safe: true
16+
}, pretty);
17+
1018
// TODO: Remove this commented out code @lgvichy
1119
// https://github.com/goonism/hyperproxy/issues/7
1220
// 40a7f6b6147ae695bcbcff432f684c7bb5291ea339c28c1755896cdeb80bd2f9

yarn.lock

+37-2
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ chalk@^1.1.3:
12041204
strip-ansi "^3.0.0"
12051205
supports-color "^2.0.0"
12061206

1207-
chalk@^2.0.0, chalk@^2.1.0:
1207+
chalk@^2.0.0, chalk@^2.1.0, chalk@^2.3.2:
12081208
version "2.3.2"
12091209
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.2.tgz#250dc96b07491bfd601e648d66ddf5f60c7a5c65"
12101210
dependencies:
@@ -2173,10 +2173,18 @@ fast-deep-equal@^1.0.0:
21732173
version "1.1.0"
21742174
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614"
21752175

2176+
fast-json-parse@^1.0.3:
2177+
version "1.0.3"
2178+
resolved "https://registry.yarnpkg.com/fast-json-parse/-/fast-json-parse-1.0.3.tgz#43e5c61ee4efa9265633046b770fb682a7577c4d"
2179+
21762180
fast-json-stable-stringify@^2.0.0:
21772181
version "2.0.0"
21782182
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
21792183

2184+
fast-safe-stringify@^1.0.8, fast-safe-stringify@^1.2.3:
2185+
version "1.2.3"
2186+
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-1.2.3.tgz#9fe22c37fb2f7f86f06b8f004377dbf8f1ee7bc1"
2187+
21802188
fd-read-stream@^1.1.0:
21812189
version "1.1.0"
21822190
resolved "https://registry.yarnpkg.com/fd-read-stream/-/fd-read-stream-1.1.0.tgz#d303ccbfee02a9a56a3493fb08bcb59691aa53b1"
@@ -2250,6 +2258,10 @@ flat-tree@^1.3.0, flat-tree@^1.6.0:
22502258
version "1.6.0"
22512259
resolved "https://registry.yarnpkg.com/flat-tree/-/flat-tree-1.6.0.tgz#fca30cddb9006fb656eb5ebc79aeb274e7fde9ed"
22522260

2261+
flatstr@^1.0.5:
2262+
version "1.0.5"
2263+
resolved "https://registry.yarnpkg.com/flatstr/-/flatstr-1.0.5.tgz#5b451b08cbd48e2eac54a2bbe0bf46165aa14be3"
2264+
22532265
for-each@^0.3.2, for-each@~0.3.2:
22542266
version "0.3.2"
22552267
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.2.tgz#2c40450b9348e97f281322593ba96704b9abd4d4"
@@ -3999,6 +4011,23 @@ pinkie@^2.0.0:
39994011
version "2.0.4"
40004012
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
40014013

4014+
pino-std-serializers@^2.0.0:
4015+
version "2.0.0"
4016+
resolved "https://registry.yarnpkg.com/pino-std-serializers/-/pino-std-serializers-2.0.0.tgz#63cbacf34bed8c95dd2c67eec824e48b8dd3445f"
4017+
4018+
pino@^4.16.1:
4019+
version "4.16.1"
4020+
resolved "https://registry.yarnpkg.com/pino/-/pino-4.16.1.tgz#8bcb6b685ee4d4e26adfe79a05f12f6b46962d40"
4021+
dependencies:
4022+
chalk "^2.3.2"
4023+
fast-json-parse "^1.0.3"
4024+
fast-safe-stringify "^1.2.3"
4025+
flatstr "^1.0.5"
4026+
pino-std-serializers "^2.0.0"
4027+
pump "^3.0.0"
4028+
quick-format-unescaped "^1.1.2"
4029+
split2 "^2.2.0"
4030+
40024031
prebuild-install@~2.3.0:
40034032
version "2.3.0"
40044033
resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-2.3.0.tgz#19481247df728b854ab57b187ce234211311b485"
@@ -4132,6 +4161,12 @@ [email protected]:
41324161
version "0.2.0"
41334162
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
41344163

4164+
quick-format-unescaped@^1.1.2:
4165+
version "1.1.2"
4166+
resolved "https://registry.yarnpkg.com/quick-format-unescaped/-/quick-format-unescaped-1.1.2.tgz#0ca581de3174becef25ac3c2e8956342381db698"
4167+
dependencies:
4168+
fast-safe-stringify "^1.0.8"
4169+
41354170
quick-lru@^1.0.0:
41364171
version "1.1.0"
41374172
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-1.1.0.tgz#4360b17c61136ad38078397ff11416e186dcfbb8"
@@ -4702,7 +4737,7 @@ speedometer@^1.0.0:
47024737
version "1.0.0"
47034738
resolved "https://registry.yarnpkg.com/speedometer/-/speedometer-1.0.0.tgz#cd671cb06752c22bca3370e2f334440be4fc62e2"
47044739

4705-
split2@^2.0.0:
4740+
split2@^2.0.0, split2@^2.2.0:
47064741
version "2.2.0"
47074742
resolved "https://registry.yarnpkg.com/split2/-/split2-2.2.0.tgz#186b2575bcf83e85b7d18465756238ee4ee42493"
47084743
dependencies:

0 commit comments

Comments
 (0)