Skip to content

Add Winston log rotation to prevent unbounded log file growth in production #153

@Calebux

Description

@Calebux

Description

The Winston logger in /backend/src/services/logger.ts (or wherever it is configured) does not have log rotation configured. In production, log files will grow indefinitely until the disk fills up and the server crashes.

Current State

Winston is configured with file transports but no rotation:

new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' }),

A busy production server logging every request and blockchain event will generate hundreds of MB per day.

Fix

Use winston-daily-rotate-file:

npm install winston-daily-rotate-file
import DailyRotateFile from 'winston-daily-rotate-file';

const transport = new DailyRotateFile({
  filename: 'logs/application-%DATE%.log',
  datePattern: 'YYYY-MM-DD',
  zippedArchive: true,
  maxSize: '20m',      // rotate when file reaches 20MB
  maxFiles: '14d',     // keep 14 days of logs
  level: 'info',
});

const errorTransport = new DailyRotateFile({
  filename: 'logs/error-%DATE%.log',
  datePattern: 'YYYY-MM-DD',
  zippedArchive: true,
  maxSize: '10m',
  maxFiles: '30d',
  level: 'error',
});

const logger = winston.createLogger({
  transports: [transport, errorTransport],
});

Additional Steps

  • Add logs/ directory to .gitignore
  • Configure log level via LOG_LEVEL environment variable
  • Add structured logging fields: requestId, userId, duration on every request
  • Consider shipping logs to a service (Datadog, Papertrail, Axiom) for production

Acceptance Criteria

  • winston-daily-rotate-file installed and configured
  • Logs rotate daily with 14-day retention
  • Old logs are gzip-compressed
  • logs/ directory in .gitignore
  • LOG_LEVEL environment variable respected

Metadata

Metadata

Labels

BackendStellar WaveIssues in the Stellar wave programperformancePerformance issue or optimization

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions