two-log-min
v1.0.12
Published
ora and debug , just two logger, if debug
Downloads
38
Readme
two-log-min
switch
ora
anddebug
, ifdebug == true
log =>debug
, else log =>ora
install
npm i two-log-min
cli DEMO
npm i -g two-log-min-cli
Usage
// cli.js
const twoLog = require('two-log-min');
let D = cli.flags['D'] || false;
let l = twoLog(D);
let useWhat = !D ? 'ora' : 'log';
const o1 = {
ora: 'red',
log: 'cli',
};
const backLog = l.start(
`hello debug:${D} , then use ${c(useWhat)} ${m(toS(o1))}`,
o1
);
setTimeout(() => {
backLog(`use backLog ${c('withou log namespace')}`);
}, t - 5000);
const o2 = {
ora: 'green',
log: 'cli',
};
setTimeout(() => {
l.text(`ora:green, log:cli`, o2);
l.one('one time ora');
}, t - 3000);
const o3 = {
ora: 'green',
log: 'cli',
only: 'log',
};
setTimeout(() => {
l.text(`ora:green, only show log`, o3);
}, t - 2000);
const o4 = {
ora: 'fail',
log: 'cli',
};
setTimeout(() => {
l.stop(`i fail if ora `, o4);
}, t);
l.start === loggerStart
l.text === loggerText
l.stop === loggerStop
l.one === oneOra
logger
***
use for other module withoutl = twoLog(D)
init
2. doc-templite example
cli log with https://github.com/chinanf-boy/doc-templite/blob/master/cli.js#L51
main log with https://github.com/chinanf-boy/doc-templite/blob/master/doc-templite.js#L55
more start log 👆, only one stop https://github.com/chinanf-boy/doc-templite/blob/master/cli.js#L112
API
twoLog(debug, userUser):log
debug
| name: | debug |
| ----- | ----------------- |
| Type: | boolean
|
| Desc: | debug for two log |
userUse(api)
| name: | userUse |
| -------- | ---------------------------- |
| Type: | function(api)
|
| Default: | undefined
|
| Desc: | reset debug options for user |
api
| name: | api |
| -------- | ---------------------- |
| Type: | object
|
| Desc: | api for user |
| api.log: | log = require('debug') |
| api.ora: | ora = require('ora') |
let userUse = api => {
let createDebug = api.log;
createDebug.formatters.h = v => {
return v.toString('hex');
};
};
let l = twoLog(true, userUse);
// …elsewhere
const debug = l.start('something str', { log: 'foo' });
debug('this is hex: %h', new Buffer('hello world'));
// foo this is hex: 68656c6c6f20776f726c6421 +0ms
log
| name: | log |
| -------- | -------------------------------------------------- |
| Type: | any
|
| Desc: | log api |
| Default: | { start, text, stop, one }
|
| Details: | start === [loggerStart](#loggerstartstr-options)
|
| Details: | text === [loggerText](#loggertextstr-options)
|
| Details: | stop === [loggerStop](#loggerstopstr-options)
|
| Details: | one === oneOra
|
loggerStart(...args):strLog
str
| name: | str |
| -------------------- | ------------------------------------------------------------ |
| Type: | string
|
| Desc: | start log |
| Expand by ...args
: | start('one','two',opts) , one
+/% formatter two
will log |
options
| name: | options |
| ------------- | ------------------------------------------- |
| Type: | any
|
| Default: | { ora: 'yellow', log:
pkgName, only:"" }
|
| Desc: | log text |
| options.ora: | ora color |
| options.log: | debug show log level |
| options.only: | only one {'ora' | 'log'} can use |
pkgName
is the most closest package.json name
strLog(...args)
| name: | strLog |
| ----- | -------------------------------------------- |
| Type: | Function
|
| Desc: | can use debug
without namespace, may ora
|
const twoLog = require('../index');
let l = twoLog(true);
const strLog = l.start('something str', { log: 'foo' }); // here set debug namespace
strLog('this is just like debug');
loggerText(...args)
str
| name: | str |
| -------------------- | ----------------------------------------------------------- |
| Type: | string
|
| Desc: | log text |
| Expand by ...args
: | text('one','two',opts) , one
+/% formatter two
will log |
options
| name: | options |
| ------------- | ------------------------------------------ |
| Type: | any
|
| Default: | { ora: 'yellow', log: pkgName, only:"" }
|
| Desc: | log text |
| options.ora: | ora color |
| options.log: | debug show log level |
| options.only: | only one {'ora' | 'log'} can use |
pkgName
is the most closest package.json name
loggerStop(...args)
str
| name: | str |
| -------------------- | ----------------------------------------------------------- |
| Type: | string
|
| Desc: | log text |
| Expand by ...args
: | stop('one','two',opts) , one
+/% formatter two
will log |
options
| name: | options |
| ------------- | ------------------------------------------------------------------------ |
| Type: | any
|
| Default: | { ora: '', log: pkgName, only:"" }
|
| Desc: | log text |
| options.ora: | ora {fail\|succeed\|warn
} https://github.com/sindresorhus/ora#instance |
| options.log: | debug show log level |
| options.only: | only one {'ora' | 'log'} can use |
oneOra(...args)
str
| name: | str |
| -------------------- | ---------------------------------------------------------- |
| Type: | string
|
| Desc: | ora text |
| Expand by ...args
: | one('one','two',opts) , one
+/% formatter two
will log |
options
| 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 for ota |
concat
- two-log just need two log,
ora
/winston
License
MIT © chinanf-boy