0.0.0 • Published 2 years ago
@open-sandbox/ntw-logger v0.0.0
NTW Logger
ntw-logger is a singleton logging utility for Node.js applications built using the winston library. It provides structured logging formats, supports multiple transports, and offers a simple API for logging messages at different levels.
Features
- Singleton Pattern: Ensures only one instance of the logger is created.
- Custom Log Format: Combines timestamps, error stack traces, and other relevant information into structured logs.
- Multiple Transports: Logs to both the console and files (error logs and combined logs).
- Exception Handling: Automatically logs uncaught exceptions to a separate file.
- File Logging: Supports writing specific log messages to individual files.
Installation
You can install ntw-logger via npm:
npm install @open-sandbox/ntw-loggerUsage
import { LoggerService } from '@open-sandbox/ntw-logger';
const logger = LoggerService.getInstance();
// Logging at different levels
logger.info('Application has started');
logger.warn('This is a warning message');
logger.error('An error occurred', new Error('Sample error'));
// Logging to a specific file
logger.file('custom-log', 'This is a log message for a custom log file');Configuration
Log Levels
You can use the following log levels:
info: General information messageswarn: Warning messageserror: Error messages with optional stack trace
File Structure
By default, logs are saved in the logs directory:
logs/error.log: Contains error messageslogs/combined.log: Contains all messageslogs/exceptions.log: Contains uncaught exceptionslogs/browser: Contains custom logs
License
This project is licensed under the MIT License.
0.0.0
2 years ago