diff --git a/package-lock.json b/package-lock.json index 67836511..cdfd644e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "elastic-apm-utils": "^4.1.1", "got": "^14.2.1", "gunzip-maybe": "^1.4.2", - "h-logger2": "^1.2.6", + "h-logger2": "^1.3.1", "h-logger2-elastic": "^6.2.1", "http-errors": "^2.0.0", "ipaddr.js": "^2.2.0", @@ -11268,9 +11268,9 @@ } }, "node_modules/h-logger2": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/h-logger2/-/h-logger2-1.2.6.tgz", - "integrity": "sha512-hujf7IH5SO+bE2mFHvsePj8075GI7stbwXn4ThjHm9L5fO6zFwv6yftXaqRe27QyxnrsMZ20bFXmfNcxd0wF/Q==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/h-logger2/-/h-logger2-1.3.1.tgz", + "integrity": "sha512-RwkqyXxos6vuaZsq88CL8ZAMQR3yhiFI/mPkqMK3Ym9lcJ1O+3iSe29MNM0inKq/n9xiddWxeDQy2dc7zh9BrQ==", "license": "MIT", "dependencies": { "chalk": "^4.1.2", diff --git a/package.json b/package.json index de10fba3..995be1fb 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "elastic-apm-utils": "^4.1.1", "got": "^14.2.1", "gunzip-maybe": "^1.4.2", - "h-logger2": "^1.2.6", + "h-logger2": "^1.3.1", "h-logger2-elastic": "^6.2.1", "http-errors": "^2.0.0", "ipaddr.js": "^2.2.0", diff --git a/src/lib/logger.ts b/src/lib/logger.ts index 4932a245..6a069686 100644 --- a/src/lib/logger.ts +++ b/src/lib/logger.ts @@ -15,13 +15,17 @@ if (process.env['ELASTIC_SEARCH_URL']) { }); } +const loggerOptions = { + inspectOptions: { breakLength: 120 }, +}; + const logger = new Logger( 'globalping-api', esClient ? [ - new ConsoleWriter(Number(process.env['LOG_LEVEL']) as LogLevelValue || Logger.levels.info), + new ConsoleWriter(Number(process.env['LOG_LEVEL']) as LogLevelValue || Logger.levels.info, loggerOptions), new ElasticWriter(Number(process.env['LOG_LEVEL']) as LogLevelValue || Logger.levels.info, { esClient, apmClient: apmAgent }), ] : [ - new ConsoleWriter(Number(process.env['LOG_LEVEL']) as LogLevelValue || Logger.levels.trace), + new ConsoleWriter(Number(process.env['LOG_LEVEL']) as LogLevelValue || Logger.levels.trace, loggerOptions), ], ); diff --git a/src/lib/ws/gateway.ts b/src/lib/ws/gateway.ts index 7eb5c076..53a33a2f 100644 --- a/src/lib/ws/gateway.ts +++ b/src/lib/ws/gateway.ts @@ -33,7 +33,7 @@ io socket.emit('api:connect:location', location); socket.emit('api:connect:adoption', { isAdopted }); - logger.info(`ws client ${socket.id} connected from ${location.city}, ${location.country} [${probe.ipAddress} - ${location.network}]`); + logger.info(`WS client connected`, { client: { id: socket.id, ip: probe.ipAddress }, location: { city: location.city, country: location.country, network: location.network } }); // Handlers socket.on('probe:status:update', handleStatusUpdate(probe)); diff --git a/src/lib/ws/helper/error-handler.ts b/src/lib/ws/helper/error-handler.ts index 2e9aa706..63a98d1a 100644 --- a/src/lib/ws/helper/error-handler.ts +++ b/src/lib/ws/helper/error-handler.ts @@ -25,7 +25,7 @@ export const errorHandler = (next: NextArgument) => (socket: ServerSocket, mwNex const clientIp = getProbeIp(socket) ?? ''; const reason = isError(error) ? error.message : 'unknown'; - logger.info(`Disconnecting client ${socket.id} for (${reason}) [${clientIp}]`); + logger.info(`Disconnecting client for (${reason})`, { client: { id: socket.id, ip: clientIp } }); logger.debug('Details:', error); if (mwNext) { diff --git a/src/lib/ws/helper/probe-ip-limit.ts b/src/lib/ws/helper/probe-ip-limit.ts index 65f9911a..28de40ce 100644 --- a/src/lib/ws/helper/probe-ip-limit.ts +++ b/src/lib/ws/helper/probe-ip-limit.ts @@ -68,7 +68,7 @@ export class ProbeIpLimit { const previousProbe = await this.getProbeByIp(ip, { allowStale: false }); if (previousProbe && previousProbe.client !== socketId) { - logger.warn(`ws client ${socketId} has reached the concurrent IP limit.`, { message: previousProbe.ipAddress }); + logger.warn(`WS client ${socketId} has reached the concurrent IP limit.`, { message: previousProbe.ipAddress }); throw new ProbeError('ip limit'); } } diff --git a/src/lib/ws/helper/subscribe-handler.ts b/src/lib/ws/helper/subscribe-handler.ts index 5522aa24..5a7ad245 100644 --- a/src/lib/ws/helper/subscribe-handler.ts +++ b/src/lib/ws/helper/subscribe-handler.ts @@ -16,7 +16,7 @@ export const subscribeWithHandler = (socket: ServerSocket, event: string, method const clientIp = probe.ipAddress; const reason = isError(error) ? error.message : 'unknown'; - logger.info(`Event "${event}" failed to handle. ${socket.id} for (${reason}) [${clientIp}]`); + logger.info(`Event "${event}" failed to handle for (${reason})`, { client: { id: socket.id, ip: clientIp } }); logger.debug(`Details:`, error); } });