switch
ora
andwinston
, ifdebug == true
log =>winston
, else log =>ora
npm i two-log
npm i -g two-log-cli
// cli.js
const twoLog = require('two-log');
let D = cli.flags['D'] ? true : false;
let l = twoLog(D);
let useWhat = !D ? 'ora' : 'winston';
l.start(`hello there debug:${D} , then use ${useWhat}`, {
ora: 'red',
log: 'error',
});
let t = 5000;
setTimeout(() => {
l.text(`ora:green, log:debug and ${t} i will stop `, {
ora: 'green',
});
l.one('just show one time ora');
}, t - 3000);
setTimeout(() => {
l.text(`ora:green, log:debug and ${t} only show log style `, {
ora: 'green',
only: 'log',
});
}, t - 2000);
setTimeout(() => {
l.stop(`${t}ms , ok i fail if ora `, { ora: 'fail', log: 'debug' });
}, t);
logger
***
use for other module withoutl = twoLog(D)
init
name: | debug |
---|---|
Type: | boolean |
Desc: | debug for two log |
name: | userUse |
---|---|
Type: | function(api) |
Default: | undefined |
Desc: | reset winston options for user |
name: | api |
---|---|
Type: | object |
Desc: | api for user |
api.log: | log === winston |
api.setLog: | winston options |
api examples
let userUse = api => {
let winston = api.log;
let wopts = {
level: 'info',
};
api.setLog(wopts);
};
let l = log(true, userUse);
// winston level change
two-log default winston options
let defaultWinston = {
level: 'debug',
transports: [
new winston.transports.Console({
datePattern: '.yyyy-MM-ddTHH-mm',
colorize: true,
}),
new winston.transports.File({
filename: `${pkg.name}.log`,
handleExceptions: true,
maxsize: 52000,
maxFiles: 1,
level: 'info',
colorize: true,
}),
],
};
name: | log |
---|---|
Type: | any |
Desc: | log api |
Default: | { start, text, stop } |
Details: | start === loggerStart |
Details: | text === loggerText |
Details: | stop === loggerStop |
Details: | one === oneOra |
name: | str |
---|---|
Type: | string |
Desc: | log text |
name: | options |
---|---|
Type: | any |
Default: | { ora: 'yellow', log: 'debug', only:"" } |
Desc: | log text |
options.ora: | ora color |
options.log: | winston show log level |
options.only: | only one {'ora' | 'log'} can use |
name: | str |
---|---|
Type: | string |
Desc: | log text |
name: | options |
---|---|
Type: | any |
Default: | { ora: 'yellow', log: 'debug', only:"" } |
Desc: | log text |
options.ora: | ora color |
options.log: | winston show log level |
options.only: | only one {'ora' | 'log'} can use |
name: | str |
---|---|
Type: | string |
Desc: | log text |
name: | options |
---|---|
Type: | any |
Default: | { ora: '', log: 'debug', only:"" } |
Desc: | log text |
options.ora: | ora {fail|succeed|warn } https://github.com/sindresorhus/ora#instance |
options.log: | winston show log level |
options.only: | only one {'ora' | 'log'} can use |
name: | str |
---|---|
Type: | string |
Desc: | ora text |
name: | options |
---|---|
Type: | any |
Default: | { color: 'yellow', end: 'succeed' } |
Desc: | log text |
options.end: | end {fail|succeed|warn } https://github.com/sindresorhus/ora#instance |
options.color: | color |
- node-modules-size show node_modules hole size
- doc-templite multi-md-file with templite tool
MIT © chinanf-boy