Skip to content

Commit

Permalink
Log requests to static
Browse files Browse the repository at this point in the history
Closes: #434
PR-URL: #453
  • Loading branch information
tshemsedinov committed Sep 11, 2023
1 parent 978c715 commit 1702396
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ class Transport extends EventEmitter {
this.send(packet, httpCode);
}

log(code) {
const { server, req, ip } = this;
const { console } = server;
const { url, method } = req;
const msg = `${ip}\t${method}\t${url}\t${code}`;
if (code >= 200 && code <= 299) console.debug(msg);
else console.error(msg);
}

send(obj, code = 200) {
const data = JSON.stringify(obj);
this.write(data, code, 'json');
Expand All @@ -124,6 +133,7 @@ class HttpTransport extends Transport {
}

write(data, httpCode = 200, ext = 'json', options = {}) {
this.log(httpCode);
const { res } = this;
if (res.writableEnded) return;
const streaming = data instanceof Readable;
Expand Down

0 comments on commit 1702396

Please sign in to comment.