zconsole v1.0.2
ZConsole
A console instance with name and color assignment.
Use
Normal Use
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!"
Overwriting
Or even overwrite the normal one:
const ConsoleInstance = require('zconsole'),
console = new ConsoleInstance('My Console');
console.log('Yo bro!'); // Says "[My Console] Yo bro!"
Standalone function
For short, you can use:
const log = myConsole.getLogger;
// OR
const log = myConsole.logger;
And so:
log('Hey ya') // Says "[My Console] Hey ya"
Methods
Internal Methods
Get a stand-alone log() function
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"
Using the Display name
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('');
Setting a color to the console
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.
Static values
MAX_DISPLAY_LENGTH
Defines what is the max length for the string property display.
Defaults to 16.
colorNames
Just the names of the colors. Nothing usefull at all.
Copied Methods
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
Bonus
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.