https://github.com/akshay-singh-rajput/env-console-override
A package to customize console outputs based on the environment
https://github.com/akshay-singh-rajput/env-console-override
clear console fronted javascript npm reactjs
Last synced: 2 months ago
JSON representation
A package to customize console outputs based on the environment
- Host: GitHub
- URL: https://github.com/akshay-singh-rajput/env-console-override
- Owner: Akshay-Singh-Rajput
- License: mit
- Created: 2024-06-22T15:16:55.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-06-23T11:09:33.000Z (12 months ago)
- Last Synced: 2025-03-16T12:16:09.674Z (3 months ago)
- Topics: clear, console, fronted, javascript, npm, reactjs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/env-console-override?activeTab=readme
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# env-console-override
A flexible NPM package to customize console outputs with custom messages, ASCII art, or custom functions based on a whitelist of environments.
## Installation
To install this package, use npm:
```Js
npm install env-console-override
```# Basic Usage
```Js
const overWriteConsoleMethods = require('env-console-override');overWriteConsoleMethods({
logOptions: {
customMessage: 'Production Log Message',
asciiArt: ' A K K\n A A K K \n AAAAA KK \n A A K K \nA A K K'
},
whitelistEnvs: ['production']
});console.log("This will show a custom log message in production.");
```### Options
#### Main Options
- **logOptions**: Configuration for `console.log`.
- **warnOptions**: Configuration for `console.warn`.
- **errorOptions**: Configuration for `console.error`.
- **infoOptions**: Configuration for `console.info`.
- **whitelistEnvs**: Array of environments where the console methods should be overwritten (default: `['production']`).
- **env**: Current environment (default: `process.env.NODE_ENV`).#### Method Options
- **customMessage**: Custom message to display (default: `'Default Message'`).
- **asciiArt**: ASCII art to display.
- **customFunction**: Custom function to execute. Receives the original console method as the first argument and the original arguments as the rest.
- **clearOnly**: If `true`, only clears the console without displaying any message (default: `false`).# Example Usage
```Js
const overWriteConsoleMethods = require('env-console-override');// Example in production environment
process.env.NODE_ENV = 'production';overWriteConsoleMethods({
logOptions: {
customMessage: 'Production Log Message',
asciiArt: ' A K K\n A A K K \n AAAAA KK \n A A K K \nA A K K'
},
warnOptions: {
customMessage: 'Warning!',
},
errorOptions: {
customFunction: (originalError, ...args) => {
originalError('Custom Error Function Executed with args:', ...args);
}
},
infoOptions: {
customMessage: 'Information Message',
},
whitelistEnvs: ['production', 'staging']
});console.log("This will show a custom log message in production or staging.");
console.warn("This will show a custom warning message in production or staging.");
console.error("This will execute a custom error function in production or staging.");
console.info("This will show a custom information message in production or staging.");// Example in development environment
process.env.NODE_ENV = 'development';overWriteConsoleMethods({
logOptions: {
customMessage: 'Development log message',
clearOnly: true
},
whitelistEnvs: ['production']
});console.log("This will log normally in development.");
```