Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oresoftware/log-prepend
Create a function like console.log or console.error, but with a prepended string on each line.
https://github.com/oresoftware/log-prepend
javascript logging nodejs stderr stdout stream streaming
Last synced: 19 days ago
JSON representation
Create a function like console.log or console.error, but with a prepended string on each line.
- Host: GitHub
- URL: https://github.com/oresoftware/log-prepend
- Owner: ORESoftware
- License: mit
- Created: 2017-09-01T00:16:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-19T04:25:04.000Z (over 6 years ago)
- Last Synced: 2024-12-05T10:37:47.507Z (28 days ago)
- Topics: javascript, logging, nodejs, stderr, stdout, stream, streaming
- Language: JavaScript
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# log-prepend
Create a console.log or console.error like function, but prepend a string to each line.
## API
```js
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:
```js
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:
```js
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.