Skip to content

Commit 3007e56

Browse files
committed
New websocket logging
1 parent a38c434 commit 3007e56

File tree

8 files changed

+69
-38
lines changed

8 files changed

+69
-38
lines changed

controllers/rpc2.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ router.post('/', textParser, async function(req, res) {
4242

4343
logEvent(
4444
'XmlRpc',
45-
request.methodName,
45+
{
46+
methodName: request.methodName,
47+
params: request.params
48+
},
4649
dayjs().format('x')
4750
);
4851

public/css/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,10 @@ tr:hover {
196196

197197
.mb-20 {
198198
margin-bottom: 20px;
199+
}
200+
201+
.log-panel {
202+
border: 1px solid #e0e0e0;
203+
border-radius: 8px;
204+
overflow: hidden;
199205
}

services/app-messages.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ module.exports = {
1616
tooManyParams: (method) => `Can't call "${method}" because there are too many parameters.`
1717
}
1818
},
19-
log: {
20-
subscription: (apiUrl, displayUrl, resourceUrl, protocol) => `Subscriber <a href="${apiUrl}">${displayUrl}</a> requests notification when the <a href="${resourceUrl}">resource</a> changes via <i>${protocol}</i> protocol.`,
21-
ping: (resourceUrl, result) => `The <a href="${resourceUrl}">resource</a> was said to have changed. We checked and the claim appears to be ${result}.`,
22-
notify: (apiUrl, displayUrl, resourceUrl, protocol) => `Subscriber <a href="${apiUrl}">${displayUrl}</a> was notified that <a href="${resourceUrl}">resource</a> has changed via <i>${protocol}</i> protocol.`,
23-
notifyFailed: (apiUrl, displayUrl, resourceUrl, protocol) => `Failed to notify subscriber <a href="${apiUrl}">${displayUrl}</a> that <a href="${resourceUrl}">resource</a> has changed via <i>${protocol}</i> protocol.`
24-
},
2519
success: {
2620
subscription: 'Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!',
2721
ping: 'Thanks for the ping.'

services/log-event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const getDayjs = require('./dayjs-wrapper'),
22
websocket = require('./websocket');
33

4-
async function logEvent(eventtype, htmltext, startticks, req) {
4+
async function logEvent(eventtype, data, startticks, req) {
55
const dayjs = await getDayjs();
66
let secs, time;
77

@@ -14,7 +14,7 @@ async function logEvent(eventtype, htmltext, startticks, req) {
1414

1515
websocket.broadcast({
1616
eventtype,
17-
htmltext,
17+
data,
1818
secs,
1919
time: new Date(time.utc().format()),
2020
headers: req.headers

services/notify-subscribers.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
const appMessages = require('./app-messages'),
2-
config = require('../config'),
1+
const config = require('../config'),
32
getDayjs = require('./dayjs-wrapper'),
43
logEvent = require('./log-event'),
54
mongodb = require('./mongodb'),
6-
notifyOne = require('./notify-one'),
7-
url = require('url');
5+
notifyOne = require('./notify-one');
86

97
async function fetchSubscriptions(resourceUrl) {
108
const subscriptions = await mongodb.get('rsscloud')
@@ -30,7 +28,6 @@ async function notifyOneSubscriber(resourceUrl, subscription) {
3028
const dayjs = await getDayjs();
3129
const apiurl = subscription.url,
3230
startticks = dayjs().format('x'),
33-
parts = url.parse(apiurl),
3431
notifyProcedure = subscription.notifyProcedure,
3532
protocol = subscription.protocol;
3633

@@ -43,7 +40,17 @@ async function notifyOneSubscriber(resourceUrl, subscription) {
4340

4441
await logEvent(
4542
'Notify',
46-
appMessages.log.notify(apiurl, parts.host, resourceUrl, parts.protocol),
43+
{
44+
subscriberUrl: apiurl,
45+
notifyProcedure: notifyProcedure,
46+
protocol: protocol,
47+
resourceUrl: resourceUrl,
48+
subscription: {
49+
totalUpdates: subscription.ctUpdates,
50+
consecutiveErrors: subscription.ctConsecutiveErrors,
51+
totalErrors: subscription.ctErrors
52+
}
53+
},
4754
startticks
4855
);
4956
} catch (err) {
@@ -55,7 +62,18 @@ async function notifyOneSubscriber(resourceUrl, subscription) {
5562

5663
await logEvent(
5764
'NotifyFailed',
58-
appMessages.log.notifyFailed(apiurl, parts.host, resourceUrl, parts.protocol),
65+
{
66+
subscriberUrl: apiurl,
67+
notifyProcedure: notifyProcedure,
68+
protocol: protocol,
69+
resourceUrl: resourceUrl,
70+
subscription: {
71+
totalUpdates: subscription.ctUpdates,
72+
consecutiveErrors: subscription.ctConsecutiveErrors,
73+
totalErrors: subscription.ctErrors
74+
},
75+
error: err.message
76+
},
5977
startticks
6078
);
6179
}

services/ping.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@ async function checkForResourceChange(resource, resourceUrl, startticks) {
6969

7070
await logEvent(
7171
'Ping',
72-
appMessage.log.ping(resourceUrl, resource.flDirty.toString()),
72+
{
73+
resourceUrl: resourceUrl,
74+
changed: resource.flDirty,
75+
hash: resource.lastHash,
76+
size: resource.lastSize,
77+
stats: {
78+
totalChecks: resource.ctChecks,
79+
totalUpdates: resource.ctUpdates
80+
}
81+
},
7382
startticks
7483
);
7584
}

services/please-notify.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const appMessages = require('./app-messages'),
66
logEvent = require('./log-event'),
77
mongodb = require('./mongodb'),
88
notifyOne = require('./notify-one'),
9-
notifyOneChallenge = require('./notify-one-challenge'),
10-
url = require('url');
9+
notifyOneChallenge = require('./notify-one-challenge');
1110

1211
async function checkresourceUrlStatusCode(resourceUrl) {
1312
const controller = new AbortController();
@@ -53,8 +52,7 @@ async function upsertSubscriptions(subscriptions) {
5352
async function notifyApiUrl(notifyProcedure, apiurl, protocol, resourceUrl, diffDomain) {
5453
const dayjs = await getDayjs();
5554
const subscriptions = await fetchSubscriptions(resourceUrl),
56-
startticks = dayjs().format('x'),
57-
parts = url.parse(apiurl);
55+
startticks = dayjs().format('x');
5856

5957
await initSubscription(subscriptions, notifyProcedure, apiurl, protocol);
6058

@@ -78,7 +76,12 @@ async function notifyApiUrl(notifyProcedure, apiurl, protocol, resourceUrl, diff
7876

7977
await logEvent(
8078
'Subscribe',
81-
appMessages.log.subscription(apiurl, parts.host, resourceUrl, parts.protocol),
79+
{
80+
subscriberUrl: apiurl,
81+
notifyProcedure: notifyProcedure,
82+
resourceUrl: resourceUrl,
83+
diffDomain: diffDomain
84+
},
8285
startticks
8386
);
8487
} catch {

views/view-log.handlebars

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,25 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
<title>rssCloud: Log</title>
77
<link href="/css/style.css" rel="stylesheet">
8-
<script type="module" src="https://esm.sh/@andrewshell/socklog"></script>
9-
<style>
10-
socklog-viewer {
11-
display: block;
12-
height: 70vh;
13-
border: 1px solid #ccc;
14-
border-radius: 4px;
15-
margin-top: 10px;
16-
}
17-
socklog-controls {
18-
display: block;
19-
margin-top: 20px;
20-
}
21-
</style>
228
</head>
239
<body>
2410
<h1>rssCloud: Log</h1>
2511
<p>Real-time events on this rssCloud server.</p>
2612

27-
<socklog-controls></socklog-controls>
28-
<socklog-viewer url="ws://{{host}}:{{port}}/wsLog"></socklog-viewer>
13+
<script type="module">
14+
import 'https://esm.sh/@andrewshell/socklog'
15+
16+
const viewer = document.getElementById('viewer')
17+
const controls = document.getElementById('controls')
18+
19+
// Connect controls to viewer's log store
20+
controls.store = viewer.getStore()
21+
</script>
22+
23+
<div class="log-panel">
24+
<socklog-controls id="controls"></socklog-controls>
25+
<socklog-viewer id="viewer" url="ws://{{host}}:{{port}}/wsLog"></socklog-viewer>
26+
</div>
2927

3028
<p class="mt-20">
3129
<a href="/">← Back to Home</a>

0 commit comments

Comments
 (0)