Node.js › Logging & Monitoring
What is log level (debug, info, warn, error), and how do you configure a logger like Pino or Winston to filter output by level per environment?
IntermediateAnswer
Log levels categorize the severity/importance of a log entry, letting a logger be configured to only actually output entries at or above a certain threshold -- typically 'debug' level (very verbose, useful during active development) is enabled locally but suppressed in production, where only 'info' and above are emitted, reducing log volume and cost while still capturing everything operationally relevant; 'error' level logs are reserved for genuine failures needing attention.
const pino = require('pino')({
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
});
pino.debug('Detailed diagnostic info'); // only shown in development
pino.info('Server started'); // shown in both
pino.error({ err }, 'Payment processing failed'); // always shown, needs attentionReal-world example A production service configured with log level 'info' silently drops thousands of verbose debug-level log lines per minute that would otherwise be generated during normal operation, keeping log storage costs manageable while a developer can temporarily set the level to 'debug' via an environment variable when actively investigating a specific issue.