@mohitrj49/traceline
v0.0.6
Published
log-message
Readme
@mohitrj49/traceline
@mohitrj49/traceline is a utility library for console logging that conditionally enables or disables logging based on the environment. This is especially useful to prevent logging in production environments while allowing detailed logs in development or testing environments.
Installation
You can install the package using npm:
npm install @mohitrj49/tracelineor using yarn:
yarn add @mohitrj49/tracelineUsage
Importing the Library
First, import the library in your TypeScript or JavaScript file:
import { traceline } from '@mohitrj49/traceline';Creating the Logger
You need to pass a function to determine if the environment is production. This function should return true if the environment is production, otherwise false.
const isProduction = (): boolean => {
return process.env.NODE_ENV === 'production';
};
const logger = traceline({ shouldDisableNativeLogs: isProduction() });Logging Methods
The logger provides several methods for logging messages:
- logger.info(...args: any[]): Logs informational messages.
- logger.warn(...args: any[]): Logs warning messages.
- logger.error(...args: any[]): Logs error messages.
- logger.log(...args: any[]): Logs general messages.
These methods will only output messages if the environment is not production.
Example
import { traceline } from '@mohitrj49/traceline';
const isProduction = (): boolean => {
return process.env.NODE_ENV === 'production';
};
const logger = traceline({ shouldDisableNativeLogs: isProduction() });
logger.info('This is an info message');
logger.warn('This is a warning message');
logger.error('This is an error message');
logger.log('This is a log message');License
This project is licensed under the MIT License. See the LICENSE file for more details.
