From 1a8289be748d1119a7d67978365f5240bc273257 Mon Sep 17 00:00:00 2001 From: Danilo Hoffmann Date: Fri, 4 Feb 2022 11:42:39 +0100 Subject: [PATCH] chore: PM2 logging adaptions for the Intershop Commerce-Plattform (#980) * chore: remove timestamp from PM2 log output * chore: add PM2 process id to logs * chore: log should contain process name for better understanding Co-authored-by: Marcel Eisentraut --- server.ts | 30 ++++++++++++++++++++++- src/ssr/server-scripts/build-ecosystem.js | 3 --- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/server.ts b/server.ts index bb1e0a4694f..8fa5ef21033 100644 --- a/server.ts +++ b/server.ts @@ -10,6 +10,28 @@ import { AppServerModule, ICM_WEB_URL, HYBRID_MAPPING_TABLE, environment, APP_BA import { ngExpressEngine } from '@nguniversal/express-engine'; import { getDeployURLFromEnv, setDeployUrlInFile } from './src/ssr/deploy-url'; +const PM2 = process.env.pm_id && process.env.name ? `${process.env.pm_id} ${process.env.name}` : undefined; + +if (PM2) { + const logOriginal = console.log; + + console.log = (...args: unknown[]) => { + logOriginal(PM2, ...args); + }; + + const warnOriginal = console.warn; + + console.warn = (...args: unknown[]) => { + warnOriginal(PM2, ...args); + }; + + const errorOriginal = console.error; + + console.error = (...args: unknown[]) => { + errorOriginal(PM2, ...args); + }; +} + const PORT = process.env.PORT || 4200; const DEPLOY_URL = getDeployURLFromEnv(); @@ -126,8 +148,14 @@ export function app() { server.set('views', BROWSER_FOLDER); if (logging) { + const morgan = require('morgan'); + // see https://github.com/expressjs/morgan#predefined-formats + let logFormat = morgan.tiny; + if (PM2) { + logFormat = `${PM2} ${logFormat}`; + } server.use( - require('morgan')('tiny', { + morgan(logFormat, { skip: (req: express.Request) => req.originalUrl.startsWith('/INTERSHOP/static'), }) ); diff --git a/src/ssr/server-scripts/build-ecosystem.js b/src/ssr/server-scripts/build-ecosystem.js index 3e3099d3d63..346a8df90e2 100644 --- a/src/ssr/server-scripts/build-ecosystem.js +++ b/src/ssr/server-scripts/build-ecosystem.js @@ -18,7 +18,6 @@ if (Object.keys(ports).length === 1) { name: distributor instances: ${process.env.CONCURRENCY_DISTRIBUTOR || 'max'} exec_mode: cluster - time: true `; } @@ -26,7 +25,6 @@ if (/^(on|1|true|yes)$/i.test(process.env.PROMETHEUS)) { content += ` - script: dist/prometheus.js name: prometheus - time: true `; } @@ -36,7 +34,6 @@ Object.entries(ports).forEach(([theme, port]) => { name: ${theme} instances: ${process.env.CONCURRENCY_SSR || 2} exec_mode: cluster - time: true max_memory_restart: ${process.env.SSR_MAX_MEM || '400M'} env: BROWSER_FOLDER: dist/${theme}/browser