Skip to content

Commit d0ce089

Browse files
committed
Log IP addresses
Closes: #165 PR-URL: #172
1 parent a6604df commit d0ce089

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/client.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Client {
2929
constructor(req, res, connection) {
3030
this.req = req;
3131
this.res = res;
32+
this.ip = req.socket.remoteAddress;
3233
this.connection = connection;
3334
}
3435

@@ -52,12 +53,12 @@ class Client {
5253
}
5354

5455
error(status, err, callId = err) {
55-
const { req: { url }, res, connection } = this;
56+
const { req: { url }, res, connection, ip } = this;
5657
const reason = http.STATUS_CODES[status];
5758
if (typeof err === 'number') err = undefined;
5859
const error = err ? err.stack : reason;
59-
const msg = status === 403 ? err.message : `${url} - ${error} - ${status}`;
60-
application.logger.error(msg);
60+
const msg = status === 403 ? err.message : `${url}\t${error}\t${status}`;
61+
application.logger.error(`${ip}\t${msg}`);
6162
const packet = { callback: callId, error: { message: reason } };
6263
const result = JSON.stringify(packet);
6364
if (connection) {

lib/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const listener = (req, res) => {
4949
clients.delete(connection);
5050
});
5151

52-
application.logger.log(`${method}\t${url}`);
52+
application.logger.log(`${client.ip}\t${method}\t${url}`);
5353
if (url === '/api') {
5454
if (method !== 'POST') {
5555
client.error(403, new Error(`Forbidden: ${url}`));

0 commit comments

Comments
 (0)