caro-console
v0.9.6
Published
The module for easy-reading node.js console
Downloads
49
Readme
Caro-Console
The module for easy-reading node.js console depend on cli-color
Install and Usage
$ npm install caro
var cc = require('caro-console');
cc.log('This is caro-console');
Print nonstop-log
cc.log('This is ', undefined).log('And arr = ', ['caro', 'console']).log('End');
var name = 'caro';
var age = 18;
cc.log('I am %s and %s years old', name, age);
cc.log('I am ', name, ' and ', age, ' years old');
Set your log styles
cc.log.setOddColor('red').setEvenColor('magenta').setStyle('bold', 'underline');
cc.log('This is msg with color-red');
cc.log('This is msg with color-magenta');
Create a new log-function for yourself
cc.createLog('err').setOddColor('red').setEvenColor('magenta');
cc.err('This is Log used for error');
cc.createLog('notice').setColor('cyan').setStyle('bold', 'underline');
cc.notice('This is Log used for notice');
Support print Error
cc.log(new Error('This is Error')); // 'Error: This is Error'
Settings
- setColor([color='white']) - set log-color
cc.log.setColor('green');
- setOddColor([color='white']) - set log-color when it's odd
cc.log.setOddColor('green');
- setEvenColor([color='white']) - set log-color when it's even
cc.log.setEvenColor('green');
- setStyle(style...) - set log-style
cc.log.setStyle('bold', 'underline');
- setLine([length=0]) - will print line after each log
cc.log.setLine(40);
cc.log('This is Log with line after');
/*
This is Log with line after
========================================
*/
- showMe([bool=true]) - show stack-info that log placed
/* e.g. in [/caro-console/caro-console.js] */
cc.log.showMe();
cc.log('This is log with stack-info');
/*
Context.<anonymous> (/caro-console/caro-console.coffee:3:4)
This is log with stack-info
*/
- head(string | function) - show pre-log
var index = 0
cc.log.head(() ->
var date = new Date();
return '**Index:' + (++index) + ' - ' + date + '**';
);
cc.log('This is log 1');
cc.log('This is log 2');
/*
**Index:1 - Tue Jun 09 2015 19:00:24 GMT+0800 (CST)**
This is log 1
**Index:2 - Tue Jun 09 2015 19:00:24 GMT+0800 (CST)**
This is log 2
*/
cc.log.head(null)
cc.log('This is log without head')
- resetAll() - reset all settings
cc.log.resetAll();
Method
- createLog(logName) - create a new log-function
cc.createLog('err').setColor('red');
cc.err('This is Log used for error');
- line([length=40] [ifDouble=true]) - print line
cc.line(); // ========================================
cc.line(40,false); // ----------------------------------------
- accept(logName...) - choice which log-function you want to print
cc.log.setColor('white');
cc.createLog('info').setColor('green');
cc.createLog('err').setColor('red');
if (process.env.ENV_VARIABLE === 'production') {
// only print cc.err and cc.info in console when production
cc.accept('err', 'info');
} else {
cc.accept(); // accept all
}
cc.log('This is Log'); // won't print when production
cc.info('This is Info');
cc.err('This is Err');
- showWhere() - print stack-list
/* e.g. in [/caro-console/caro-console.js] */
cc.showWhere();
/*
[
'Context.<anonymous> (/caro-console/caro-console.js:2:4)',
...
...
]
*/
History
- Fix bug of print null - v0.9.2
- Print object by JSON - v0.9.1
- Support print Error - v0.9.0
- Add [Settings -> head] - v0.8.0
- Add [Method -> showWhere] - v0.7.0
- Add [Settings -> showMe] - v0.6.0
- Remove [Settings -> setBreakLine] - v0.5.2
- Update [Settings -> setLine] lineLength default to 0 - v0.5.2
- Remove [Method -> lineLog] - v0.5.2