From 6c8d512d1abd5c4109f7e348fcc686cefed181be Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 17 Mar 2026 15:33:25 -0700 Subject: [PATCH] fix(logging): Improved logging --- bin/server.js | 6 ++- dev-docs/update-logs/2026-03-17.md | 60 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 dev-docs/update-logs/2026-03-17.md diff --git a/bin/server.js b/bin/server.js index f6196b5..63a1643 100644 --- a/bin/server.js +++ b/bin/server.js @@ -59,6 +59,7 @@ class Server { try { // Create an Express instance. const app = express() + app.set('trust proxy', true) const x402Settings = getX402Settings() const basicAuthSettings = getBasicAuthSettings() @@ -183,7 +184,10 @@ class Server { // Request logging middleware app.use((req, res, next) => { - wlogger.info(`${req.method} ${req.path}`) + wlogger.info(`${req.method} ${req.path}`, { + client_ip: req.ip, + remote_address: req.socket?.remoteAddress || null + }) next() }) diff --git a/dev-docs/update-logs/2026-03-17.md b/dev-docs/update-logs/2026-03-17.md new file mode 100644 index 0000000..08bdf62 --- /dev/null +++ b/dev-docs/update-logs/2026-03-17.md @@ -0,0 +1,60 @@ +# 2026-03-17 Update Log + +## Summary + +Enhanced REST request logging to capture client network identity in Winston logs and enabled proxy-aware IP resolution. + +## Changes Made + +- Updated `bin/server.js`: + - Set Express proxy handling with `app.set('trust proxy', true)`. + - Kept the current Winston request message format (`"${req.method} ${req.path}"`). + - Added structured Winston metadata fields to request logs: + - `client_ip` from `req.ip` + - `remote_address` from `req.socket.remoteAddress` + +## Useful Fields Available for REST Request Logging + +- Routing and request basics: + - `method` (`req.method`) + - `path` (`req.path`) + - `original_url` (`req.originalUrl`) + - `query` (`req.query`) +- Client network identity: + - `client_ip` (`req.ip`) + - `forwarded_ips` (`req.ips`, when behind one or more proxies) + - `remote_address` (`req.socket.remoteAddress`) +- HTTP and transport: + - `protocol` (`req.protocol`) + - `secure` (`req.secure`) + - `http_version` (`req.httpVersion`) + - `host` (`req.get('host')`) + - `origin` (`req.get('origin')`) + - `referer` (`req.get('referer')`) + - `user_agent` (`req.get('user-agent')`) +- Request/response performance and size: + - `status_code` (`res.statusCode`, from `res.on('finish')`) + - `duration_ms` (elapsed time between request start and response finish) + - `request_size_bytes` (`req.get('content-length')`) + - `response_size_bytes` (`res.getHeader('content-length')`) +- App-specific request context in this codebase: + - `basic_auth_valid` (`req.locals.basicAuthValid`) + - x402 decision/bypass status (derived from middleware path and config) + +## Already Logging + +- In Winston request logs: + - `message` with method + path (for example `GET /v6/full-node/blockchain/getBlockCount`) + - `client_ip` + - `remote_address` + - `timestamp` (from Winston timestamp formatter) + - `level` +- In console endpoint logs: + - Request line with method, path, and `req.ip` + - Response line with method, path, and final `res.statusCode` + +## Outcome + +- Request logs now preserve existing behavior while adding IP attribution fields. +- `trust proxy` ensures `req.ip` is proxy-aware when the server is deployed behind a reverse proxy. +- The project now has a documented list of high-value request fields for future logging expansion.