Skip to content

feat: rotating log files#98

Merged
dennis-zyska merged 2 commits intodevfrom
feat-55-rotating_logger
Feb 26, 2026
Merged

feat: rotating log files#98
dennis-zyska merged 2 commits intodevfrom
feat-55-rotating_logger

Conversation

@karimouf
Copy link
Copy Markdown
Collaborator

Implemented log rotation to prevent unbounded growth of activity logs in production

New Dev Features

  • Added log rotation capability using winston-daily-rotate-file for all log files (error, activity, and complete logs)
  • Integrated event listeners for rotation and error events to monitor log file management
  • Log files now automatically rotate when reaching 20MB size limit

Improvements

  • Log files are automatically compressed (gzipped) after rotation, significantly reducing disk space usage (~90% compression for JSON logs)
  • All rotated log files are preserved indefinitely without automatic deletion, ensuring complete audit trail
  • Rotation occurs seamlessly without requiring backend restart or manual intervention
  • Console logging added for rotation events to track when log files are rotated

Bug Fixes

  • Fixed unbounded log file growth in production mode that previously led to excessive disk usage
  • Prevented potential performance degradation caused by extremely large log files
  • Eliminated the need for risky manual log deletion while the backend is running

Known Limitations

  • Rotated log files are never automatically deleted, requiring manual cleanup if disk space becomes constrained over extended periods (e.g., multi-year deployments)

Future Steps

  • Consider implementing configurable retention policies (e.g., maxFiles setting) for environments with strict disk space constraints

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds log rotation support to the backend Winston logger to prevent log files from growing without bound in production.

Changes:

  • Replaced winston.transports.File with winston-daily-rotate-file transports for error/complete/activity logs (20MB max size + gzip).
  • Added rotate/error event listeners for the rotating file transports.
  • Added winston-daily-rotate-file dependency to backend package.json.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
backend/utils/logger.js Switches file logging to rotating transports and hooks up rotation/error event handlers.
backend/package.json Adds winston-daily-rotate-file dependency.

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

Comment on lines 124 to +155
exports = module.exports = function (service = "log", db = null) {
const errorTransport = new winston.transports.DailyRotateFile({
filename: logging_dir + '/error.log',
level: 'error',
maxSize: '20m',
zippedArchive: true
});

const completeTransport = new winston.transports.DailyRotateFile({
filename: logging_dir + '/complete.log',
level: process.env.LOGGING_LEVEL,
maxSize: '20m',
zippedArchive: true
});

const activityTransport = new winston.transports.DailyRotateFile({
filename: logging_dir + '/activity.log',
level: 'info',
maxSize: '20m',
zippedArchive: true
});

// Handle transport errors
[errorTransport, completeTransport, activityTransport].forEach(transport => {
transport.on('error', error => {
console.error('Log transport error:', error);
});

transport.on('rotate', (oldFilename, newFilename) => {
console.log('Log rotated from %s to %s', oldFilename, newFilename);
});
});
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

These DailyRotateFile transports (and their error/rotate listeners) are instantiated every time the exported logger factory is called. This codebase creates loggers in frequently constructed objects (e.g., per-socket connection), so this can lead to many concurrent file transports writing/rotating the same files (extra file descriptors, duplicated rotate events, potential contention). Consider creating the rotating transports once at module scope and returning baseLogger.child({service}), or otherwise ensuring transports are shared/singleton.

Copilot uses AI. Check for mistakes.
"uuid": "^8.3.2",
"winston": "^3.8.1",
"winston-daily-rotate-file": "^5.0.0",
"winston-transport": "^4.5.0",
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

package-lock.json is present in the repo, but this PR adds a new dependency. Please update and commit the lockfile as well (e.g., run npm install in backend/) so CI/production installs are deterministic.

Suggested change
"winston-transport": "^4.5.0",

Copilot uses AI. Check for mistakes.
@dennis-zyska dennis-zyska merged commit 960ec64 into dev Feb 26, 2026
2 checks passed
@dennis-zyska dennis-zyska deleted the feat-55-rotating_logger branch February 26, 2026 13:34
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.

3 participants