0.4.9 • Published 2 years ago
log-pose v0.4.9
LogPose
Helps you to not get lost.
$ npm i log-pose --save
# or `yarn add log-pose`API
Import the module and retrieve a shared logger instance.
import LogPose from 'log-pose';
// define logging level
LogPose.setLevel('verbose');
// get shared logger instance
const log = LogPose.getLogger();
// calling `newLogger()` returns a single method
const fail = LogPose.newLogger('my-app', 'verbose');pause()— Pause the logging outputresume()— Resume the logging outputsetLevel(type: String|Boolean)— Set a logging level to disable/enable verbs; iffalseis given logging gets disabledsetLogger([stdout: Object])— Set the standard-output for logging; if any falsy value is given, then the entire logging is disabled. Givenstdoutis used to output log messagesgetLogger([depth: Number[, stdout: Object]])— Returns a shared logger instance;depthis used on status formattingnewLogger(prefix: String[, level: String|Number[, depth: Number, stdout: Object]])— Returns a single logging method; actually, the shared logger is built from those methods. Methods are prefixed and receive a base level and depth; their output is skipped if given level is above the currently defined
Log levels are
info,debugandverbose.
Logger
It's a function that can print statuses:
// single status
log('testing');
// prefixed status
log('kind', 'value');
// async status
async function main() {
// single task delayed
await log('long task', () => new Promise(resolve => setTimeout(resolve, 1000)));
// prefixed task delayed
await log('kind', 'value', () => new Promise(resolve => setTimeout(resolve, 1000)));
// prefixed task delayed, with callback
await log('write', 'filepath', done => setTimeout(() => {
// custom feedback on logs
done('filepath', 'failed', 'fail');
}, 1000));
}
main();Also, it have some methods:
printf(...)— Prints always, with formatting enabledwrite(...)— Prints always, without formattinginfo(...)— Prints if level is> 0debug(...)— Prints if level is>= 1verbose(...)— Prints if level is>= 2isInfo()— Returnstrueif level is> 0isDebug()— Returnstrueif level is>= 1isVerbose()— Returnstrueif level is>= 2isEnabled()— Returnstrueif level is> 0
Formatting works calling built-in util.format() on printing, e.g.
log.info('{%info.bgBlue.white Text with spaces and values: %s%}\n', 42);Available symbols are:
tick→ ✔cross→ ✖star→ ★line→ ─info→ ➲reload→ ↺pointer→ ›warning→ ⚠
Built-in types are:
exception→line.bgRed.boldfeatured→star.bgBlue.boldfailure→warning.bgRed.whitesuccess→line.greenerror→line.redtip→star.yellowlink→line.cyanitem→line.graywarn→warning.boldinfo→info.bluefail→cross.redwait→reload.grayend→tick.cyanlog→pointer.grayok→tick.green
Using these you can short your code:
log.info('{%ok Text with spaces and values: %s%}\n', 42);Color names are defined by Chalk.
0.4.9
2 years ago
0.4.8
2 years ago
0.4.7
4 years ago
0.4.6
5 years ago
0.4.5
5 years ago
0.4.4
5 years ago
0.4.3
5 years ago
0.4.2
5 years ago
0.4.1
5 years ago
0.4.0
5 years ago
0.3.7
5 years ago
0.3.6
5 years ago
0.3.5
6 years ago
0.3.4
7 years ago
0.3.3
8 years ago
0.3.2
8 years ago
0.3.1
8 years ago
0.3.0
8 years ago
0.2.6
8 years ago
0.2.5
8 years ago
0.2.4
8 years ago
0.2.3
8 years ago
0.2.2
8 years ago
0.2.1
8 years ago
0.2.0
8 years ago
0.1.1
8 years ago
0.1.0
8 years ago