Socket
Socket
Sign inDemoInstall

proc-log

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proc-log - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

lib/index.js

30

package.json
{
"name": "proc-log",
"version": "1.0.0",
"version": "2.0.0",
"files": [
"index.js"
"bin",
"lib"
],
"main": "lib/index.js",
"description": "just emit 'log' events on the process object",
"repository": "https://github.com/npm/proc-log",
"author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)",
"author": "GitHub Inc.",
"license": "ISC",

@@ -14,16 +16,22 @@ "scripts": {

"snap": "tap",
"posttest": "eslint index.js test/*.js",
"posttest": "npm run lint",
"postsnap": "eslint index.js test/*.js --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags"
"prepublishOnly": "git push origin --follow-tags",
"lint": "eslint '**/*.js'",
"postlint": "npm-template-check",
"template-copy": "npm-template-copy --force",
"lintfix": "npm run lint -- --fix"
},
"devDependencies": {
"eslint": "^7.9.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"tap": "^15.0.2"
"@npmcli/template-oss": "^2.7.1",
"tap": "^15.1.6"
},
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=16"
},
"templateOSS": {
"version": "2.7.1"
}
}

@@ -7,3 +7,3 @@ # proc-log

This is used by various modules within the npm CLI stack in order to send
log events that [`npmlog`](http://npm.im/npmlog) can consume and print.
log events that can be consumed by a listener on the process object.

@@ -31,5 +31,62 @@ ## API

Information about HTTP requests made and/or completed.
* `log.pause(...args)` calls `process.emit('log', 'pause')` Used to tell
* `log.pause()` calls `process.emit('log', 'pause')` Used to tell
the consumer to stop printing messages.
* `log.resume(...args)` calls `process.emit('log', 'resume', ...args)`
* `log.resume()` calls `process.emit('log', 'resume')`
Used to tell the consumer that it is ok to print messages again.
* `log.LEVELS` an array of strings of all log method names
## Examples
Every method calls `process.emit('log', level, ...otherArgs)` internally.
So in order to consume those events you need to do `process.on('log', fn)`.
### Colorize based on level
Here's an example of how to consume `proc-log` events and colorize them
based on level:
```js
const chalk = require('chalk')
process.on('log', (level, ...args) => {
if (level === 'error') {
console.log(chalk.red(level), ...args)
} else {
console.log(chalk.blue(level), ...args)
}
})
```
### Pause and resume
`pause` and `resume` are included so you have the ability to tell your consumer
that you want to pause or resume your display of logs. In the npm CLI we use
this to buffer all logs on init until we know the correct loglevel to display.
But we also setup a second handler that writes everything to a file even if
paused.
```js
let paused = true
const buffer = []
// this handler will buffer and replay logs only
// after `procLog.resume()` is called
process.on('log', (level, ...args) => {
if (level === 'resume') {
buffer.forEach((item) => console.log(...item))
paused = false
return
if (paused) {
buffer.push([level, ...args])
} else {
console.log(level, ...args)
}
})
// this handler will write everything to a file
process.on('log', (...args) => {
fs.appendFileSync('debug.log', args.join(' '))
})
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc