@ugm/logger
v1.0.2
Published
A simple and easy to use logger based on winston
Readme
@ugm/logger
A simple and easy-to-use logger based on Winston
Description
@ugm/logger is a lightweight logging utility built on top of Winston, designed to provide a straightforward and flexible logging solution for Node.js applications. Its key objective is to get up and running quickly with default logging to logs/combined.log for all logs and logs/error.log for errors.
Installation
npm install @ugm/logger
# or
pnpm add @ugm/loggerUsage
The logger is pre-configured to write all logs to logs/combined.log and error logs to logs/error.log. The package supports both ES Modules and CommonJS.
ES Modules (import)
Method 1: Import the pre-configured logger instance
import { logger } from '@ugm/logger';
// Use the logger directly
logger.info('This is an info message'); // Logged to logs/combined.log
logger.error('This is an error message'); // Logged to logs/combined.log and logs/error.log
logger.debug('This is a debug message'); // Logged to logs/combined.logMethod 2: Use the Logger class (for backward compatibility)
import { Logger } from '@ugm/logger';
const logger = new Logger();
logger.info('This is an info message'); // Logged to logs/combined.log
logger.error('This is an error message'); // Logged to logs/combined.log and logs/error.log
logger.debug('This is a debug message'); // Logged to logs/combined.logCommonJS (require)
Method 1: Require the pre-configured logger instance
const { logger } = require('@ugm/logger');
// Use the logger directly
logger.info('This is an info message'); // Logged to logs/combined.log
logger.error('This is an error message'); // Logged to logs/combined.log and logs/error.log
logger.debug('This is a debug message'); // Logged to logs/combined.logMethod 2: Use the Logger class (for backward compatibility)
const { Logger } = require('@ugm/logger');
const logger = new Logger();
logger.info('This is an info message'); // Logged to logs/combined.log
logger.error('This is an error message'); // Logged to logs/combined.log and logs/error.log
logger.debug('This is a debug message'); // Logged to logs/combined.logConfiguration
You can change default logfile names by using the following environment variables:
WINSTON_LOGS # Default: logs/combined.log
WINSTON_ERROR_LOGS # Default: logs/error.logFor development environments (when NODE_ENV is not 'production'), logs will also be output to the console with colorization.
Advanced Usage
For advanced configurations, refer to the Winston documentation.
Examples
Check out the examples directory for more detailed usage examples:
- Basic Usage - Simple example of using the logger
- Custom Logger - Advanced example showing how to customize the logger
License
ISC
