Skip to content

Commit

Permalink
feat!: change current exported function "log"
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the exports on this package have changed.  The current
functionality has moved to a `log` function in the exports.
  • Loading branch information
wraithgar committed Apr 12, 2024
1 parent 6442a36 commit 8e90af0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ log events that can be consumed by a listener on the process object.

## API

```js
const { log } = require('proc-log')
```

* `log.error(...args)` calls `process.emit('log', 'error', ...args)`
The highest log level. For printing extremely serious errors that
indicate something went wrong.
Expand Down Expand Up @@ -87,4 +91,4 @@ process.on('log', (level, ...args) => {
process.on('log', (...args) => {
fs.appendFileSync('debug.log', args.join(' '))
})
```
```
37 changes: 16 additions & 21 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
// emits 'log' events on the process
const LEVELS = [
'notice',
'error',
'warn',
'info',
'verbose',
'http',
'silly',
'pause',
'resume',
]

const log = level => (...args) => process.emit('log', level, ...args)

const logger = {}
for (const level of LEVELS) {
logger[level] = log(level)
const log = {
LEVELS: [
'notice',
'error',
'warn',
'info',
'verbose',
'http',
'silly',
'pause',
'resume',
],
}
for (const level of log.LEVELS) {
log[level] = (...args) => process.emit('log', level, ...args)
}

logger.LEVELS = LEVELS

module.exports = logger
module.exports = { log }
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const t = require('tap')
const log = require('../')
const { log } = require('../')
const { LEVELS } = log

t.matchSnapshot(LEVELS, 'log levels')
Expand Down

0 comments on commit 8e90af0

Please sign in to comment.