Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

506
Views
Node.js / Pino.js: How to rotate logs in a separate thread

I am trying to use pino for logging in to my node app Server and I do have some large logs coming, so rotating the files every day would be more practical.

So I used pino.multistream() and require('file-stream-rotator')

My code works, but for performance reasons, I would not like to use the streams in the main thread.

according to the doc, I should use pino.transport():

[pino.multistream()] differs from pino.transport() as all the streams will be executed within the main thread, i.e. the one that created the pino instance. https://github.com/pinojs/pino/releases?page=2

However, I can't manage to combine pino.transport() and file-stream-rotator.

my code that does not work completely -> logs the first entries, but is not exportable because it blocks the script with the error

throw new Error('the worker has exited')

Main file

const pino = require('pino')

const transport = pino.transport({
  target: './custom-transport.js'
})

const logger = pino(transport)
logger.level = 'info'

logger.info('Pino: Start Service Logging...')

module.exports = {
  logger
}

custom-transport.js file

const { once } = require('events')
const fileStreamRotator = require('file-stream-rotator')

const customTransport = async () => {
  const stream = fileStreamRotator.getStream({ filename: 'myfolder/custom-logger.log', frequency: 'daily' })
  await once(stream, 'open')
  return stream
}

module.exports = customTransport
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!