A console instance with name and color assignment.
Just do it:
const ConsoleInstance = require('zconsole');
var myConsole = new ConsoleInstance('My Console');
console.log('Hi!'); // Says "Hi!"
myConsole.log('Hi!'); // Says "[My Console] Hi!"
myConsole.color = 'blue';
myConsole.log('Hi!'); // Says a blue "[My Console] Hi!"
Or even overwrite the normal one:
const ConsoleInstance = require('zconsole'),
console = new ConsoleInstance('My Console');
console.log('Yo bro!'); // Says "[My Console] Yo bro!"
For short, you can use:
const log = myConsole.getLogger;
// OR
const log = myConsole.logger;
And so:
log('Hey ya') // Says "[My Console] Hey ya"
For getting a stand-alone log() function, with the display name but no need of using
console_name.log()
Use getLogger() or the get logger
property.
const log = console_instance.getLogger();
//--OR--
const log = console_instance.logger;
Now, just logging with a single function:
log('Hey ya') // Says "[My Console] Hey ya"
To get or alter the display name of the instance of the console, use the getter / setter display
// Getting the console name
var my_console_name = console_instance.display;
// Writing it into another console
another_console.display = my_console_name
.split('')
.reverse()
.join('');
At a similar way, there are a getter / setter pair to the color of the console:
console_instance.color = 'indigo';
console_instance.color = '#a2e100';
And so, console_instance.log
should output a colored text.
Defines what is the max length for the string property display.
Defaults to 16.
Just the names of the colors. Nothing usefull at all.
Here, are all the methods copied from the JS object console
:
- assert
- count
- debug
- dir
- dirxml
- error
- exception
- group
- group
- groupCollapsed
- groupEnd
- info
- log
-
time
- time
- timeEnd
- trace
- Acctually, here is a pseudo method
- warn
How I use it:
const ConsoleInstance = require('zconsole'),
console = new ConsoleInstance(appname);
console.color = 'cyan';
const log = console.logger;
log('It starts now.');
Where appname is the name of the app I'm working into.