{"_id":"@bebrasmell/mono-logger-writer","_rev":"3-64dc8169337a59abd7c53e8f16ef7156","name":"@bebrasmell/mono-logger-writer","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@bebrasmell/mono-logger-writer","version":"1.0.0","keywords":["logs","logger","console","topic"],"author":{"name":"Zak","email":"137602160+bebrasmell@users.noreply.github.com"},"license":"MIT","_id":"@bebrasmell/mono-logger-writer@1.0.0","maintainers":[{"name":"bebrasmell","email":"zakofpl@gmail.com"}],"dist":{"shasum":"faecc8e82ae6b546ee4241e39b5f0330c36399ff","tarball":"https://registry.npmjs.org/@bebrasmell/mono-logger-writer/-/mono-logger-writer-1.0.0.tgz","fileCount":13,"integrity":"sha512-rb4cEbGqTDAzi4dC8JUjGV8ix6JEhwHTsBUeKJ0a4xRhFgGtbYOsH6Nf8n46ozP8KYCag7Ytbhg1RlLkJVjCbg==","signatures":[{"sig":"MEUCIEeRr0XkRiiVhiiXKhrdpTe60B8L/gFD0q+HfAocr/pcAiEAngi1KL/D+za0BxFrj1mLkIjDdIAuTTlbcxJ15xpALio=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":69226},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"private":false,"scripts":{"lint":"biome check","test":"jest","build":"tsup","lint:fix":"biome check --write .","test:run":"node test.js"},"typings":"./dist/index.d.ts","_npmUser":{"name":"bebrasmell","email":"zakofpl@gmail.com"},"repository":{"url":"https://github.com/bebrasmell/mono-logger-writer.git","type":"git"},"description":"File writing extension for Mono-logger","directories":{},"dependencies":{"@bebrasmell/mono-logger":"^1.5.4"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tsup":"^8.2.3","@swc/core":"^1.7.2","@swc/jest":"^0.2.36","typescript":"^5.5.4","@types/jest":"^29.5.12","@biomejs/biome":"^1.8.3"},"_npmOperationalInternal":{"tmp":"tmp/mono-logger-writer_1.0.0_1722262619138_0.6676398492775506","host":"s3://npm-registry-packages"},"deprecated":"Please use @zodyac/mono-logger-writer instead."},"1.1.0":{"name":"@bebrasmell/mono-logger-writer","version":"1.1.0","keywords":["logs","logger","console","topic"],"author":{"name":"Zak","email":"137602160+bebrasmell@users.noreply.github.com"},"license":"MIT","_id":"@bebrasmell/mono-logger-writer@1.1.0","maintainers":[{"name":"bebrasmell","email":"zakofpl@gmail.com"}],"dist":{"shasum":"4d07ed31fc7ee7c6e4214c89416499e8582446d2","tarball":"https://registry.npmjs.org/@bebrasmell/mono-logger-writer/-/mono-logger-writer-1.1.0.tgz","fileCount":13,"integrity":"sha512-4r+hpLN7LZLV4mqYiDT9LD4AWRFmsTd4uI0itWuQVlvFXLrMgX8hjIQtsG8JpJunTX4T8SnHC+kpOhnMLkwFYg==","signatures":[{"sig":"MEUCIQC5rvdaYOIQLSss+cgF+R0C4Y0to4KfmQpL6et4TPta5QIgL6AXSq/BeJOwnlbUnseaKyF884vNRTYBF4DJVUUiJFg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":78109},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"private":false,"scripts":{"lint":"biome check","test":"jest","build":"tsup","lint:fix":"biome check --write .","test:run":"node test.js"},"typings":"./dist/index.d.ts","_npmUser":{"name":"bebrasmell","email":"zakofpl@gmail.com"},"repository":{"url":"https://github.com/bebrasmell/mono-logger-writer.git","type":"git"},"description":"File writing extension for Mono-logger","directories":{},"dependencies":{"@bebrasmell/mono-logger":"^1.5.4"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tsup":"^8.2.3","@swc/core":"^1.7.2","@swc/jest":"^0.2.36","typescript":"^5.5.4","@types/jest":"^29.5.12","@biomejs/biome":"^1.8.3"},"_npmOperationalInternal":{"tmp":"tmp/mono-logger-writer_1.1.0_1722267237519_0.1730375276696694","host":"s3://npm-registry-packages"},"deprecated":"Please use @zodyac/mono-logger-writer instead."},"1.2.0":{"name":"@bebrasmell/mono-logger-writer","version":"1.2.0","keywords":["logs","logger","console","topic"],"author":{"name":"Zak","email":"137602160+bebrasmell@users.noreply.github.com"},"license":"MIT","_id":"@bebrasmell/mono-logger-writer@1.2.0","maintainers":[{"name":"bebrasmell","email":"zakofpl@gmail.com"}],"dist":{"shasum":"a1d37820f5ad9739201b7af9c460f6fa7452031a","tarball":"https://registry.npmjs.org/@bebrasmell/mono-logger-writer/-/mono-logger-writer-1.2.0.tgz","fileCount":11,"integrity":"sha512-33frYZraKYlmjQbdXXRBz/cmls0SQZ973zv6q6LQ7fckcsH9K8BNaK+U69GhJD3MJurNttzNKUVerngieLCDuw==","signatures":[{"sig":"MEYCIQCWIAwO9A3uscy/EqSn1S6+TIRnPENfiP9l3ovN3wUrUQIhALjnE/Y6ERzarLXw/z3huch9gSJcpXM0bNK084oRLjAc","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":45288},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"private":false,"scripts":{"lint":"biome check","test":"jest","build":"tsup","lint:fix":"biome check --write .","test:run":"node test.js","test:badges":"jest --coverage && make-coverage-badge --report-path ./artifacts/coverage/coverage-summary.json --output-path ./badges/coverage.svg"},"typings":"./dist/index.d.ts","_npmUser":{"name":"bebrasmell","email":"zakofpl@gmail.com"},"repository":{"url":"https://github.com/bebrasmell/mono-logger-writer.git","type":"git"},"description":"File writing extension for Mono-logger","directories":{},"dependencies":{"@bebrasmell/mono-logger":"^1.5.4"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tsup":"^8.2.3","@swc/core":"^1.7.2","@swc/jest":"^0.2.36","typescript":"^5.5.4","@types/jest":"^29.5.12","@biomejs/biome":"^1.8.3","make-coverage-badge":"^1.2.0"},"_npmOperationalInternal":{"tmp":"tmp/mono-logger-writer_1.2.0_1722351472131_0.656009184436144","host":"s3://npm-registry-packages"},"deprecated":"Please use @zodyac/mono-logger-writer instead."}},"time":{"created":"2024-07-29T14:16:59.044Z","modified":"2024-09-15T20:03:44.650Z","1.0.0":"2024-07-29T14:16:59.336Z","1.1.0":"2024-07-29T15:33:57.674Z","1.2.0":"2024-07-30T14:57:52.435Z"},"author":{"name":"Zak","email":"137602160+bebrasmell@users.noreply.github.com"},"license":"MIT","keywords":["logs","logger","console","topic"],"repository":{"url":"https://github.com/bebrasmell/mono-logger-writer.git","type":"git"},"description":"File writing extension for Mono-logger","maintainers":[{"name":"bebrasmell","email":"zakofpl@gmail.com"}],"readme":"# Writer for [Mono-logger](https://github.com/bebrasmell/mono-logger)\n![NPM Version](https://img.shields.io/npm/v/%40bebrasmell%2Fmono-logger-writer)\n![NPM Downloads](https://img.shields.io/npm/dw/%40bebrasmell%2Fmono-logger-writer)\n![npm bundle size](https://img.shields.io/bundlephobia/min/%40bebrasmell%2Fmono-logger-writer)\n![Test coverage](./badges/coverage.svg)\n\nWriter extension for [Mono-logger 1.5+](https://github.com/bebrasmell/mono-logger).\nPlease refer to its documentation before jumping into configuring the __Writer__.\n\nThis effect allows you to write logs to a file with minimum configuration.\n```ts\nimport { Logger } from '@bebrasmell/mono-logger';\nimport { WriterEffect } from '@bebrasmell/mono-logger-writer';\n\nconst writerEffect = new WriterEffect({\n  path: 'logs',\n});\n\nconst logger = new Logger(\"writer\", {\n  effect: writerEffect,\n});\n\nlogger.info(\"Hello, World!\");\n\n// Console: 7/29/2024, 16:16:16 [INF] writer Hello, world!\n//\n// + file: logs/mono-logger-2024629-0.log:\n// 2024-07-29T13:18:07.235Z [INF] writer Hello, world!\n\n```\n\n## Changelog\nPlease see [CHANGELOG](./CHANGELOG.md) for latest changes.\n\n## Prerequisites\n- Node.js 12+\n- Mono-logger 1.5+\n\n## Installation\nAssuming you have already installed [Mono-logger 1.5+](https://github.com/bebrasmell/mono-logger):\n\n```bash\nyarn add @bebrasmell/mono-logger-writer\n```\n\nOr\n\n```bash\nnpm i @bebrasmell/mono-logger-writer\n```\n\n## Configuration\n- `level` (LogLevel) – The minimum log level to write (e.g. `debug`, `info`, `warn`, `error`, `fatal`). Default: `debug`;\n\n- `path` (string) – The directory to write logs. Default: `logs`;\n\n- `filename` (function) – Function to generate the filename that accepts the current date and file iterator (starts with `0`) and returns a file name `string`;\n\n- `transform` (function) – Function to transform the log message before writing to the file. Default: `undefined`;\n\n- `max_file_size` (number) – The maximum file size in kilobytes before creating a new file. Default: `5 * 1024`KB (`~5`MB);\n\n\n```ts\nimport { Logger, type LogLevel } from '@bebrasmell/mono-logger';\nimport { WriterEffect } from '@bebrasmell/mono-logger-writer';\n\nconst transformer = (ts: Date, level: LogLevel, topics: string[], ...messages: any[]) => {\n  const timestamp = ts.toString();\n  const lvl_str = level.toUpperCase();\n  return `${timestamp} [${lvl_str}] ${topics.join(':')} ${messages.join(' ')}`;\n};\n\nconst writerEffect = new WriterEffect({\n  level: 'info',\n  path: 'logs',\n  filename: (date, i) => `my-log-${date.toISOString()}-${i}.log`,\n  max_file_size: 20 * 1024, // 20MB\n  transform: transformer,\n});\n\nconst logger = new Logger(\"root\", {\n  effect: writerEffect,\n});\n\nlogger.info(\"Hello, World!\");\n\n// Output:\n// + file: logs/my-log-2024-07-29T13:34:40.782Z-0.log\n// Mon Jul 29 2024 16:35:25 GMT+0300 (Istanbul Standard time) [INFO] root Hello, World!\n```\n\n### Size based rotation\nThe __Writer__ will create a new file when the current file size exceeds the `max_file_size` limit. File size is provided in kilobytes. Default file size is around 5MB, which can be changed by setting the `max_file_size` option. If you don't want your files to be rotated, you can just pass `Infinity` to this field.\nIn this case, the __iterator__ will not have any effect.\n\nIf you stop the app and run it again with all the same configuration, __iterator__ will be pointed to the __next of the last file number__. If you want to start from scratch, you can delete those files or change the `filename` function.\n\n### Daily rotation\nBy setting `daily_rotation` to true, you can effortlessly make the __Writer__ create a new file every day. This is useful when you want to keep logs separated by days, not file size.\n\nNote: This will cancel __Size based rotation__ behavior.\n\n## How to screw things up\nCommon problems that can possibly happen fall into one (or more) of these categories:\n\n- `fs` cannot write to the directory because of it's access rules;\n\n- `fs` cannot write because the disk is full;\n\n- File is being overwritten because it happened to have same filename and path (check the `path` and `filename` function);\n\n- Provided `max_file_size` is smaller than a given record, so the file will be rotated immediately (and possibly infinitely if you dump __MASSIVE__ amount of data in one record);\n\n## Contributing\n\nContribution is always welcomed!\nThese are several points of special interest:\n\n- Improve test coverage (Jest);\n- Edge case exploration;\n- Stability and efficiency improvements (KISS);\n\nYou are also welcome to extend and improve [Mono-logger](https://github.com/bebrasmell/mono-logger) plugin ecosystem.\n\n## License\nMIT\n","readmeFilename":"README.md"}