Skip to content

Commit eb88841

Browse files
authoredDec 8, 2021
allow sonic-boom to filter call to close on stdout (#280)
1 parent 68b3d9e commit eb88841

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed
 

‎index.js

-7
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,6 @@ function build (opts = {}) {
196196
sync: false
197197
})
198198
}
199-
/* istanbul ignore else */
200-
if (destination.fd === 1) {
201-
// We cannot close the output
202-
destination.end = function () {
203-
this.emit('close')
204-
}
205-
}
206199

207200
source.on('unknown', function (line) {
208201
destination.write(line + '\n')

‎test/basic.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,32 @@ test('basic prettifier tests', (t) => {
848848
t.doesNotThrow(pinoPretty)
849849
})
850850

851+
t.test('does not call fs.close on stdout stream', (t) => {
852+
t.plan(2)
853+
const destination = pino.destination({ minLength: 4096, sync: true })
854+
const prettyDestination = pinoPretty({ destination, colorize: false })
855+
const log = pino(prettyDestination)
856+
log.info('this message has been buffered')
857+
const chunks = []
858+
const { close, writeSync } = fs
859+
let closeCalled = false
860+
fs.close = new Proxy(close, {
861+
apply: (target, self, args) => {
862+
closeCalled = true
863+
}
864+
})
865+
fs.writeSync = new Proxy(writeSync, {
866+
apply: (target, self, args) => {
867+
chunks.push(args[1])
868+
return args[1].length
869+
}
870+
})
871+
destination.end()
872+
Object.assign(fs, { close, writeSync })
873+
t.match(chunks.join(''), /INFO .+: this message has been buffered/)
874+
t.equal(closeCalled, false)
875+
})
876+
851877
t.test('stream usage', async (t) => {
852878
t.plan(1)
853879
const tmpDir = path.join(__dirname, '.tmp_' + Date.now())

0 commit comments

Comments
 (0)
Please sign in to comment.