Skip to content

Instantly share code, notes, and snippets.

@tkurki
Created September 17, 2017 09:30
Show Gist options
  • Save tkurki/3eb2fc0ce563985c57952b5a52ef5424 to your computer and use it in GitHub Desktop.
Save tkurki/3eb2fc0ce563985c57952b5a52ef5424 to your computer and use it in GitHub Desktop.
Rotate minute interval test
const rfs = require('rotating-file-stream')
const filenameGenerator = (timeParam, index) => {
if (!timeParam) {
return 'current.log'
}
const time = timeParam || new Date()
const year = time.getFullYear()
const month = pad(time.getMonth() + 1)
const day = pad(time.getDate())
const hour = pad(time.getHours())
const minute = pad(time.getMinutes())
const result = `test.${year}-${month}-${day}T${hour}${minute}`
console.log(result)
return result
}
const stream = new rfs(filenameGenerator, {
path: '/tmp/',
interval: '1m'
})
stream.on('rotation', _ => {
console.log('rotation')
})
stream.on('rotated', filename => {
console.log('rotated ' + filename)
})
stream.on('error', error => {
console.log(error)
})
setInterval(_ => {
console.log(new Date())
stream.write(new Date() + '\n')
}, 5 * 1000)
function pad (num) {
return (num > 9 ? '' : '0') + num
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment