Installations
npm install proc-log
Developer
npm
Developer Guide
Module System
CommonJS
Min. Node Version
^18.17.0 || >=20.5.0
Typescript Support
No
Node Version
22.8.0
NPM Version
10.8.3
Statistics
10 Stars
92 Commits
4 Forks
8 Watching
2 Branches
71 Contributors
Updated on 23 Nov 2024
Bundle Size
2.12 kB
Minified
667.00 B
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
945,271,350
Last day
2.5%
3,439,661
Compared to previous day
Last week
7%
18,024,769
Compared to previous week
Last month
12.9%
72,133,371
Compared to previous month
Last year
165.4%
628,718,784
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
3
proc-log
Emits events on the process object which a listener can consume and print to the terminal or log file.
This is used by various modules within the npm CLI stack in order to send log events that can be consumed by a listener on the process object.
Currently emits log
, output
, input
, and time
events.
API
1const { log, output, input, time } = require('proc-log')
output
-
output.standard(...args)
callsprocess.emit('output', 'standard', ...args)
This is for general standard output. Consumers will typically show this on stdout (after optionally formatting or filtering it).
-
output.error(...args)
callsprocess.emit('output', 'error', ...args)
This is for general error output. Consumers will typically show this on stderr (after optionally formatting or filtering it).
-
output.buffer(...args)
callsprocess.emit('output', 'buffer', ...args)
This is for buffered output. Consumers will typically buffer this until they are ready to display.
-
output.flush(...args)
callsprocess.emit('output', 'flush', ...args)
This is to indicate that the output buffer should be flushed.
-
output.LEVELS
an array of strings of all output method names
log
-
log.error(...args)
callsprocess.emit('log', 'error', ...args)
The highest log level. For printing extremely serious errors that indicate something went wrong.
-
log.warn(...args)
callsprocess.emit('log', 'warn', ...args)
A fairly high log level. Things that the user needs to be aware of, but which won't necessarily cause improper functioning of the system.
-
log.notice(...args)
callsprocess.emit('log', 'notice', ...args)
Notices which are important, but not necessarily dangerous or a cause for excess concern.
-
log.info(...args)
callsprocess.emit('log', 'info', ...args)
Informative messages that may benefit the user, but aren't particularly important.
-
log.verbose(...args)
callsprocess.emit('log', 'verbose', ...args)
Noisy output that is more detail that most users will care about.
-
log.silly(...args)
callsprocess.emit('log', 'silly', ...args)
Extremely noisy excessive logging messages that are typically only useful for debugging.
-
log.http(...args)
callsprocess.emit('log', 'http', ...args)
Information about HTTP requests made and/or completed.
-
log.timing(...args)
callsprocess.emit('log', 'timing', ...args)
Timing information.
-
log.pause()
callsprocess.emit('log', 'pause')
Used to tell the consumer to stop printing messages.
-
log.resume()
callsprocess.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
input
-
input.start(fn?)
callsprocess.emit('input', 'start')
Used to tell the consumer that the terminal is going to begin reading user input. Returns a function that will call
input.end()
for convenience.This also takes an optional callback which will run
input.end()
on its completion. If the callback returns aPromise
theninput.end()
will be run duringfinally()
. -
input.end()
callsprocess.emit('input', 'end')
Used to tell the consumer that the terminal has stopped reading user input.
-
input.read(...args): Promise
callsprocess.emit('input', 'read', resolve, reject, ...args)
Used to tell the consumer that the terminal is reading user input and returns a
Promise
that the producer canawait
until the consumer has finished its async action.This emits
resolve
andreject
functions (in addition to all passed in arguments) which the consumer must use to resolve the returnedPromise
.
time
-
time.start(timerName, fn?)
callsprocess.emit('time', 'start', 'timerName')
Used to start a timer with the specified name. Returns a function that will call
time.end()
for convenience.This also takes an optional callback which will run
time.end()
on its completion. If the callback returns aPromise
thentime.end()
will be run duringfinally()
. -
time.end(timerName)
callsprocess.emit('time', 'end', timeName)
Used to tell the consumer to stop a timer with the specified name.
Examples
log
Every log
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
log events and colorize them based on level:
1const chalk = require('chalk') 2 3process.on('log', (level, ...args) => { 4 if (level === 'error') { 5 console.log(chalk.red(level), ...args) 6 } else { 7 console.log(chalk.blue(level), ...args) 8 } 9})
Pause and resume
log.pause
and log.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.
1let paused = true 2const buffer = [] 3 4// this handler will buffer and replay logs only after `procLog.resume()` is called 5process.on('log', (level, ...args) => { 6 if (level === 'resume') { 7 buffer.forEach((item) => console.log(...item)) 8 paused = false 9 return 10 }Â 11 12 if (paused) { 13 buffer.push([level, ...args]) 14 } else { 15 console.log(level, ...args) 16 } 17}) 18 19// this handler will write everything to a file 20process.on('log', (...args) => { 21 fs.appendFileSync('debug.log', args.join(' ')) 22})
input
start
and end
producer.js
1const { output, input } = require('proc-log') 2const { readFromUserInput } = require('./my-read') 3 4// Using callback passed to `start` 5try { 6 const res = await input.start( 7 readFromUserInput({ prompt: 'OK?', default: 'y' }) 8 ) 9 output.standard(`User said ${res}`) 10} catch (err) { 11 output.error(`User cancelled: ${err}`) 12} 13 14// Manually calling `start` and `end` 15try { 16 input.start() 17 const res = await readFromUserInput({ prompt: 'OK?', default: 'y' }) 18 output.standard(`User said ${res}`) 19} catch (err) { 20 output.error(`User cancelled: ${err}`) 21} finally { 22 input.end() 23}
consumer.js
1const { read } = require('read') 2 3process.on('input', (level) => { 4 if (level === 'start') { 5 // Hide UI to make room for user input being read 6 } else if (level === 'end') { 7 // Restore UI now that reading is ended 8 } 9})
Using read
to call read()
producer.js
1const { output, input } = require('proc-log') 2 3try { 4 const res = await input.read({ prompt: 'OK?', default: 'y' }) 5 output.standard(`User said ${res}`) 6} catch (err) { 7 output.error(`User cancelled: ${err}`) 8}
consumer.js
1const { read } = require('read') 2 3process.on('input', (level, ...args) => { 4 if (level === 'read') { 5 const [res, rej, opts] = args 6 read(opts).then(res).catch(rej) 7 } 8})
No vulnerabilities found.
Reason
all changesets reviewed
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 26 commits out of 30 are checked with a SAST tool
Reason
8 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 6
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:21
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:22
- Warn: no topLevel permission defined: .github/workflows/audit.yml:1
- Warn: no topLevel permission defined: .github/workflows/ci-release.yml:1
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: topLevel 'contents' permission set to 'write': .github/workflows/post-dependabot.yml:8
- Warn: no topLevel permission defined: .github/workflows/pull-request.yml:1
- Warn: no topLevel permission defined: .github/workflows/release-integration.yml:1
- Warn: topLevel 'contents' permission set to 'write': .github/workflows/release.yml:11
- Warn: topLevel 'checks' permission set to 'write': .github/workflows/release.yml:13
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/audit.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/audit.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/audit.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/audit.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-release.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/ci-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-release.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/ci-release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-release.yml:63: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/ci-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-release.yml:112: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/ci-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-release.yml:128: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/ci-release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-release.yml:144: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/ci-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:89: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:95: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/post-dependabot.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/post-dependabot.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/post-dependabot.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/post-dependabot.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/post-dependabot.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/post-dependabot.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull-request.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/pull-request.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull-request.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/pull-request.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release-integration.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release-integration.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release-integration.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release-integration.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:199: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:218: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:236: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:274: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:283: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:303: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:57: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:66: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:76: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:83: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:110: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:119: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:136: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:162: update your workflow using https://app.stepsecurity.io/secureworkflow/npm/proc-log/release.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/audit.yml:38
- Warn: npmCommand not pinned by hash: .github/workflows/ci-release.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:42
- Warn: npmCommand not pinned by hash: .github/workflows/post-dependabot.yml:39
- Warn: npmCommand not pinned by hash: .github/workflows/pull-request.yml:42
- Warn: npmCommand not pinned by hash: .github/workflows/release-integration.yml:52
- Warn: npmCommand not pinned by hash: .github/workflows/release.yml:50
- Warn: npmCommand not pinned by hash: .github/workflows/release.yml:130
- Info: 0 out of 26 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 12 third-party GitHubAction dependencies pinned
- Info: 0 out of 8 npmCommand dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
6.8
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to proc-log
@types/proc-log
TypeScript definitions for proc-log
spawnd
Spawn a dependent child process.
@devicefarmer/adbkit-logcat
A Node.js interface for working with Android's logcat output.
@stroncium/procfs
Zero dependency library for reading and parsing various files from `procfs` for Node.js, implemented in pure JS.