@nodebug/logger
v1.1.4
Published
Simple Winston logger helper for Node.js applications
Downloads
772
Readme
@nodebug/logger
A simple Winston-based logger helper for Node.js applications.
Features
- Creates structured JSON logs for
errorandcombinedfiles - Adds console output automatically when not in production
- Creates the
logs/directory if it does not exist - Exposes a configurable logger factory
- Supports Node.js
>=24 - Zero dependencies beyond Winston
- Easy to use and configure
Installation
npm install @nodebug/loggerUsage
Default Logger
import { log } from '@nodebug/logger'
// Use the default logger
log.info('Application started')
log.error('Something went wrong')
log.warn('Warning message')
log.debug('Debug message')Custom Logger
import { createLogger } from '@nodebug/logger'
// Create a custom logger
const customLogger = createLogger({
level: 'info',
logDir: './logs',
console: true,
})
customLogger.error('Something went wrong')Custom Logger with Different Configuration
import { createLogger } from '@nodebug/logger'
// Create a logger with custom file names
const customLogger = createLogger({
level: 'debug',
logDir: './my-logs',
console: false,
errorFilename: 'errors.log',
combinedFilename: 'combined.log',
})
customLogger.info('Custom logger configured')API
createLogger(options)
Returns a Winston logger instance.
Options:
level— logger level (debug,info,warn,error) - default:'debug'logDir— directory for log files - default:'logs'console— boolean to enable console logging - default:truewhen not in productionerrorFilename— file name for error logs - default:'error.log'combinedFilename— file name for combined logs - default:'combined.log'
Development
Make sure to install Husky and lint-staged first:
npm install --save-devTo lint the code:
npm run lintTo format the code:
npm run formatRun tests:
npm testThe tests are now run with Jest
License
This project is licensed under the Mozilla Public License 2.0.# @nodebug/logger
MPL-2.0