Comparing version 1.0.0 to 2.0.0
{ | ||
"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(' ')) | ||
}) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5044
2
19
90
1