file-timestamp-stream
This module creates
stream.Writable
to a file which is automatically rotated based on current time.
Requirements
This module requires ES6 with Node >= 6.
Installation
npm install file-timestamp-stream
Additionally for Typescript:
npm install -D @types/node
Transpiling this module with own settings in tsconfig.json
:
{
"compilerOptions": {
"paths": {
"file-timestamp-stream": ["node_modules/file-timestamp-stream/src/file-timestamp-stream"]
}
}
}
Usage
Example:
const { FileTimestampStream } = require('file-timestamp-stream')
Typescript:
import FileTimestampStream from 'file-timestamp-stream'
Options
newFilename
is a custom function with this object as an only argument which
returns new filename (default: returns new filename based on path and current
time)flags
is a string with
flags
for opened stream (default: 'a'
)fs
is a custom fs module (optional)path
is a template for new filenames (default: 'out.log'
)
Example:
Basic path based on strftime
parameters:
const stream = new FileTimestampStream({
path: '%Y-%m-%dT%H.log',
flags: 'a'
})
Custom filename generator:
const strftime = require('ultra-strftime')
let counter = 0
const stream = new FileTimestampStream({
path: '%Y-%m-%dT%H:%M.log',
newFilename
})
function newFilename (fileTimestampStream) {
const filename = strftime(fileTimestampStream.path)
if (filename !== fileTimestampStream.currentFilename) counter++
return filename
}
Properties
currentFilename
contains last opened filenamestream
contains
fs.WriteStream
object
Path template format
Path can contain strftime specifiers.
License
Copyright (c) 2017-2018 Piotr Roszatycki piotr.roszatycki@gmail.com
MIT