Back to articles
Winston Has Free Production Logging for Node.js — Here's the Complete Setup Guide

Winston Has Free Production Logging for Node.js — Here's the Complete Setup Guide

via Dev.to WebdevAlex Spinov

Winston remains the most flexible Node.js logger. Here is how to set it up properly for production. Quick Start bun add winston import winston from " winston " ; const logger = winston . createLogger ({ level : " info " , format : winston . format . combine ( winston . format . timestamp (), winston . format . json () ), transports : [ new winston . transports . File ({ filename : " error.log " , level : " error " }), new winston . transports . File ({ filename : " combined.log " }), ], }); if ( process . env . NODE_ENV !== " production " ) { logger . add ( new winston . transports . Console ({ format : winston . format . combine ( winston . format . colorize (), winston . format . simple () ), })); } logger . info ( " Application started " , { port : 3000 }); logger . error ( " Database connection failed " , { host : " db.example.com " , code : " ECONNREFUSED " }); Custom Formats const customFormat = winston . format . combine ( winston . format . timestamp ({ format : " YYYY-MM-DD HH

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles