项目作者: ORESoftware

项目描述 :
Create a function like console.log or console.error, but with a prepended string on each line.
高级语言: JavaScript
项目地址: git://github.com/ORESoftware/log-prepend.git
创建时间: 2017-09-01T00:16:08Z
项目社区:https://github.com/ORESoftware/log-prepend

开源协议:MIT License

下载


log-prepend

Create a console.log or console.error like function, but prepend a string to each line.

API

  1. const {lp} = require('log-prepend');
  2. const log = lp(' [suman] ', process.stdout);
  3. const logerr = lp(' [suman error] ', process.stderr);
  4. log('a','b','c');
  5. log('log1', 'log2\n3',4,5 + '\n55');

To use colors in the prepending string, simply do:

  1. const chalk = require('chalk');
  2. const log = lp(chalk.blue(' [suman] '), process.stdout);
  3. const logerr = lp(chalk.red(' [suman error] '), process.stderr);

Extra

This works as a rudimentary solution:

  1. const log = console.log.bind(console, ' [suman] ');

But the problem with the above log function is that it won’t handle new lines chars that are passed to it.