Skip to content

ORESoftware/log-prepend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

log-prepend

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

API

const {lp} = require('log-prepend');
const log = lp(' [suman] ', process.stdout);
const logerr = lp(' [suman error] ', process.stderr);

log('a','b','c');
log('log1', 'log2\n3',4,5 + '\n55');

To use colors in the prepending string, simply do:

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

Extra

This works as a rudimentary solution:

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.

About

Create a function like console.log or console.error, but with a prepended string on each line.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published