Skip to content

API-57 request logs to stdout as JSON for CloudWatch#231

Merged
sedv8808 merged 1 commit into
developfrom
logs_apprunner
Jul 16, 2026
Merged

API-57 request logs to stdout as JSON for CloudWatch#231
sedv8808 merged 1 commit into
developfrom
logs_apprunner

Conversation

@sedv8808

@sedv8808 sedv8808 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

This pull request updates the logging setup in app.js to simplify request logging and improve compatibility with production environments. The main changes are the removal of the rotating-file-stream log file rotation, and the introduction of a JSON logging format for production, with improved handling for log analysis and health check noise reduction.

Logging improvements:

  • Replaced the rotating-file-stream-based file logging with logging directly to stdout, removing the dependency on rotating-file-stream and related custom log file naming code. [1] [2]
  • Introduced a JSON log format for production that includes structured fields (timestamp, IP, method, path, status, bytes, response time, user agent) to make logs easier to query and analyze with tools like CloudWatch Logs Insights.
  • Configured the logger to skip health check endpoints to reduce log noise.
  • In development, switched to the more readable 'dev' format for logs.

Copilot AI review requested due to automatic review settings July 16, 2026 18:28
@sedv8808
sedv8808 merged commit 8f8dc6c into develop Jul 16, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Express request-logging configuration to better suit production deployments (e.g., AWS App Runner/CloudWatch) by removing file-based rotation and emitting structured access logs.

Changes:

  • Removed rotating-file-stream usage and related log filename/rotation logic.
  • Added a production JSON access log format intended for CloudWatch Logs Insights and introduced healthcheck skipping.
  • Switched non-production logging to Morgan’s readable 'dev' format.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app.js
Comment on lines +77 to +78
const skipHealthChecks = (req) =>
req.url === '/healthcheck' || req.url.startsWith('/healthcheck/');
Comment thread app.js
Comment on lines 8 to 9
const morgan = require('morgan');
const rfs = require('rotating-file-stream'); // version 2.x
const path = require('path');
Comment thread app.js

const jsonAccessFormat = (tokens, req, res) => JSON.stringify({
type: 'access', // discriminator for queries: filter type = "access"
time: tokens.date(req, res, 'iso'),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants