Overriding console.log to customize the log with current time along with passed log arguments
npm install override-console-log # Override Console Log
- Author: Shammi Hans | Smi0001 https://github.com/orgs/IYAHU/people/Smi0001
- Dependency: JavaScript (ES06)
- Description: Overriding console.log to customize the log with current time along with passed log arguments
- License: GPL-3.0
__________
``sh |/ _ \
___ _ _
/ _ \__ _____ _ __ _ __(_) __| | ___
| | | \ \ / / _ \ '__| '__| |/ _
| |_| |\ V / __/ | | | | | (_| | __/
\___/ \_/ \___|_| |_| |_|\__,_|\___|
____ _ _
/ ___|___ _ __ ___ ___ | | ___ | | ___ __ _
| | / _ \| '_ \/ __|/ _ \| |/ _ \ | | / _ \ / _ |
| |__| (_) | | | \__ \ (_) | | __/ | |__| (_) | (_| |
\____\___/|_| |_|___/\___/|_|\___| |_____\___/ \__, |
|___/
``
__________NEW FEATURES
- Shorthand names available, just use log / logD / logE / logI
- Stop all Fns from executing, there is no need of finding & commenting / deleting each Fn calls configure 'stopLogging' ``
- Enable / disable any particular Fn or all Fns configure 'enableAll' / 'enableLog' / 'enableLogI', 'enableLogD' / 'enableLogE' ``
- Enable or disable date-time logging configure 'logDate' ``
- Customize log-type tag (replace INFO/DEBUG/ERROR with your own custom string as prefix) configure 'logDateThenPrefix' ``
- set the order of appearance for date-time and prefix-tag configure 'logDateThenPrefix' `
- Customize Date/Time format
- New 14 configurable options
#### HOW TO IMPORT
`javascript`
var { log, logI, logD, logE, logConfig } = require(`
ORjavascript`
import { log, logI, logD, logE, logConfig } from
javascript
console.log('Original logging'); // [2018-4-5 16:43:23] Original logging
console.logI('info format'); // [2018-4-5 16:43:23] INFO info format
console.logD('debug fromat'); // [2018-4-5 16:43:23] DEBUG debug fromat
console.logE('Error format'); // [2018-4-5 16:43:23] ERROR Error format
`
OR
`javascript
log('Original logging'); // [2018-4-5 16:43:23] Original logging
logI('info format'); // [2018-4-5 16:43:23] INFO info format
logD('debug fromat'); // [2018-4-5 16:43:23] DEBUG debug fromat
logE('Error format'); // [2018-4-5 16:43:23] ERROR Error format
`$3
1. `javascript
logDate: true
// set 'true' or 'false' to enable or disable logging of date-time
`
2. `javascript
logDateFormat: 'toLocaleString'
// set date format with the format-function-name in which user wants to convert the date
// Use 'toLocaleString' => '12/07/2018, 22:47:23',
// 'toDateString' => 'Thu Jul 12 2018',
// 'toGMTString' => 'Thu, 12 Jul 2018 17:17:23 GMT',
// 'toISOString' => '2018-07-12T17:17:23.031Z',
// 'toJSON' => '2018-07-12T17:17:23.031Z',
// 'toLocaleDateString' => '12/07/2018',
// 'toLocaleTimeString' => '22:47:23',
// 'toString' => 'Thu Jul 12 2018 22:47:23 GMT+0530 (India Standard Time)',
// 'toTimeString' => '22:47:23 GMT+0530 (India Standard Time)',
// 'toUTCString' => 'Thu, 12 Jul 2018 17:17:23 GMT'
`
3. `javascript
enableAll: true
// set 'true' or 'false' to enable or disable all logging Fns, if disabled all Fns will behave like simple console.log Fn
`
4. `javascript
enableLog: true
// set 'true' or 'false' to enable or disable 'log' Fn, if disabled it will behave like simple console.log Fn
`
5. `javascript
enableLogI: true
// set 'true' or 'false' to enable or disable 'logI' Fn, if disabled it will behave like simple console.log Fn
`
6. `javascript
enableLogD: true
// set 'true' or 'false' to enable or disable 'logD' Fn, if disabled it will behave like simple console.log Fn
`
7. `javascript
enableLogE: true
// set 'true' or 'false' to enable or disable 'logE' Fn, if disabled it will behave like simple console.log Fn
`
8. `javascript
logCustomPrefix: ''
// accepts any string of length < 1000, to log with custom prefix
//configuration:
// logConfig.logCustomPrefix =
// ;
//
// use:
// log('Hello world');
//
//output:
//
// LOG **
// Hello world
`
9. `javascript
logDateThenPrefix: true,
// use 'true' to set order of date first then prefix, or false to set order of prefix first then date
`
10. `javascript
debugPrefix: 'DEBUG'
// set any string for all debug logging
//configuration:
// logConfig.debugPrefix = 'debugger-mode';
//
// use:
// logD('value:', val);
//
//output:
// debugger-mode value:
`
11. `javascript
infoPrefix: 'INFO'
// set any string for all debug logging
//configuration:
// logConfig.infoPrefix = 'information-mode';
//
// use:
// logI('Value:', val);
//
//output:
// information-mode Value:
`
12. `javascript
errorPrefix: 'ERROR'
// set any string for all debug logging
//configuration:
// logConfig.errorPrefix = 'FOUND ERROR-->';
//
// use:
// logE(error.message);
//
//output:
// FOUND ERROR-->
`
13. `javascript
stopLogging: false
// set 'true' to stop all logging Fns to execute, set 'false' to let all logging Fns to execute
//configuration:
// logConfig.stopLogging = true;
//
//output:
//
`
14. `javascript
resetLogger(); // reset logger to default options
`
OR
`javascript
console.resetLogger(); // reset logger to default options
`$3
> See logger.js for functionalities examples.
> Execute `npm run dev` or `node logger.js`__________
Test Cases
> Unit test-cases are written using _Mocha_. Few test-cases are pending.$3
`
npm test
``__________
__________
Took help from Stackoverflow Forum
Test-cases written using Mocha Docs
__________