0.5.0 • Published 7 months ago
simple-log-helper v0.5.0
simple-log-helper
A lightweight logging utility to manage logs for different environments (development and production). Easily switch logging on or off based on your needs.
Installation
To install the package, use:
npm install simple-log-helper
Usage
Importing the Library
import { LogHelper } from "simple-log-helper";
const logHelper = new LogHelper();
logHelper.developmentLog("This is a development log.");
logHelper.productionLog("This is a production log.");
Class: LogHelper
new LogHelper(enableProductionMode: boolean = false)
Parameters:
enableProductionMode
(optional): A boolean value to toggle production mode. Defaults tofalse
(production mode Off).
notations:
#P
: Production mode#D
: Development mode$P
: starting of functionP$
: End of function
Methods
developmentLog(message: string): void
- Logs messages for development when
enableProductionMode
is set tofalse
.
- Logs messages for development when
productionLog(message: string): void
- Logs messages for production when
enableProductionMode
is set totrue
.
- Logs messages for production when
Example
Development mode: on
- All logs will get printed in this mode
const logHelper = new LogHelper(); // Development mode on by default
logHelper.developmentLog("This is a development log"); // #D 1/23/2025, 4:51:45 PM - This is a development log
logHelper.productionLog("This is a production log"); // #P 1/23/2025, 4:51:45 PM - This is a production log
Production mode: on
- Only development logs will not get printed in this mode
const logHelper = new LogHelper(true); // enable production mode
logHelper.developmentLog("This is a development log"); // Logs will not get printed.
logHelper.productionLog("This is a production log"); // #P 1/23/2025, 4:51:45 PM - This is a production log
logHelper.fnInitLog('Function execution started'); // $P 1/23/2025, 4:51:45 PM - Function execution started
logHelper.fnEndLog('Function execution completed'); // P$ 1/23/2025, 4:51:45 PM - Function execution completed
TypeScript Support
This package includes TypeScript definitions (.d.ts
) to ensure compatibility and autocompletion in TypeScript projects.
Contributing
Contributions are welcome! If you have suggestions or find issues, feel free to open a pull request or file an issue on GitLab.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
- Hiren Patel
- GitLab: Your GitLab Profile
Enjoy using simple-log-helper
! If you find it helpful, consider giving the repository a star!