mirror of
https://github.com/pinojs/pino.git
synced 2026-02-01 17:46:06 +00:00
Remove in-between Transform for file (#1140)
This commit is contained in:
parent
8261137d97
commit
ba7241fa01
12
file.js
12
file.js
@ -1,20 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const { Transform, pipeline } = require('stream')
|
||||
const pino = require('./pino')
|
||||
const { once } = require('events')
|
||||
|
||||
module.exports = async function (opts = {}) {
|
||||
const stream = new Transform({
|
||||
objectMode: true,
|
||||
autoDestroy: true,
|
||||
transform (chunk, enc, cb) {
|
||||
cb(null, chunk.toString())
|
||||
}
|
||||
})
|
||||
|
||||
const destination = pino.destination({ dest: opts.destination || 1, sync: false })
|
||||
await once(destination, 'ready')
|
||||
pipeline(stream, destination, () => {})
|
||||
return stream
|
||||
return destination
|
||||
}
|
||||
|
||||
29
test/fixtures/transport-many-lines.js
vendored
Normal file
29
test/fixtures/transport-many-lines.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
'use strict'
|
||||
|
||||
const pino = require('../..')
|
||||
const transport = pino.transport({
|
||||
targets: [{
|
||||
level: 'info',
|
||||
target: 'pino/file',
|
||||
options: {
|
||||
destination: process.argv[2]
|
||||
}
|
||||
}]
|
||||
})
|
||||
const logger = pino(transport)
|
||||
|
||||
const toWrite = 1000000
|
||||
transport.on('ready', run)
|
||||
|
||||
let total = 0
|
||||
|
||||
function run () {
|
||||
if (total++ === 8) {
|
||||
return
|
||||
}
|
||||
|
||||
for (let i = 0; i < toWrite; i++) {
|
||||
logger.info(`hello ${i}`)
|
||||
}
|
||||
transport.once('drain', run)
|
||||
}
|
||||
@ -11,6 +11,13 @@ const url = require('url')
|
||||
const strip = require('strip-ansi')
|
||||
const execa = require('execa')
|
||||
const writer = require('flush-write-stream')
|
||||
const { promisify } = require('util')
|
||||
const stream = require('stream')
|
||||
const { createReadStream } = require('fs')
|
||||
const split = require('split2')
|
||||
|
||||
const pipeline = promisify(stream.pipeline)
|
||||
const { Writable } = stream
|
||||
|
||||
const { pid } = process
|
||||
const hostname = os.hostname()
|
||||
@ -478,3 +485,25 @@ test('transport options with target and stream', async ({ fail, equal }) => {
|
||||
equal(err.message, 'only one of option.transport or stream can be specified')
|
||||
}
|
||||
})
|
||||
|
||||
test('eight million lines', async ({ equal, comment }) => {
|
||||
const destination = join(
|
||||
os.tmpdir(),
|
||||
'_' + Math.random().toString(36).substr(2, 9)
|
||||
)
|
||||
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'transport-many-lines.js'), destination])
|
||||
|
||||
await once(child, 'exit')
|
||||
const toWrite = 8 * 1000000
|
||||
let count = 0
|
||||
await pipeline(createReadStream(destination), split(), new Writable({
|
||||
write (chunk, enc, cb) {
|
||||
if (count % (toWrite / 10) === 0) {
|
||||
comment(`read ${count}`)
|
||||
}
|
||||
count++
|
||||
cb()
|
||||
}
|
||||
}))
|
||||
equal(count, toWrite)
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user