masklogger-node
v1.0.9
Published
A versatile logger module for Node.js with customizable logging levels and transports.
Downloads
2
Readme
Custom Logger
A versatile logger module for Node.js with customizable logging levels and transports.
Installation
To install the package, use npm or yarn:
npm install masklogger-node
# or
yarn add masklogger-node
Importing
const Logger = require('masklogger-node');
// or using ES6 import
import Logger from 'masklogger-node';
Creating Logger Instances
const fileTransport = new FileTransport({ filename: path.join(__dirname, 'combined.log'), level: LogLevelText.ERROR });
const consoleTransport = new ConsoleTransport();
const logger = new Logger({
transports: [consoleTransport, fileTransport],
});
Logging Levels
Logging Messages
The logger instance supports different log levels:
error(message: string)
warn(message: string)
info(message: string)
success(message: string)
custom(message: string)
Usage
const Logger = require('masklogger-node');
const path = require('path');
// Define file transport
const fileTransport = new Logger.FileTransport({
filename: path.join(__dirname, 'combined.log'),
level: Logger.LogLevelText.ERROR,
});
// Define console transport
const consoleTransport = new Logger.ConsoleTransport();
// Create logger with defined transports
const logger = new Logger.CustomLogger({ transports: [consoleTransport, fileTransport] });
Features
- Easy to configure
- Lightweight
- Supports different colors
- Supports file write