Skip to content

Commit 2f8160d

Browse files
authored
Disable demo-app logs by default (#271)
1 parent f82bd6d commit 2f8160d

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"build": "tsc --build tsconfig.json",
2525
"build:demo-app": "yarn workspace @pwrdrvr/lambda-dispatch-demo-app build",
2626
"start:demo-app": "NUMBER_OF_WORKERS=${NUMBER_OF_WORKERS:-1} yarn workspace @pwrdrvr/lambda-dispatch-demo-app start:app",
27+
"start:demo-app:logging": "NUMBER_OF_WORKERS=${NUMBER_OF_WORKERS:-1} yarn workspace @pwrdrvr/lambda-dispatch-demo-app start:app:logging",
2728
"test": "yarn workspace @pwrdrvr/lambda-dispatch-cdk test && yarn workspace @pwrdrvr/lambda-dispatch-cdk-stack test"
2829
},
2930
"author": "",

src/demo-app/app.cjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ const logFormat =
6262

6363
// Use the custom format
6464
app.use(trackBytes);
65-
app.use(morgan(logFormat));
65+
if (process.env.LOGGING === 'true') {
66+
app.use(morgan(logFormat));
67+
}
6668

6769
const port = 3001;
6870
const spdyPort = 3002;
@@ -371,7 +373,9 @@ app.post('/echo', async (req, res) => {
371373
const timestamp = new Date().toISOString();
372374
totalBytesReceived += chunk.length;
373375
if (debugMode) {
374-
console.log(`${logPrefix} - RECEIVED chunk ${chunk.length} bytes, total ${totalBytesReceived} bytes at ${timestamp}`);
376+
console.log(
377+
`${logPrefix} - RECEIVED chunk ${chunk.length} bytes, total ${totalBytesReceived} bytes at ${timestamp}`,
378+
);
375379
}
376380

377381
this.push(chunk);
@@ -383,7 +387,7 @@ app.post('/echo', async (req, res) => {
383387
console.log(`${logPrefix} - FINISHED`);
384388
}
385389
callback();
386-
}
390+
},
387391
});
388392

389393
// Pipe the req body to the response with back pressure
@@ -465,7 +469,7 @@ app.post('/double-echo', async (req, res) => {
465469

466470
app.post('/half-echo', async (req, res) => {
467471
const contentType = req.get('Content-Type');
468-
472+
469473
if (contentType) {
470474
res.set('Content-Type', contentType);
471475
}
@@ -492,7 +496,7 @@ app.post('/half-echo', async (req, res) => {
492496
const halfLength = chunk.length >> 1;
493497
this.push(chunk.slice(0, halfLength), 'binary');
494498
callback();
495-
}
499+
},
496500
});
497501

498502
// Pipe through halver transform then to response

src/demo-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"build:directlambda": "esbuild directlambda.mjs --bundle --platform=node --format=esm --external:./serverlessloader.cjs --outfile=dist/directlambda.mjs",
1111
"build:serverlessloader": "esbuild serverlessloader.cjs --bundle --platform=node --format=cjs --outfile=dist/serverlessloader.cjs",
1212
"start:app": "node dist/app.cjs",
13+
"start:app:logging": "LOGGING=true node dist/app.cjs",
1314
"start:directlambda": "node dist/directlambda.mjs"
1415
},
1516
"author": "PwrDrvr LLC",

0 commit comments

Comments
 (0)