The Complete Production SOP: How to Deploy and Run Winston Multi-Transport Logging & Daily File Rotation in Autonomous AI Agents
Step-by-step SOP to install and run winston-multi-transport-logger in Codex, Claude Code, & Cursor. Includes verified prompts, file rotation, and error fixes.
Technical Overview & Architectural Context
Autonomous coding agents frequently stumble when architecting Node.js logging infrastructure. When prompted to add logging, agents typically instantiate standard `console.log` statements or naive Winston singletons that lack stream backpressure, omit standardized ISO timestamps, combine stdout and stderr into raw text files, or write unrotated log files directly into project roots. This introduces serious production hazards: runaway disk space consumption from unrotated files, JSON parse failures in centralized aggregators like Datadog or ELK, and silent crashes when unhandled exceptions or rejected promises bypass standard transports. The `winston-multi-transport-logger` skill injects deterministic SOP boundaries directly into autonomous agents operating across Codex, Claude Code, Cursor, and Windsurf. By binding the agent to an auditable schema, it mandates decoupled transports—standard colored console output for local development, structured JSON rotation with compressed archiving for production, isolated exception and rejection handlers, and workspace-scoped file writing. With an audited 98/100 security score, it prevents agents from invoking dangerous child processes or writing outside sandboxed project logs directories.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules into the agent context.
Autonomous coding agents look for workspace or global skill definitions in standardized manifest paths (`.cursor/rules`, `.claude/skills`, or `.agents/skills`). Mounting the SKILL.md specification instructs the runtime to monitor prompt keywords such as 'configure winston logger' and dynamically inject procedural rules without polluting the global system prompt.
mkdir -p .agents/skills/winston-multi-transport-logger && cat << 'EOF' > .agents/skills/winston-multi-transport-logger/SKILL.md
---
name: "winston-multi-transport-logger"
description: "Route logs to multiple outputs, format timestamps, and manage automated daily file rotation."
metadata:
author: "Winston"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "configure winston logger"
- "winston daily rotate file"
- "custom winston format"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# Winston Multi-Transport Logging & Daily File Rotation
Configures Winston: defining transports (Console, File), formatting with winston.format, integrating winston-daily-rotate-file with retention limits, and exception handling.
EOF---
name: "winston-multi-transport-logger"
description: "Route logs to multiple outputs, format timestamps, and manage automated daily file rotation."
metadata:
author: "Winston"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "configure winston logger"
- "winston daily rotate file"
- "custom winston format"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---Place the SKILL.md in project-level `.agents/skills` or `.cursor/rules` to keep the prompt instructions scoped per repository, conserving context window tokens across unrelated projects.
Ensure `fs_write: workspace` is respected. Agents will error out if they attempt to write rotated logs to absolute host paths like `/var/log` without root permissions.
Dependency Installation & Base Logger Generation
Install Winston runtime modules and generate the modular logger utility adhering to SOP format rules.
The skill instructs the agent to install `winston` and `winston-daily-rotate-file`, create an isolated `src/utils/logger.ts` or `src/utils/logger.js`, and define separate formatting pipelines for human-readable console execution and JSON-serialized file persistence.
npm install winston winston-daily-rotate-file && npm install --save-dev @types/winstonimport winston from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';
import path from 'path';
const LOG_DIR = process.env.LOG_DIR || path.join(process.cwd(), 'logs');
const consoleFormat = winston.format.combine(
winston.format.colorize({ all: true }),
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }),
winston.format.printf(({ timestamp, level, message, ...meta }) => {
const metaString = Object.keys(meta).length ? JSON.stringify(meta, null, 2) : '';
return `[${timestamp}] [${level}]: ${message} ${metaString}`;
})
);
const fileFormat = winston.format.combine(
winston.format.timestamp(),
winston.format.errors({ stack: true }),
winston.format.json()
);
export const logger = winston.createLogger({
level: process.env.LOG_LEVEL || 'info',
format: fileFormat,
defaultMeta: { service: process.env.SERVICE_NAME || 'api-backend' },
transports: [
new winston.transports.Console({
format: consoleFormat,
silent: process.env.NODE_ENV === 'test',
}),
new DailyRotateFile({
dirname: LOG_DIR,
filename: 'application-%DATE%.log',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d',
level: 'info',
}),
new DailyRotateFile({
dirname: LOG_DIR,
filename: 'error-%DATE%.log',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '30d',
level: 'error',
}),
],
exceptionHandlers: [
new DailyRotateFile({
dirname: LOG_DIR,
filename: 'exceptions-%DATE%.log',
datePattern: 'YYYY-MM-DD',
maxFiles: '30d',
}),
],
rejectionHandlers: [
new DailyRotateFile({
dirname: LOG_DIR,
filename: 'rejections-%DATE%.log',
datePattern: 'YYYY-MM-DD',
maxFiles: '30d',
}),
],
exitOnError: false,
});Setting `exitOnError: false` stops Winston from immediately crashing the Node.js runtime on caught exceptions, allowing the active agent process to drain log buffers cleanly.
Always append `logs/` and `*.log` to `.gitignore`. Uncommitted log files confuse autonomous agents by polluting diffs during subsequent git commits.
Intent Matching & Trigger Invocation
Verify deterministic activation using tested natural language prompts in your IDE agent interface.
Provide a concrete directive matching the skill's triggers ('configure winston logger', 'winston daily rotate file', or 'custom winston format'). The agent runtime will scan its registered skills, activate `winston-multi-transport-logger`, and execute the structured logging configuration without introducing hallucinated logging packages or non-standard output schemas.
# In Claude Code CLI or Codex Desktop Chat:
claude-code 'Please configure winston logger with daily rotate file in src/utils/logger.ts and inject it into src/server.ts'import { logger } from './utils/logger';
logger.info('HTTP server initializing', {
port: process.env.PORT || 3000,
nodeEnv: process.env.NODE_ENV || 'development',
});Specify environment-based log levels in your prompt (`LOG_LEVEL=debug` for development, `LOG_LEVEL=info` for production) to allow the agent to wire up dynamic process.env handling cleanly.
Do not request the agent to log sensitive request bodies without masking SOPs; raw authorization headers or passwords could be permanently archived to disk.
Verification, Linting & Output Quality Gate
Execute automated self-healing checks and rotation sanity verification before accepting agent deliverables.
Enforce the skill's Verification Checklist. The agent or developer must verify that the logging module passes TypeScript compilation, logs serialize correctly into the target directory, and log rotation parameters hold without runtime permission errors.
npx tsc --noEmit && node -e "const { logger } = require('./dist/utils/logger'); logger.info('Self-check completed', { testRun: true });" && ls -la logs/#!/usr/bin/env bash
set -euo pipefail
echo 'Running logger lint and verification...'
npx eslint src/utils/logger.ts
npx tsc --noEmit
# Run smoke test in subshell
node -e "const { logger } = require('./dist/utils/logger'); logger.info('Healthcheck probe');"
if [ -d 'logs' ]; then
echo 'Verification successful: logs directory created with active file transports.'
exit 0
else
echo 'Error: logs directory was not created.' >&2
exit 1
fiInspect `git status` following verification to guarantee generated log files (`logs/application-*.log`) are ignored by Git.
If running inside a non-root Docker container, ensure the container user UID has write permissions to the mounted log volume directory.
Real-World Scenario: Microservice Log Aggregation & Rotation Hardening
“Please configure winston logger in our Express payment microservice. Set up a custom winston format with ISO timestamps, send human-readable colored logs to console in development, and stream JSON logs to a winston daily rotate file with 14-day retention and 20MB chunk limits for all errors and transaction events.”
Runtime Troubleshooting & Failure Modes
Root Cause: The directory specified in 'dirname' does not exist, and the agent did not enable automatic directory creation or ensure the path was created prior to logger instantiation.
import fs from 'fs';
import path from 'path';
const LOG_DIR = path.join(process.cwd(), 'logs');
if (!fs.existsSync(LOG_DIR)) {
fs.mkdirSync(LOG_DIR, { recursive: true });
}
// Alternatively, set 'createSymlink: false' and ensure DailyRotateFile is configured with an absolute dirname path.Root Cause: Common CommonJS/ESM interop discrepancy in TypeScript or Node.js project when importing 'winston-daily-rotate-file' with default imports.
// Use standard default import with esModuleInterop enabled in tsconfig.json:
import DailyRotateFile from 'winston-daily-rotate-file';
// Or if using CJS require:
// const DailyRotateFile = require('winston-daily-rotate-file');
// In tsconfig.json, verify:
// "compilerOptions": { "esModuleInterop": true, "allowSyntheticDefaultImports": true }Frequently Asked Questions (Winston Multi-Transport Logging & Daily File Rotation SOP)
Q:Can I use Winston Multi-Transport Logging & Daily File Rotation across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification. Whether placed in '.agents/skills/winston-multi-transport-logger' or linked into '.cursor/rules', Codex, Claude Code, Cursor, and Windsurf read the standardized metadata triggers and adhere to identical SOP constraints.
Q:How does Winston Multi-Transport Logging & Daily File Rotation prevent context window overflow during long agent sessions?
By prescribing precise configuration rules and transports in a self-contained skill document (~300 tokens), the agent does not require multi-turn prompting or huge system prompt injections to remember proper JSON formatting, exception handling, and rotation parameters.
Q:Does this skill require escalated root or container permissions?
No. The skill is audited with a security score of 98/100 and explicitly operates under 'fs_write: workspace' and 'shell_exec: false'. Logs are restricted to the workspace directory without requesting root access or modifying host system files outside the repository.
Ready to equip your autonomous agent with Winston Multi-Transport Logging & Daily File Rotation?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.