logger-sri-winston
v0.0.4
Published
Winston-based logger with file + console transports, structured JSON, timezone-aware timestamps, and console override.
Maintainers
Readme
Logger Utility
A simple Winston-based logger with automatic file and console logging, structured JSON output, Bangkok timezone timestamps, and optional console override for consistent logging across your Node.js application.
Features
- Logs to file and console simultaneously
- JSON format with timestamp and stack traces for errors
- Automatic service/file tagging for child loggers
- Optional console override to forward
console.log,console.error, etc. to Winston - Handles Error objects and structured metadata
Installation
npm install logger-sri-winstonUsage
const { getLogger } = require("logger-sri-winston");
const logger = getLogger(__filename);
logger.info("Server started");
logger.warn("This is a warning");
logger.error(new Error("Something went wrong"));Output (JSON):
{
"level": "info",
"message": "Server started",
"service": "server",
"timestamp": "2026-03-25T09:00:00"
}Override Console
Forward all console logs to Winston, keeping structured logging consistent:
- Supports: console.log, console.error, console.warn, console.debug, console.trace
- Error objects are automatically formatted with stack traces 0 Extra objects are included under the extra key in JSON logs
const { getLogger, overrideConsole } = require("logger-sri-winston");
const logger = getLogger(__filename);
const { console, restore } = overrideConsole(logger);
console.log("Hello World", { user: "santi" });
console.error(new Error("Oops!"));
restore(); // restore original consoleChild Logger Per File
Automatically tags each log with the file/service name:
const logger = getLogger(__filename);
logger.info("This log includes the file name as service");Logger Format
All logs are in JSON format:
{
"level": "info",
"message": "Hello World",
"service": "server",
"extra": { "user": "santi" },
"timestamp": "2026-03-25T09:00:00"
}Notes
- Timestamp is Bangkok time (Asia/Bangkok)
- Ensure logs folder exists; otherwise, Winston will throw an error
- console.trace is preserved as original console behavior
