Skip to content

Commit

Permalink
chore: PM2 logging adaptions for the Intershop Commerce-Plattform (#980)
Browse files Browse the repository at this point in the history
* 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 <meisentraut@intershop.de>
  • Loading branch information
2 people authored and SGrueber committed Feb 15, 2022
1 parent c04cfe9 commit 1a8289b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
30 changes: 29 additions & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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'),
})
);
Expand Down
3 changes: 0 additions & 3 deletions src/ssr/server-scripts/build-ecosystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ if (Object.keys(ports).length === 1) {
name: distributor
instances: ${process.env.CONCURRENCY_DISTRIBUTOR || 'max'}
exec_mode: cluster
time: true
`;
}

if (/^(on|1|true|yes)$/i.test(process.env.PROMETHEUS)) {
content += `
- script: dist/prometheus.js
name: prometheus
time: true
`;
}

Expand All @@ -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
Expand Down

0 comments on commit 1a8289b

Please sign in to comment.