-
-
Save tkurki/3eb2fc0ce563985c57952b5a52ef5424 to your computer and use it in GitHub Desktop.
Rotate minute interval test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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