Skip to content

anusthan12/Winston-logging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advanced Node.js Logger

Implementation of Winston with daily file rotation for logging in Node.js applications, featuring multi-level logging, daily rotation, and comprehensive request tracking.

Node.js Winston MVC

Features

  • Three-tier logging system:
    • Access logs (L1) — Basic request/response information
    • Detail logs (L2) — Comprehensive debug information
    • Error logs (L3) — Error tracking with stack traces
  • Daily log rotation with 200MB file size limit, 14-day retention, and automatic compression
  • Request Tracking — Method, URL, response time, status code, and IP address logging
  • Error Handling — Stack trace capture, request context preservation, and detailed error metadata
  • Security — Automatic directory creation, safe file rotation, and error protection

Installation

npm install winston winston-daily-rotate-file node-cron

Usage

const logger = require('./path/to/logger');
const express = require('express');
const app = express();

app.use(logger.requestLogger);  // Apply logger middleware
app.use(logger.errorHandler);   // Error handling

Log Levels

Level Code Description
Emergency 0 System is unusable
Alert 1 Immediate action required
Critical 2 Critical conditions
Error 3 Error conditions
Warning 4 Warning conditions
Notice 5 Normal but significant condition
Info 6 Informational messages
Debug 7 Debug-level messages

File Structure

logs/
├── access/
│   └── DD-MM-YYYY-access.log
├── detail/
│   └── DD-MM-YYYY-detail.log
└── error/
    └── DD-MM-YYYY-error.log

Configuration

Customize logging behavior by modifying the file rotation schedule (cron expression), file size limits, retention period, timestamp format, and log formats.

Author

Built and maintained by Anusthan Singh · © 2025

Releases

No releases published

Packages

 
 
 

Contributors