lub-log
is a log util when you create your own lub plugin.
It supports several log types usually needed.
debug
log
info
warn
error
success
wait
start
watch
$ npm i lub-log --save
Setting your scope when require lub-log
and log:
const lubLog = require('./index')('hello');
lubLog.debug('hello world');
lubLog.info('Hello', 'world');
lubLog.warn('It will boom in %s seconds', '10');
lubLog.error('It throws an error');
lubLog.success('Build successfully!');
lubLog.wait('Writing to you file ...');
lubLog.start('Hello', 'world');
lubLog.watch({
prefix: 'webpack',
message: 'watching build directory...',
suffix: 'lub-log',
});
debug
method is based on debug, you scope name will be passed as debug's module name
You can also pass more configs into lub-log
,to log some useful info like date, time, filename:
const lubLog = require('./index')({
scope: [ 'hello', 'lub-log' ],
config: {
displayDate: true,
displayTimestamp: true,
displayFilename: true,
displayLabel: true,
displayBadge: true,
underlinePrefix: true,
uppercaseLabel: true,
underlineLabel: true,
underlineMessage: true,
underlineSuffix: true,
},
});
lubLog.debug('hello world');
lubLog.info('Hello', 'world');
lubLog.warn('It will boom in %s seconds', '10');
lubLog.error('It throws an error');
lubLog.success('Build successfully!');
lubLog.wait('Writing to you file ...');
lubLog.start('Hello', 'world');
lubLog.watch({
prefix: 'webpack',
message: 'watching build directory...',
suffix: 'lub-log',
});
- type:
Function
One of several log types usually needed mentioned above.
- type:
String
Can be one or more comma delimited strings.
They will be formated by Nodejs's util lib;
const lubLog = require('lub-log')();
lubLog.success('Successful operation');
//=> ✔ success Successful operation
lubLog.success('Successful', 'operation');
//=> ✔ success Successful operation
lubLog.success('Successful %s', 'operation');
//=> ✔ success Successful operation
- type:
Object
A object with prefix
, message
and suffix
props.
const lubLog = require('lub-log');
lubLog.complete({prefix: '[webpack]', message: 'build successfully', suffix: 'index.js'});
//=> [webpack] ☒ complete build successfully index.js
- type:
Error Object
When you pass an error object, lub-log
will log stack info:
const lubLog = require('lub-log');
lubLog.error(new Error('Unsuccessful operation'));
//=> ✖ error Error: Unsuccessful operation
// at Module._compile (module.js:660:30)
// at Object.Module._extensions..js (module.js:671:10)
// ...
Defines the scope name of the logger.
- type:
String
Clear the scope name of the logger.
Defines the setting config of the logger.
- type:
Object
The default config value is:
{
displayDate: false,
displayTimestamp: false,
displayFilename: false,
displayLabel: true,
displayBadge: true,
underlinePrefix: false,
uppercaseLabel: false,
underlineLabel: false,
underlineMessage: false,
underlineSuffix: false,
}