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

154
Views
WinstonJS Rotate files when they are oversized using timestamp or indexes in filename

I have a task - to rotate logfile when its size is over 2M Logfilename must be 'log_unixtimestamp.log' or 'log_number.log'

I tried to code it using both transports.File and transports.DailyRotateFile

My best result - Every time log is written the new logfile with actual timestamp is created

my code

const fileTransport = transports.DailyRotateFile({
  format: format.combine(/*...*/),
  maxSize: '2m',
  maxFiles: 3,
  fileName: 'logs/log_%DATE%.log',
  datePattern: 'X',
  createSymlink: true,
  symlinkName: 'logs/log_%DATE%.log'
  close: false,
})

result:

/logs
.../log_1635758863.log //1 KB
.../log_1635758865.log //1 KB
.../log_1635758870.log //1 KB

Also I've tried to use dynamic filename but it does not update in runtime

const generateTimestamp = Math.round(new Date().getTime() / 1000)

const fileTransport = transports.DailyRotateFile({
  format: format.combine(/*...*/),
  maxSize: '2m',
  maxFiles: 3,
  fileName: `logs/log%DATE%${generateTimestamp()}.log`,
  datePattern: '_',
  createSymlink: true,
  symlinkName: `logs/log%DATE%${generateTimestamp()}.log`
  close: false,
})

result

/logs
.../log_1635758880.log //2 MB
.../log_1635758880.log.1 //2 MB
.../log_1635758880.log.2 //2 MB

This code did not help me

fileTransport.on('new' /*the same with 'rotate'*/, () => {
  fileTransport.fileName =`logs/log%DATE%${generateTimestamp()}.log`;
  fileTransport.symlinkName=`logs/log%DATE%${generateTimestamp()}.log`;
});
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!