{"_id":"winston-opensearch","_rev":"2-3bd31e5281ba821be8c71142bf2815fe","name":"winston-opensearch","dist-tags":{"latest":"0.3.0"},"versions":{"0.1.0":{"name":"winston-opensearch","version":"0.1.0","keywords":["logging","winston","opensearch","transport","logstash"],"license":"MIT","_id":"winston-opensearch@0.1.0","maintainers":[{"name":"lukas.j.han","email":"lukas.j.han@gmail.com"}],"contributors":[{"url":"https://github.com/andypotanin","name":"Andy Potanin"}],"homepage":"https://github.com/lukasjhan/winston-opensearch#readme","bugs":{"url":"https://github.com/lukasjhan/winston-opensearch/issues"},"dist":{"shasum":"6a341a4fdb432c46ed3300fc766d95428fb8c93e","tarball":"https://registry.npmjs.org/winston-opensearch/-/winston-opensearch-0.1.0.tgz","fileCount":9,"integrity":"sha512-sWqFzapCHF/z5O7/wyjyW3F84FfpRThqchVirNno8SpSIG0KjPLH82z1rekU2PLquFyAtGZdbfR7vuO2OINnVw==","signatures":[{"sig":"MEUCIGFrmus9+cY7bX4ugdAZr16ozHRb46lywIaNjalUJ+uFAiEAnmbFy6SRsY6Ecx5pgielzYwYbzL9tSW0cSXNz0mpas8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":27998},"main":"index","types":"./index.d.ts","authors":[{"url":"https://github.com/jackdbernier","name":"Jacques-Olivier D. Bernier"},{"url":"https://github.com/vanthome","name":"Thomas Hoppe","email":"thomas.hoppe@n-fuse.co"},{"url":"https://github.com/lukasjhan","name":"Lukas J Han","email":"lukas.j.han@gmail.com"}],"engines":{"node":">= 8.0.0"},"gitHead":"22ff869830db58025edc67f980f401e18dd8c7f5","scripts":{"lint":"eslint *.json *.js","test":"nyc mocha","mocha":"mocha --full-trace./test/* -- --trace-warnings","coveralls":"nyc report --reporter=text-lcov | coveralls"},"_npmUser":{"name":"lukas.j.han","email":"lukas.j.han@gmail.com"},"prettier":{"printWidth":120,"arrowParens":"always","singleQuote":true,"trailingComma":"all"},"repository":{"url":"git+https://github.com/lukasjhan/winston-opensearch.git","type":"git"},"_npmVersion":"9.6.6","description":"An Opensearch transport for winston","directories":{},"_nodeVersion":"16.17.0","dependencies":{"dayjs":"^1.11.7","debug":"^4.3.4","retry":"^0.13.1","promise":"^8.3.0","winston":"^3.8.2","lodash.omit":"^4.5.0","lodash.defaults":"^4.2.0","winston-transport":"^4.5.0","@opensearch-project/opensearch":"^2.3.1"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.1.0","mocha":"^10.2.0","eslint":"^8.34.0","should":"^13.2.3","coveralls":"^3.1.1","babel-eslint":"^10.1.0","eslint-plugin-json":"^3.1.0","eslint-plugin-import":"^2.27.5","eslint-config-airbnb-base":"^15.0.0"},"_npmOperationalInternal":{"tmp":"tmp/winston-opensearch_0.1.0_1691681142993_0.9430972823985946","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"winston-opensearch","version":"0.2.0","keywords":["logging","winston","opensearch","transport","logstash"],"license":"MIT","_id":"winston-opensearch@0.2.0","maintainers":[{"name":"lukas.j.han","email":"lukas.j.han@gmail.com"}],"contributors":[{"url":"https://github.com/andypotanin","name":"Andy Potanin"}],"homepage":"https://github.com/lukasjhan/winston-opensearch#readme","bugs":{"url":"https://github.com/lukasjhan/winston-opensearch/issues"},"dist":{"shasum":"f9e33972128143c20a12f7db44deb254f828c80f","tarball":"https://registry.npmjs.org/winston-opensearch/-/winston-opensearch-0.2.0.tgz","fileCount":9,"integrity":"sha512-CwJObUl8a76hUvw5nq8gmYUxh4lX+qmIxRfOSiBx409uhTfIqp/4xzhGavBQndrPP+RhnmwMiZYZiCC3v67xDg==","signatures":[{"sig":"MEQCIH2i5nPHVppPVvsVBciJZoyvAbe8zEfUZElRo59UZAZ/AiA6/9wShSGvanP2gHNtBNu468na4SuNuoXriUwURQoN+g==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":28130},"main":"index","types":"./index.d.ts","authors":[{"url":"https://github.com/jackdbernier","name":"Jacques-Olivier D. Bernier"},{"url":"https://github.com/vanthome","name":"Thomas Hoppe","email":"thomas.hoppe@n-fuse.co"},{"url":"https://github.com/lukasjhan","name":"Lukas J Han","email":"lukas.j.han@gmail.com"}],"engines":{"node":">= 8.0.0"},"gitHead":"1886a6354938d2691e3b1049b99209f9362af1eb","scripts":{"lint":"eslint *.json *.js","test":"nyc mocha","mocha":"mocha --full-trace./test/* -- --trace-warnings","coveralls":"nyc report --reporter=text-lcov | coveralls"},"_npmUser":{"name":"lukas.j.han","email":"lukas.j.han@gmail.com"},"prettier":{"printWidth":120,"arrowParens":"always","singleQuote":true,"trailingComma":"all"},"repository":{"url":"git+https://github.com/lukasjhan/winston-opensearch.git","type":"git"},"_npmVersion":"10.2.4","description":"An Opensearch transport for winston","directories":{},"_nodeVersion":"20.11.1","dependencies":{"dayjs":"^1.11.7","debug":"^4.3.4","retry":"^0.13.1","promise":"^8.3.0","winston":"^3.8.2","lodash.omit":"^4.5.0","lodash.defaults":"^4.2.0","winston-transport":"^4.5.0","@opensearch-project/opensearch":"^2.3.1"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.1.0","mocha":"^10.2.0","eslint":"^8.34.0","should":"^13.2.3","coveralls":"^3.1.1","babel-eslint":"^10.1.0","eslint-plugin-json":"^3.1.0","eslint-plugin-import":"^2.27.5","eslint-config-airbnb-base":"^15.0.0"},"_npmOperationalInternal":{"tmp":"tmp/winston-opensearch_0.2.0_1735946744893_0.22035222460541504","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"winston-opensearch","version":"0.3.0","description":"An Opensearch transport for winston","main":"index","authors":[{"name":"Jacques-Olivier D. Bernier","url":"https://github.com/jackdbernier"},{"name":"Thomas Hoppe","url":"https://github.com/vanthome","email":"thomas.hoppe@n-fuse.co"},{"name":"Lukas J Han","url":"https://github.com/lukasjhan","email":"lukas.j.han@gmail.com"}],"contributors":[{"name":"Andy Potanin","url":"https://github.com/andypotanin"}],"repository":{"type":"git","url":"git+https://github.com/lukasjhan/winston-opensearch.git"},"license":"MIT","keywords":["logging","winston","opensearch","transport","logstash"],"dependencies":{"@opensearch-project/opensearch":"^2.3.1","dayjs":"^1.11.7","debug":"^4.3.4","lodash.defaults":"^4.2.0","lodash.omit":"^4.5.0","promise":"^8.3.0","retry":"^0.13.1","winston":"^3.8.2","winston-transport":"^4.5.0"},"devDependencies":{"babel-eslint":"^10.1.0","coveralls":"^3.1.1","eslint":"^8.34.0","eslint-config-airbnb-base":"^15.0.0","eslint-plugin-import":"^2.27.5","eslint-plugin-json":"^3.1.0","mocha":"^10.2.0","nyc":"^15.1.0","should":"^13.2.3"},"scripts":{"test":"nyc mocha","lint":"eslint *.json *.js","mocha":"mocha --full-trace./test/* -- --trace-warnings","coveralls":"nyc report --reporter=text-lcov | coveralls"},"engines":{"node":">= 8.0.0"},"prettier":{"printWidth":120,"singleQuote":true,"trailingComma":"all","arrowParens":"always"},"_id":"winston-opensearch@0.3.0","gitHead":"d129f1c34cf68b8334b9a888dd34482b4d18ea4a","types":"./index.d.ts","bugs":{"url":"https://github.com/lukasjhan/winston-opensearch/issues"},"homepage":"https://github.com/lukasjhan/winston-opensearch#readme","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-tKkIyxh9IMeFYL8Ty1NPyJCxGtJXiz2kR3CQ50TBtTSvDriEN0uNu6UBtwb4bm7it6zpe27KJwvP0ySg9tQ02g==","shasum":"7f1d94f40fca3c984ebcf13131f2f0c34e6cf601","tarball":"https://registry.npmjs.org/winston-opensearch/-/winston-opensearch-0.3.0.tgz","fileCount":9,"unpackedSize":28213,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH6uQicO3E+2fmL6zUMvMJYSM8hwNivW2eSdoun8Q+09AiBSOkXrF3U6gzOqZuBtqf2WFI5lldkPrEqnzDVK1yyxOQ=="}]},"_npmUser":{"name":"lukas.j.han","email":"lukas.j.han@gmail.com"},"directories":{},"maintainers":[{"name":"lukas.j.han","email":"lukas.j.han@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/winston-opensearch_0.3.0_1735955381379_0.039067387156313416"},"_hasShrinkwrap":false}},"time":{"created":"2023-08-10T15:25:42.892Z","modified":"2025-01-04T01:49:41.780Z","0.1.0":"2023-08-10T15:25:43.215Z","0.2.0":"2025-01-03T23:25:45.092Z","0.3.0":"2025-01-04T01:49:41.590Z"},"bugs":{"url":"https://github.com/lukasjhan/winston-opensearch/issues"},"license":"MIT","homepage":"https://github.com/lukasjhan/winston-opensearch#readme","keywords":["logging","winston","opensearch","transport","logstash"],"repository":{"type":"git","url":"git+https://github.com/lukasjhan/winston-opensearch.git"},"description":"An Opensearch transport for winston","contributors":[{"name":"Andy Potanin","url":"https://github.com/andypotanin"}],"maintainers":[{"name":"lukas.j.han","email":"lukas.j.han@gmail.com"}],"readme":"# winston-opensearch\n\ntransport for the [winston](https://github.com/winstonjs/winston) logging toolkit.\n\nMost of code is from the [winston-elasticsearch](https://github.com/vanthome/winston-elasticsearch) version 0.17.3\n\n## Features\n\n- [logstash](https://www.elastic.co/products/logstash) compatible message structure.\n- Thus consumable with [kibana](https://www.elastic.co/products/kibana).\n- Date pattern based index names.\n- Custom transformer function to transform logged data into a different message structure.\n- Buffering of messages in case of unavailability of ES. The limit is the memory as all unwritten messages are kept in memory.\n\n### Compatibility\n\nI tested **Winston 3.8.2**, **Opensearch 2.7** for AWS usage.\n\n## Installation\n\n```sh\nnpm install --save winston winston-opensearch\n```\n\n## Usage\n\n```js\nconst winston = require('winston');\nconst { OpensearchTransport } = require('winston-opensearch');\n\nconst esTransportOpts = {\n  level: 'info',\n};\nconst esTransport = new OpensearchTransport(esTransportOpts);\nconst logger = winston.createLogger({\n  transports: [esTransport],\n});\n// Compulsory error handling\nlogger.on('error', (error) => {\n  console.error('Error in logger caught', error);\n});\nesTransport.on('error', (error) => {\n  console.error('Error in logger caught', error);\n});\n```\n\nThe [winston API for logging](https://github.com/winstonjs/winston#streams-objectmode-and-info-objects)\ncan be used with one restriction: Only one JS object can only be logged and indexed as such.\nIf multiple objects are provided as arguments, the contents are stringified.\n\n## Options\n\n- `level` [`info`] Messages logged with a severity greater or equal to the given one are logged to ES; others are discarded.\n- `index` [none | when `dataStream` is `true`, `logs-app-default`] The index to be used. This option is mutually exclusive with `indexPrefix`.\n- `indexPrefix` [`logs`] The prefix to use to generate the index name according to the pattern `<indexPrefix>-<indexSuffixPattern>`. Can be string or function, returning the string to use.\n- `indexSuffixPattern` [`YYYY.MM.DD`] a Day.js compatible date/ time pattern.\n- `transformer` [see below] A transformer function to transform logged data into a different message structure.\n- `useTransformer` [`true`] If set to `true`, the given `transformer` will be used (or the default). Set to `false` if you want to apply custom transformers during Winston's `createLogger`.\n- `ensureIndexTemplate` [`true`] If set to `true`, the given `indexTemplate` is checked/ uploaded to ES when the module is sending the first log message to make sure the log messages are mapped in a sensible manner.\n- `indexTemplate` [see file `index-template-mapping.json`] the mapping template to be ensured as parsed JSON.\n  `ensureIndexTemplate` is `true` and `indexTemplate` is `undefined`\n- `flushInterval` [`2000`] Time span between bulk writes in ms.\n- `retryLimit` [`400`] Number of retries to connect to ES before giving up.\n- `dataStream` [false] Use Opensearch datastreams.\n- `healthCheckTimeout` [`30s`] Timeout for one health check (health checks will be retried forever).\n- `healthCheckWaitForStatus` [`yellow`] Status to wait for when check upon health. See [its API docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html) for supported options.\n- `healthCheckWaitForNodes` [`>=1`] Nodes to wait for when check upon health. See [its API docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html) for supported options.\n- `client` An [opensearch client](https://www.npmjs.com/package/@elastic/elasticsearch) instance. If given, the `clientOpts` are ignored.\n- `clientOpts` An object passed to the ES client. See [its docs](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-configuration.html) for supported options.\n- `waitForActiveShards` [`1`] Sets the number of shard copies that must be active before proceeding with the bulk operation.\n- `pipeline` [none] Sets the pipeline id to pre-process incoming documents with. See [the bulk API docs](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-bulk).\n- `buffering` [`true`] Boolean flag to enable or disable messages buffering. The `bufferLimit` option is ignored if set to `false`.\n- `bufferLimit` [`null`] Limit for the number of log messages in the buffer.\n- `source` [none] the source of the log message. This can be useful for microservices to understand from which service a log message origins.\n- `internalLogger` [`console.error`] A logger of last resort to log internal errors.\n\n### Logging of OpenSearch Client\n\nThe default client and options will log through `console`.\n\n### Interdependencies of Options\n\nWhen changing the `indexPrefix` and/or the `transformer`,\nmake sure to provide a matching `indexTemplate`.\n\n## Transformer\n\nThe transformer function allows mutation of log data as provided\nby winston into a shape more appropriate for indexing in Opensearch.\n\nThe default transformer generates a `@timestamp` and rolls any `meta`\nobjects into an object called `fields`.\n\nParams:\n\n- `logdata` An object with the data to log. Properties are:\n  - `timestamp` [`new Date().toISOString()`] The timestamp of the log entry\n  - `level` The log level of the entry\n  - `message` The message for the log entry\n  - `meta` The meta data for the log entry\n\nReturns: Object with the following properties\n\n- `@timestamp` The timestamp of the log entry\n- `severity` The log level of the entry\n- `message` The message for the log entry\n- `fields` The meta data for the log entry\n\nThe default transformer function's transformation is shown below.\n\nInput A:\n\n```js\n{\n  \"message\": \"Some message\",\n  \"level\": \"info\",\n  \"meta\": {\n    \"method\": \"GET\",\n    \"url\": \"/sitemap.xml\",\n    ...\n  }\n}\n```\n\nOutput A:\n\n```js\n{\n  \"@timestamp\": \"2019-09-30T05:09:08.282Z\",\n  \"message\": \"Some message\",\n  \"severity\": \"info\",\n  \"fields\": {\n    \"method\": \"GET\",\n    \"url\": \"/sitemap.xml\",\n    ...\n  }\n}\n```\n\nThe default transformer can be imported and extended\n\n### Example\n\n```js\nconst { OpensearchTransformer } = require('winston-opensearch');\nconst esTransportOpts = {\n  transformer: (logData) => {\n    const transformed = OpensearchTransformer(logData);\n    transformed.fields.customField = 'customValue';\n    return transformed;\n  },\n};\nconst esTransport = new OpensearchTransformer(esTransportOpts);\n```\n\nNote that in current logstash versions, the only \"standard fields\" are\n`@timestamp` and `@version`, anything else is just free.\n\nA custom transformer function can be provided in the options initiation.\n\n## Events\n\n- `error`: in case of any error.\n\n## Example\n\nAn example assuming default settings.\n\n### Log Action\n\n```js\nlogger.info('Some message', {});\n```\n\nOnly JSON objects are logged from the `meta` field. Any non-object is ignored.\n\n### Generated Message\n\nThe log message generated by this module has the following structure:\n\n```js\n{\n  \"@timestamp\": \"2019-09-30T05:09:08.282Z\",\n  \"message\": \"Some log message\",\n  \"severity\": \"info\",\n  \"fields\": {\n    \"method\": \"GET\",\n    \"url\": \"/sitemap.xml\",\n    \"headers\": {\n      \"host\": \"www.example.com\",\n      \"user-agent\": \"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)\",\n      \"accept\": \"*/*\",\n      \"accept-encoding\": \"gzip,deflate\",\n      \"from\": \"googlebot(at)googlebot.com\",\n      \"if-modified-since\": \"Tue, 30 Sep 2019 11:34:56 GMT\",\n      \"x-forwarded-for\": \"66.249.78.19\"\n    }\n  }\n}\n```\n\n### Target Index\n\nThis message would be POSTed to the following endpoint:\n\n    http://localhost:9200/logs-2019.09.30/log/\n\nSo the default mapping uses an index pattern `logs-*`.\n","readmeFilename":"README.md"}