{"name":"rotating-file-stream","version":"3.2.7","keywords":["log","rotate","logrotate"],"author":{"url":"https://github.com/iccicci","name":"Daniele Ricci","email":"daniele.icc@gmail.com"},"license":"MIT","_id":"rotating-file-stream@3.2.7","maintainers":[{"name":"cicci","email":"daniele.icc@gmail.com"},{"name":"allevo","email":"tomallevi@gmail.com"}],"contributors":[{"url":"https://www.trinityteam.it/DanieleRicci#en","name":"cicci"},{"name":"allevo"},{"name":"kbirger"},{"name":"jvassev"},{"name":"wangao"},{"name":"rakshith-ravi"},{"name":"Jorge Silva","email":"jorgemsrs@gmail.com"},{"name":"Jan Christoph Bernack","email":"jc.bernack@gmail.com"},{"url":"https://github.com/cchare","name":"cchare"}],"homepage":"https://github.com/iccicci/rotating-file-stream#readme","bugs":{"url":"https://github.com/iccicci/rotating-file-stream/issues"},"dist":{"shasum":"db41fce36d0a10de3e27f028aa8d5f587f1ca916","tarball":"http://registry-npm.ywwl.com/rotating-file-stream/download/rotating-file-stream-3.2.7.tgz","fileCount":7,"integrity":"sha512-SVquhBEVvRFY+nWLUc791Y0MIlyZrEClRZwZFLLRgJKldHyV1z4e2e/dp9LPqCS3AM//uq/c3PnOFgjqnm5P+A==","signatures":[{"sig":"MEQCIF3sN5aiIfKKZSMsRUc2oKtycjfmGnfAVWxiGkrMxdGOAiAsfejrYiv5nHbkRwY/OWQiWbWwSDIixdEBTwpNBchjzg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":75287,"size":14743,"noattachment":false,"key":"/rotating-file-stream/-/rotating-file-stream-3.2.7.tgz"},"main":"./dist/cjs/index.js","type":"module","types":"./dist/types/index.d.ts","module":"./dist/esm/index.js","engines":{"node":">=14.0"},"exports":{".":{"types":"./dist/types/index.d.ts","import":"./dist/esm/index.js","require":"./dist/cjs/index.js"}},"funding":{"url":"https://www.blockchain.com/btc/address/12p1p5q7sK75tPyuesZmssiMYr4TKzpSCN"},"gitHead":"0d66ed954e9fbcbedc4eb60fcddf6cf8b0732dc3","scripts":{"all":"yarn eslint && yarn coverage","test":"rm -rf dist && TZ=Europe/Rome jest --runInBand","eslint":"eslint index.ts utils.ts test/*ts","ignore":"tsx utils ignore","prepare":"npm run ignore && tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.types.json","coverage":"rm -rf dist && TZ=Europe/Rome jest --coverage --runInBand"},"_npmUser":{"name":"cicci","email":"daniele.icc@gmail.com"},"prettier":{"printWidth":200,"arrowParens":"avoid","trailingComma":"none","jsxBracketSameLine":true},"repository":{"url":"git+https://github.com/iccicci/rotating-file-stream.git","type":"git"},"_npmVersion":"10.2.3","description":"Opens a stream.Writable to a file rotated by interval and/or size. A logrotate alternative.","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"tsx":"4.19.2","jest":"29.7.0","eslint":"8.56.0","ts-jest":"29.2.5","prettier":"3.5.0","typescript":"5.7.3","@types/jest":"29.5.14","@types/node":"22.13.1","eslint-plugin-sort-keys":"2.3.5","@typescript-eslint/parser":"6.16.0","@typescript-eslint/eslint-plugin":"6.16.0","jest-environment-node-single-context":"29.4.0"},"_npmOperationalInternal":{"tmp":"tmp/rotating-file-stream_3.2.7_1756088127084_0.8344432922854577","host":"s3://npm-registry-packages-npm-production"},"readme":"# rotating-file-stream\n\n[![Build Status][travis-badge]][travis-url]\n[![Code Climate][code-badge]][code-url]\n[![Test Coverage][cover-badge]][code-url]\n\n[![NPM version][npm-badge]][npm-url]\n[![NPM downloads][npm-downloads-badge]][npm-url]\n[![Stars][stars-badge]][stars-url]\n\n[![Types][types-badge]][npm-url]\n[![Dependents][deps-badge]][npm-url]\n[![Donate][donate-badge]][donate-url]\n\n[code-badge]: https://codeclimate.com/github/iccicci/rotating-file-stream/badges/gpa.svg\n[code-url]: https://codeclimate.com/github/iccicci/rotating-file-stream\n[cover-badge]: https://codeclimate.com/github/iccicci/rotating-file-stream/badges/coverage.svg\n[deps-badge]: https://img.shields.io/librariesio/dependents/npm/rotating-file-stream?logo=npm\n[deps-url]: https://www.npmjs.com/package/rotating-file-stream?activeTab=dependents\n[donate-badge]: https://img.shields.io/static/v1?label=donate&message=bitcoin&color=blue&logo=bitcoin\n[donate-url]: https://blockchain.info/address/12p1p5q7sK75tPyuesZmssiMYr4TKzpSCN\n[github-url]: https://github.com/iccicci/rotating-file-stream\n[npm-downloads-badge]: https://img.shields.io/npm/dw/rotating-file-stream?logo=npm\n[npm-badge]: https://img.shields.io/npm/v/rotating-file-stream?color=green&logo=npm\n[npm-url]: https://www.npmjs.com/package/rotating-file-stream\n[stars-badge]: https://img.shields.io/github/stars/iccicci/rotating-file-stream?logo=github&style=flat&color=green\n[stars-url]: https://github.com/iccicci/rotating-file-stream/stargazers\n[travis-badge]: https://img.shields.io/travis/com/iccicci/rotating-file-stream?logo=travis\n[travis-url]: https://app.travis-ci.com/github/iccicci/rotating-file-stream\n[types-badge]: https://img.shields.io/static/v1?label=types&message=included&color=green&logo=typescript\n\n### Description\n\nCreates a [stream.Writable](https://nodejs.org/api/stream.html#stream_class_stream_writable) to a file which is\nrotated. Rotation behavior can be deeply customized; optionally, classical UNIX **logrotate** behavior can be used.\n\n### Usage\n\n```javascript\nimport { createStream } from \"rotating-file-stream\";\n\nconst stream = createStream(\"file.log\", {\n  size: \"10M\", // rotate every 10 MegaBytes written\n  interval: \"1d\", // rotate daily\n  compress: \"gzip\" // compress rotated files\n});\n```\n\n### Installation\n\nWith [npm](https://www.npmjs.com/package/rotating-file-stream):\n\n```sh\n$ npm install --save rotating-file-stream\n```\n\n### Table of contents\n\n- [Upgrading from v2 to v3](#upgrading-from-v2-to-v3)\n- [Upgrading from v1 to v2](#upgrading-from-v1-to-v2)\n- [API](#api)\n  - [rfs.createStream(filename[, options])](#rfscreatestreamfilename-options)\n    - [filename](#filename)\n      - [filename(time[, index])](#filenametime-index)\n      - [filename(index)](#filenameindex)\n  - [Class: RotatingFileStream](#class-rotatingfilestream)\n    - [Event: 'external'](#event-external)\n    - [Event: 'history'](#event-history)\n    - [Event: 'open'](#event-open)\n    - [Event: 'removed'](#event-removed)\n    - [Event: 'rotation'](#event-rotation)\n    - [Event: 'rotated'](#event-rotated)\n    - [Event: 'warning'](#event-warning)\n  - [options](#options)\n    - [compress](#compress)\n    - [encoding](#encoding)\n    - [history](#history)\n    - [immutable](#immutable)\n    - [initialRotation](#initialrotation)\n    - [interval](#interval)\n    - [intervalBoundary](#intervalboundary)\n    - [intervalUTC](#intervalutc)\n    - [maxFiles](#maxfiles)\n    - [maxSize](#maxsize)\n    - [mode](#mode)\n    - [omitExtension](#omitextension)\n    - [path](#path)\n    - [rotate](#rotate)\n    - [size](#size)\n    - [teeToStdout](#teeToStdout)\n- [Rotation logic](#rotation-logic)\n- [Under the hood](#under-the-hood)\n- [Compatibility](#compatibility)\n- [TypeScript](#typescript)\n- [License](#license)\n- [Bugs](#bugs)\n- [ChangeLog](#changelog)\n- [Donating](#donating)\n\n# Upgrading from v2 to v3\n\nIn **v3** the package was completely refactored using **async / await**.\n\n**TypeScript** types for events and the [external](#event-external) event were added.\n\n**Breaking change**: by default the `.gz` extension is added to the rotated compressed files.\n\n**Breaking change**: the way the _external compression command_ is executed was slightly changed; possible breaking\nchange.\n\nTo maintain back compatibility upgrading from **v2** to **v3**, just follow this rules:\n\n- using a _file name generator_ or not using [`options.compress`](#compress): nothing to do\n- using a _file name_ and using [`options.compress`](#compress): use [`options.omitExtension`](#omitextension) or check\n  how rotated files are treated.\n\n# Upgrading from v1 to v2\n\nThere are two main changes in package interface.\n\nIn **v1** the _default export_ of the package was directly the **RotatingFileStream** _constructor_ and the caller\nhave to use it; while in **v2** there is no _default export_ and the caller should use the\n[createStream](#rfscreatestreamfilename-options) exported function and should not directly use\n[RotatingFileStream](#class-rotatingfilestream) class.\nThis is quite easy to discover: if this change is not applied, nothing than a runtime error can happen.\n\nThe other important change is the removal of option **rotationTime** and the introduction of **intervalBoundary**.\nIn **v1** the `time` argument passed to the _filename generator_ function, by default, is the time when _rotation job_\nstarted, while if [`options.interval`](#interval) option is used, it is the lower boundary of the time interval within\n_rotation job_ started. Later I was asked to add the possibility to restore the default value for this argument so I\nintroduced `options.rotationTime` option with this purpose. At the end the result was something a bit confusing,\nsomething I never liked.\nIn **v2** the `time` argument passed to the _filename generator_ function is always the time when _rotation job_\nstarted, unless [`options.intervalBoundary`](#intervalboundary) option is used. In a few words, to maintain back\ncompatibility upgrading from **v1** to **v2**, just follow this rules:\n\n- using [`options.rotation`](#rotation): nothing to do\n- not using [`options.rotation`](#rotation):\n  - not using [`options.interval`](#interval): nothing to do\n  - using [`options.interval`](#interval):\n    - using `options.rotationTime`: to remove it\n    - not using `options.rotationTime`: then use [`options.intervalBoundary`](#intervalboundary).\n\n# API\n\n```javascript\nconst rfs = require(\"rotating-file-stream\");\n```\n\n## rfs.createStream(filename[, options])\n\n- `filename` [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) |\n  [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) The name\n  of the file or the function to generate it, called _file name generator_. See below for\n  [details](#filename-stringfunction).\n- `options` [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)\n  Rotation options, See below for [details](#options).\n- Returns: [&lt;RotatingFileStream>](#class-rotatingfilestream) The **rotating file stream**!\n\nThis interface is inspired to\n[fs.createWriteStream](https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options) one. The file is rotated\nfollowing _options_ rules.\n\n### filename\n\nThe most complex problem about file name is: _how to call the rotated file name?_\n\nThe answer to this question may vary in many forms depending on application requirements and/or specifications.\nIf there are no requirements, a `string` can be used and _default rotated file name generator_ will be used;\notherwise a `Function` which returns the _rotated file name_ can be used.\n\n**Note:**\nif part of returned destination path does not exists, the rotation job will try to create it.\n\n#### filename(time[, index])\n\n- `time` [&lt;Date>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)\n  - By default: the time when rotation job started;\n  - if both [`options.interval`](#interval) and [`intervalBoundary`](#intervalboundary) options are enabled: the start\n    time of rotation period.\n\n  If `null`, the _not-rotated file name_ must be returned.\n\n- `index` [&lt;number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The\n  progressive index of rotation by size in the same rotation period.\n\nAn example of a complex _rotated file name generator_ function could be:\n\n```javascript\nconst pad = num => (num > 9 ? \"\" : \"0\") + num;\nconst generator = (time, index) => {\n  if (!time) return \"file.log\";\n\n  var month = time.getFullYear() + \"\" + pad(time.getMonth() + 1);\n  var day = pad(time.getDate());\n  var hour = pad(time.getHours());\n  var minute = pad(time.getMinutes());\n\n  return `${month}/${month}${day}-${hour}${minute}-${index}-file.log`;\n};\n\nconst rfs = require(\"rotating-file-stream\");\nconst stream = rfs.createStream(generator, {\n  size: \"10M\",\n  interval: \"30m\"\n});\n```\n\n**Note:**\nif both of [`options.interval`](#interval) [`options.size`](#size) are used, returned _rotated file name_ **must** be\nfunction of both arguments `time` and `index`.\n\n#### filename(index)\n\n- `index` [&lt;number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The\n  progressive index of rotation. If `null`, the _not-rotated file name_ must be returned.\n\nIf classical **logrotate** behavior is enabled (by [`options.rotate`](#rotate)), _rotated file name_ is only a\nfunction of `index`.\n\n## Class: RotatingFileStream\n\nExtends [stream.Writable](https://nodejs.org/api/stream.html#stream_class_stream_writable). It should not be directly\nused. Exported only to be used with `instanceof` operator and similar.\n\n`RotatingFileStream` emits all events emitted by `stream.Writable` plus the ones described below.\n\n### Event: 'external'\n\n- `stdout` [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The\n  standard output of the external compression command.\n- `stderr` [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The\n  standard error of the external compression command.\n\nThe `external` event is emitted once an _external compression command_ completes its execution to give access to the\ncommand output streams.\n\n### Event: 'history'\n\nThe `history` event is emitted once the _history check job_ is completed.\n\n### Event: 'open'\n\n- `filename` [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Is\n  constant unless [`options.immutable`](#immutable) is `true`.\n\nThe `open` event is emitted once the _not-rotated file_ is opened.\n\n### Event: 'removed'\n\n- `filename` [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The\n  name of the removed file.\n- `number` [&lt;boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)\n  - `true` if the file was removed due to [`options.maxFiles`](#maxFiles)\n  - `false` if the file was removed due to [`options.maxSize`](#maxSize)\n\nThe `removed` event is emitted once a _rotated file_ is removed due to [`options.maxFiles`](#maxFiles) or\n[`options.maxSize`](#maxSize).\n\n### Event: 'rotation'\n\nThe `rotation` event is emitted once the _rotation job_ is started.\n\n### Event: 'rotated'\n\n- `filename` [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The\n  _rotated file name_ produced.\n\nThe `rotated` event is emitted once the _rotation job_ is completed.\n\n### Event: 'warning'\n\n- `error` [&lt;Error>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) The\n  non blocking error.\n\nThe `warning` event is emitted once a non blocking error happens.\n\n## options\n\n- [`compress`](#compress):\n  [&lt;boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) |\n  [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) |\n  [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)\n  Specifies compression method of rotated files. **Default:** `null`.\n- [`encoding`](#encoding):\n  [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)\n  Specifies the default encoding. **Default:** `'utf8'`.\n- [`history`](#history):\n  [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)\n  Specifies the _history filename_. **Default:** `null`.\n- [`immutable`](#immutable):\n  [&lt;boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)\n  Never mutate file names. **Default:** `null`.\n- [`initialRotation`](#initialRotation):\n  [&lt;boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)\n  Initial rotation based on _not-rotated file_ timestamp. **Default:** `null`.\n- [`interval`](#interval):\n  [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)\n  Specifies the time interval to rotate the file. **Default:** `null`.\n- [`intervalBoundary`](#intervalBoundary):\n  [&lt;boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)\n  Makes rotated file name with lower boundary of rotation period. **Default:** `null`.\n- [`intervalUTC`](#intervalutc):\n  [&lt;boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)\n  Boundaries for rotation are computed in UTC. **Default:** `null`.\n- [`maxFiles`](#maxFiles):\n  [&lt;number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)\n  Specifies the maximum number of rotated files to keep. **Default:** `null`.\n- [`maxSize`](#maxSize):\n  [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)\n  Specifies the maximum size of rotated files to keep. **Default:** `null`.\n- [`mode`](#mode):\n  [&lt;number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)\n  Forwarded to [fs.createWriteStream](https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options).\n  **Default:** `0o666`.\n- [`omitExtension`](#omitextension):\n  [&lt;boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)\n  Omits the `.gz` extension from compressed rotated files. **Default:** `null`.\n- [`path`](#path):\n  [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)\n  Specifies the base path for files. **Default:** `null`.\n- [`rotate`](#rotate):\n  [&lt;number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)\n  Enables the classical UNIX **logrotate** behavior. **Default:** `null`.\n- [`size`](#size):\n  [&lt;string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)\n  Specifies the file size to rotate the file. **Default:** `null`.\n- [`teeToStdout`](#teeToStdout):\n  [&lt;boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)\n  Writes file content to `stdout` as well. **Default:** `null`.\n\n### encoding\n\nSpecifies the default encoding that is used when no encoding is specified as an argument to\n[stream.write()](https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback).\n\n### mode\n\nForwarded to [fs.createWriteStream](https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options).\n\n### path\n\nIf present, it is prepended to generated file names as well as for history file.\n\n### teeToStdout\n\nIf `true`, it makes the file content to be written to `stdout` as well. Useful for debugging purposes.\n\n### size\n\nAccepts a positive integer followed by one of these possible letters:\n\n- **B**: Bites\n- **K**: KiloBites\n- **M**: MegaBytes\n- **G**: GigaBytes\n\n```javascript\n  size: '300B', // rotates the file when size exceeds 300 Bytes\n                // useful for tests\n```\n\n```javascript\n  size: '300K', // rotates the file when size exceeds 300 KiloBytes\n```\n\n```javascript\n  size: '100M', // rotates the file when size exceeds 100 MegaBytes\n```\n\n```javascript\n  size: '1G', // rotates the file when size exceeds a GigaByte\n```\n\n### interval\n\nAccepts a positive integer followed by one of these possible letters:\n\n- **s**: seconds. Accepts integer divider of 60.\n- **m**: minutes. Accepts integer divider of 60.\n- **h**: hours. Accepts integer divider of 24.\n- **d**: days. Accepts integer.\n- **M**: months. Accepts integer. **EXPERIMENTAL**\n\n```javascript\n  interval: '5s', // rotates at seconds 0, 5, 10, 15 and so on\n                  // useful for tests\n```\n\n```javascript\n  interval: '5m', // rotates at minutes 0, 5, 10, 15 and so on\n```\n\n```javascript\n  interval: '2h', // rotates at midnight, 02:00, 04:00 and so on\n```\n\n```javascript\n  interval: '1d', // rotates at every midnight\n```\n\n```javascript\n  interval: '1M', // rotates at every midnight between two distinct months\n```\n\n### intervalBoundary\n\nIf set to `true`, the argument `time` of _filename generator_ is no longer the time when _rotation job_ started, but\nthe _lower boundary_ of rotation interval.\n\n**Note:**\nthis option has effect only if [`options.interval`](#interval) is used.\n\n### intervalUTC\n\nIf set to `true`, the boundaries of the rotation interval are computed against UTC time rather than against system time\nzone.\n\n**Note:**\nthis option has effect only if [`options.intervalBoundary`](#intervalboundary) is used.\n\n### compress\n\nThe best choice here is to use the value `\"gzip\"` to use **Node.js** internal compression library.\n\nFor historical reasons external compression can be used.\n\nTo enable external compression, a _function_ can be used or simply the _boolean_ `true` value to use default\nexternal compression.\nThe function should accept `source` and `dest` file names and must return the shell command to be executed to\ncompress the file.\nThe two following code snippets have exactly the same effect:\n\n```javascript\nvar rfs = require(\"rotating-file-stream\");\nvar stream = rfs.createStream(\"file.log\", {\n  size: \"10M\",\n  compress: true\n});\n```\n\n```javascript\nvar rfs = require(\"rotating-file-stream\");\nvar stream = rfs.createStream(\"file.log\", {\n  size: \"10M\",\n  compress: (source, dest) => `cat ${source} | gzip -c9 > ${dest}`\n});\n```\n\n**Note:**\nthis option is ignored if [`options.immutable`](#immutable) is used.\n\n**Note:**\nthe shell command to compress the rotated file should not remove the source file, it will be removed by the package\nif rotation job complete with success.\n\n### omitExtension\n\nFrom **v3** the package adds by default the `.gz` extension to the rotated compressed files. Simultaneously this option\nwas added: set this option to `true` to not add the extension, i.e. to keep backward compatibility.\n\n### initialRotation\n\nWhen program stops in a rotation period then restarts in a new rotation period, logs of different rotation period will\ngo in the next rotated file; in a few words: a rotation job is lost. If this option is set to `true` an initial check\nis performed against the _not-rotated file_ timestamp and, if it falls in a previous rotation period, an initial\nrotation job is done as well.\n\n**Note:**\nthis option has effect only if both [`options.interval`](#interval) and [`options.intervalBoundary`](#intervalboundary)\nare used.\n\n**Note:**\nthis option is ignored if [`options.rotate`](#rotate) is used.\n\n### rotate\n\nIf specified, classical UNIX **logrotate** behavior is enabled and the value of this option has same effect in\n_logrotate.conf_ file.\n\n**Note:**\nif this option is used following ones take no effect: [`options.history`](#history), [`options.immutable`](#immutable),\n[`options.initialRotation`](#initialrotation), [`options.intervalBoundary`](#intervalboundary),\n[`options.maxFiles`](#maxfiles), [`options.maxSize`](#maxsize).\n\n### immutable\n\nIf set to `true`, names of generated files never changes. New files are immediately generated with their rotated\nname. In other words the _rotated file name generator_ is never called with a `null` _time_ argument unless to\ndeterminate the _history file_ name; this can happen if [`options.history`](#history) is not used while\n[`options.maxFiles`](#maxfiles) or [`options.maxSize`](#maxsize) are used.\nThe `filename` argument passed to [`'open'`](#event-open) _event_ evaluates now as the newly created file name.\n\nUseful to send logs to logstash through [filebeat](https://www.elastic.co/beats/filebeat).\n\n**Note:**\nif this option is used, [`options.compress`](#compress) is ignored.\n\n**Note:**\nthis option is ignored if [`options.interval`](#interval) is not used.\n\n### history\n\nDue to the complexity that _rotated file names_ can have because of the _filename generator function_, if number or\nsize of rotated files should not exceed a given limit, the package needs a file where to store this information. This\noption specifies the name _history file_. This option takes effect only if at least one of\n[`options.maxFiles`](#maxfiles) or [`options.maxSize`](#maxsize) is used. If `null`, the _not rotated filename_ with\nthe `'.txt'` suffix is used.\n\n### maxFiles\n\nIf specified, it's value is the maximum number of _rotated files_ to be kept.\n\n### maxSize\n\nIf specified, it's value must respect same syntax of [option.size](#size) and is the maximum size of _rotated files_ to\nbe kept.\n\n# Rotation logic\n\nRegardless of when and why rotation happens, the content of a single\n[stream.write](https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback)\nwill never be split among two files.\n\n## by size\n\nOnce the _not-rotated_ file is opened first time, its size is checked and if it is greater or equal to\nsize limit, a first rotation happens. After each\n[stream.write](https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback),\nthe same check is performed.\n\n## by interval\n\nThe package sets a [Timeout](https://nodejs.org/api/timers.html#timers_settimeout_callback_delay_args)\nto start a rotation job at the right moment.\n\n# Under the hood\n\nLogs should be handled so carefully, so this package tries to never overwrite files.\n\nAt stream creation, if the _not-rotated_ log file already exists and its size exceeds the rotation size,\nan initial rotation attempt is done.\n\nAt each rotation attempt a check is done to verify that destination rotated file does not exists yet;\nif this is not the case a new destination _rotated file name_ is generated and the same check is\nperformed before going on. This is repeated until a not existing destination file name is found or the\npackage is exhausted. For this reason the _rotated file name generator_ function could be called several\ntimes for each rotation job.\n\nIf requested through [`options.maxFiles`](#maxfiles) or [`options.maxSize`](#maxsize), at the end of a rotation job, a\ncheck is performed to ensure that given limits are respected. This means that\n**while rotation job is running both the limits could be not respected**. The same can happen till the end of first\n_rotation job_ if [`options.maxFiles`](#maxfiles) or [`options.maxSize`](#maxsize) are changed between two runs.\nThe first check performed is the one against [`options.maxFiles`](#maxfiles), in case some files are removed, then the\ncheck against [`options.maxSize`](#maxsize) is performed, finally other files can be removed. When\n[`options.maxFiles`](#maxfiles) or [`options.maxSize`](#maxsize) are enabled for first time, an _history file_ can be\ncreated with one _rotated filename_ (as returned by _filename generator function_) at each line.\n\nOnce an **error** _event_ is emitted, nothing more can be done: the stream is closed as well.\n\n# Compatibility\n\nRequires **Node.js v14**.\n\nThe package is tested under [all Node.js versions](https://app.travis-ci.com/github/iccicci/rotating-file-stream)\ncurrently supported accordingly to [Node.js Release](https://github.com/nodejs/Release#readme).\n\nTo work with the package under Windows, be sure to configure `bash.exe` as your _script-shell_.\n\n```\n> npm config set script-shell bash.exe\n```\n\n# TypeScript\n\n**TypeScript** types are distributed with the package itself.\n\n# License\n\n[MIT License](https://github.com/iccicci/rotating-file-stream/blob/master/LICENSE)\n\n# Bugs\n\nDo not hesitate to report any bug or inconsistency [@github](https://github.com/iccicci/rotating-file-stream/issues).\n\n# ChangeLog\n\n[ChangeLog](https://github.com/iccicci/rotating-file-stream/blob/master/CHANGELOG.md)\n\n# Donating\n\nIf you find useful this package, please consider the opportunity to donate some satoshis to this bitcoin address:\n**12p1p5q7sK75tPyuesZmssiMYr4TKzpSCN**\n","publish_time":1756088127276,"_cnpm_publish_time":1756088127276,"dist-tags":{"latest":"3.2.10"}}