Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

file-timestamp-stream

Package Overview
Dependencies
3
Maintainers
1
Versions
25
Issues
File Explorer

Advanced tools

file-timestamp-stream

Writing stream with file rotating based on timestamp

    2.2.4latest

Version published
Maintainers
1
Yearly downloads
9,128
decreased by-4.54%

Weekly downloads

Changelog

Source

v2.2.4 2019-10-07

  • Compatible with newer NodeJS typings.
  • Use mocha-steps for testing.
  • Updated dependencies.

Readme

Source

file-timestamp-stream

Build Status Coverage Status npm

This module creates stream.Writable to a file which is automatically rotated based on current time and uses strftime template for file names.

Requirements

This module requires ES6 with Node >= 6.

Installation

npm install file-timestamp-stream

Additionally for Typescript:

npm install -D @types/node

Usage

Example:

const {FileTimestampStream} = require("file-timestamp-stream")

Typescript:

import FileTimestampStream from "file-timestamp-stream" // or import {FileTimestampStream} from "file-timestamp-stream"

Options

  • 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", })

newFilename

This method can be overriden in subclass.

The method generates a filename for new files. By default it returns new filename based on path and current time.

Example:

import strftime from "ultra-strftime" class MyFileTimestampStream extends FileTimestampStream { /** count how many files has been created */ counter = 0 // for pure Javascript explicit constructor is necessary // constructor (options) { super(options); this.counter = 0 } protected newFilename(): string { const filename = strftime(this.path) if (filename !== this.currentFilename) this.counter++ return filename } } const stream = new MyFileTimestampStream({ path: "%Y-%m-%dT%H:%M.log", })

Properties

Readonly public properties based on contructor's options:

  • flags
  • fs
  • path

Protected properties for custom subclass:

  • currentFilename contains last opened filename
  • stream contains current fs.WriteStream object

Path template format

Path can contain strftime specifiers.

Warning

This stream have to be closed to free own streams and timers.

License

Copyright (c) 2017-2019 Piotr Roszatycki [email protected]

MIT

Keywords

Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc