Skip to content

Commit

Permalink
allow sonic-boom to filter call to close on stdout (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Dec 8, 2021
1 parent 68b3d9e commit eb88841
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
7 changes: 0 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@ function build (opts = {}) {
sync: false
})
}
/* istanbul ignore else */
if (destination.fd === 1) {
// We cannot close the output
destination.end = function () {
this.emit('close')
}
}

source.on('unknown', function (line) {
destination.write(line + '\n')
Expand Down
26 changes: 26 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,32 @@ test('basic prettifier tests', (t) => {
t.doesNotThrow(pinoPretty)
})

t.test('does not call fs.close on stdout stream', (t) => {
t.plan(2)
const destination = pino.destination({ minLength: 4096, sync: true })
const prettyDestination = pinoPretty({ destination, colorize: false })
const log = pino(prettyDestination)
log.info('this message has been buffered')
const chunks = []
const { close, writeSync } = fs
let closeCalled = false
fs.close = new Proxy(close, {
apply: (target, self, args) => {
closeCalled = true
}
})
fs.writeSync = new Proxy(writeSync, {
apply: (target, self, args) => {
chunks.push(args[1])
return args[1].length
}
})
destination.end()
Object.assign(fs, { close, writeSync })
t.match(chunks.join(''), /INFO .+: this message has been buffered/)
t.equal(closeCalled, false)
})

t.test('stream usage', async (t) => {
t.plan(1)
const tmpDir = path.join(__dirname, '.tmp_' + Date.now())
Expand Down

0 comments on commit eb88841

Please sign in to comment.