{"_id":"@crewlinq/winston-loki","name":"@crewlinq/winston-loki","dist-tags":{"latest":"6.1.3"},"versions":{"6.1.3":{"author":{"name":"Jani Anttonen"},"dependencies":{"async-exit-hook":"2.0.1","btoa":"^1.2.1","protobufjs":"^7.2.4","url-polyfill":"^1.1.12","winston-transport":"^4.3.0"},"description":"A Winston transport for Grafana Loki - without Snappy","devDependencies":{"coveralls":"^3.0.2","eslint":"^8.8.0","eslint-config-prettier":"^3.6.0","eslint-config-standard":"^12.0.0","eslint-plugin-import":"^2.14.0","eslint-plugin-node":"^8.0.1","eslint-plugin-prettier":"^3.0.1","eslint-plugin-promise":"^4.0.1","eslint-plugin-standard":"^4.0.0","jest":"^27.4.7","standard":"^16.0.4","winston":"^3.5.1"},"jest":{"coverageDirectory":"./test/coverage","coveragePathIgnorePatterns":["./node_modules/","./test/","./src/proto/index.js"]},"keywords":["winston","winston-transport","transport","loki","grafana","logging","plugin","SRE","site reliability engineering","grafana loki"],"license":"MIT","main":"index.js","name":"@crewlinq/winston-loki","packageManager":"yarn@4.9.2","repository":{"type":"git","url":"git+https://github.com/JaniAnttonen/winston-loki.git"},"scripts":{"build:proto":"pbjs -t static-module -w commonjs -o ./src/proto/index.js ./src/proto/logproto.proto && npm run lint:fix","coverage":"jest --coverage","coveralls":"jest --coverage && cat ./test/coverage/lcov.info | coveralls","lint":"eslint *","lint:fix":"standard --fix","test":"standard && ./node_modules/.bin/jest"},"standard":{"env":{"jest":true,"node":true},"ignore":["test/coverage","src/proto/index.js"]},"types":"index.d.ts","version":"6.1.3","_id":"@crewlinq/winston-loki@6.1.3","gitHead":"57b594d421cfd20cb755d099e062654fd16dbdd5","bugs":{"url":"https://github.com/JaniAnttonen/winston-loki/issues"},"homepage":"https://github.com/JaniAnttonen/winston-loki#readme","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-XTyteDu65kaWNJ9gMcp9FYiQ6wXeqCOSgr7euiZXF1S/YDaqojRES0D1mEuJfy/uGy7qGiIND2bfY6OdEBiMvQ==","shasum":"f2239d133295e5d210eaa3f7357373e1a23a0291","tarball":"https://registry.npmjs.org/@crewlinq/winston-loki/-/winston-loki-6.1.3.tgz","fileCount":23,"unpackedSize":3918277,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDJUoc87dOXzP6VrLqBoRws1vvNkdWb0/bP3rxh7JxLIQIgAUJU31Z+368KJaik9gVZNBNcEruj/1Vf4R8c/raBK0o="}]},"_npmUser":{"name":"crewlinq-dev","email":"support@crewlinq.com"},"directories":{},"maintainers":[{"name":"crewlinq-dev","email":"support@crewlinq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/winston-loki_6.1.3_1749188661591_0.4993458121746932"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-06T05:44:21.455Z","6.1.3":"2025-06-06T05:44:21.891Z","modified":"2025-06-06T05:44:22.172Z"},"maintainers":[{"name":"crewlinq-dev","email":"support@crewlinq.com"}],"description":"A Winston transport for Grafana Loki - without Snappy","homepage":"https://github.com/JaniAnttonen/winston-loki#readme","keywords":["winston","winston-transport","transport","loki","grafana","logging","plugin","SRE","site reliability engineering","grafana loki"],"repository":{"type":"git","url":"git+https://github.com/JaniAnttonen/winston-loki.git"},"author":{"name":"Jani Anttonen"},"bugs":{"url":"https://github.com/JaniAnttonen/winston-loki/issues"},"license":"MIT","readme":"# winston-loki\n\n[![npm version](https://badge.fury.io/js/winston-loki.svg)](https://badge.fury.io/js/winston-loki)\n[![install size](https://packagephobia.now.sh/badge?p=winston-loki)](https://packagephobia.now.sh/result?p=winston-loki)\n[![Build Status](https://travis-ci.com/JaniAnttonen/winston-loki.svg?branch=master)](https://travis-ci.com/JaniAnttonen/winston-loki)\n[![Coverage Status](https://coveralls.io/repos/github/JaniAnttonen/winston-loki/badge.svg?branch=master)](https://coveralls.io/github/JaniAnttonen/winston-loki?branch=master)\n[![Maintainability](https://api.codeclimate.com/v1/badges/17a55cce14d581c308bc/maintainability)](https://codeclimate.com/github/JaniAnttonen/winston-loki/maintainability)\n\nA Grafana Loki transport for the nodejs logging library Winston.\n\n## Usage\nThis Winston transport is used similarly to other Winston transports. Require winston and define a new LokiTransport() inside its options when creating it.\n\n### [Examples](./examples/)\nSeveral usage examples with a test configuration for Grafana+Loki+Promtail reside under [`examples/`](./examples/). If you want the simplest possible configuration, that's probably the place to check out. By defining `json: true` and giving `winston-loki` the correct `host` address for Loki is enough for most.\n\n### Options\nLokiTransport() takes a Javascript object as an input. These are the options that are available, __required in bold__:\n\n| **Parameter**      | **Description**                                           | **Example**            | **Default**   |\n| ------------------ | --------------------------------------------------------- | -----------------------| ------------- |\n| __`host`__         | URL for Grafana Loki                                      | http://127.0.0.1:3100  | null          |\n| `interval`         | The interval at which batched logs are sent in seconds    | 30                     | 5             |\n| `json`             | Use JSON instead of Protobuf for transport                | true                   | false         |\n| `batching`         | If batching is not used, the logs are sent as they come   | true                   | true          |\n| `clearOnError`     | Discard any logs that result in an error during transport | true                   | false         |\n| `replaceTimestamp` | Replace any log timestamps with Date.now(). Warning: Disabling `replaceTimestamp` may result in logs failing to upload due to recent changes in the upstream Loki project. It is recommended to leave this option enabled unless you have a specific reason to disable it. | true                   | true          |\n| `labels`           | custom labels, key-value pairs                            | { module: 'http' }     | undefined     |\n| `format`           | winston format (https://github.com/winstonjs/winston#formats) | simple()           | undefined     |\n| `gracefulShutdown` | Enable/disable graceful shutdown (wait for any unsent batches) | false             | true          |\n| `timeout`          | timeout for requests to grafana loki in ms                | 30000                  | undefined     | \n| `basicAuth`        | basic authentication credentials to access Loki over HTTP | username:password      | undefined     | \n| `onConnectionError`| Loki error connection handler                        | (err) => console.error(err) | undefined     | \n| `useWinstonMetaAsLabels` | Use Winston's \"meta\" (such as defaultMeta values) as Loki labels | true        | false         |\n| `ignoredMeta`      | When useWinstonMetaAsLabels is enabled, a list of meta values to ignore | [\"error_description\"]  | undefined |\n\n### Example (Running Loki Locally)\nWith default formatting:\n```js\nconst { createLogger, transports } = require(\"winston\");\nconst LokiTransport = require(\"winston-loki\");\nconst options = {\n  ...,\n  transports: [\n    new LokiTransport({\n      host: \"http://127.0.0.1:3100\"\n    })\n  ]\n  ...\n};\nconst logger = createLogger(options);\n```\n\nYou can set custom labels in every log as well like this:\n```js\nlogger.debug({ message: 'test', labels: { 'key': 'value' } })\n```\n\nTODO: Add custom formatting example\n\n### Example (Grafana Cloud Loki)\n\n**Important**: this snippet requires the following values, here are the instructions for how you can find them.\n\n* `LOKI_HOST`: find this in your Grafana Cloud instance by checking Connections > Data Sources, find the right Loki connection, and copy its URL, which may look like `https://logs-prod-006.grafana.net`\n* `USER_ID`: the user number in the same data source definition, it will be a multi-digit number like `372040`\n* `GRAFANA_CLOUD_TOKEN`: In Grafana Cloud, search for Cloud Access Policies. Create a new Cloud Access Policy, ensuring its scopes include `logs:write`.  Generate a token for this cloud access policy, and use this value here.\n\n```js\nconst { createLogger, transports } = require(\"winston\");\nconst LokiTransport = require(\"winston-loki\");\nconst options = {\n  ...,\n  transports: [\n    new LokiTransport({\n        host: 'LOKI_HOST',\n        labels: { app: 'my-app' },\n        json: true,\n        basicAuth: 'USER_ID:GRAFANA_CLOUD_TOKEN',\n        format: winston.format.json(),\n        replaceTimestamp: true,\n        onConnectionError: (err) => console.error(err),\n    })\n  ]\n  ...\n};\nconst logger = createLogger(options);\nlogger.debug({ message: 'test', labels: { 'key': 'value' } })\n```\n\n\n## Developing\n### Requirements\nRunning a local Loki for testing is probably required, and the easiest way to do that is to follow this guide: https://github.com/grafana/loki/tree/master/production#run-locally-using-docker. After that, Grafana Loki instance is available at `http://localhost:3100`, with a Grafana instance running at `http://localhost:3000`. Username `admin`, password `admin`. Add the Loki source with the URL `http://loki:3100`, and the explorer should work.\n\nRefer to https://grafana.com/docs/loki/latest/api/ for documentation about the available endpoints, data formats etc.\n\n### Example\n```sh\nnpm install\nnpm link\ncd ~/your_project\nnpm link winston-loki\nnpm install\n```\nAnd you should have a working, requirable winston-loki package under your project's node_modules.\nAfter the link has been established, any changes to winston-loki should show on rerun of the software that uses it.\n\n### Run tests\n```sh\nnpm test\n```\n\nWrite new ones under `/test`\n","readmeFilename":"README.md","_rev":"1-cfecbf119faaf18fa7c80e0b05d19975"}