diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..dd55556 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,31 @@ +name: Publish to NPM +on: + release: + types: [published] +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 16 + registry-url: https://registry.npmjs.org + - name: Check node_modules cache + uses: actions/cache@v2 + id: yarn-cache + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + - name: Install dependencies + if: steps.yarn-cache.outputs.cache-hit != 'true' + run: yarn install --frozen-lockfile + - name: Test + run: yarn test --ci --coverage + - name: Version + run: yarn version --new-version "${GITHUB_REF:11}" --no-git-tag-version + - name: Publish + run: yarn publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index e76925e..ecb1a3a 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,12 @@ LokiTransport() takes a Javascript object as an input. These are the options tha | `batching` | If batching is not used, the logs are sent as they come | true | true | | `clearOnError` | Discard any logs that result in an error during transport | true | false | | `replaceTimestamp` | Replace any log timestamps with Date.now() | true | false | -| `labels` | custom labels, key-value pairs | { module: 'http' } | null | -| `format` | winston format (https://github.com/winstonjs/winston#formats) | simple() | null | +| `labels` | custom labels, key-value pairs | { module: 'http' } | undefined | +| `format` | winston format (https://github.com/winstonjs/winston#formats) | simple() | undefined | | `gracefulShutdown` | Enable/disable graceful shutdown (wait for any unsent batches) | false | true | -| `timeout` | timeout for requests to grafana loki in ms | 30000 | null | -| `basicAuth` | basic authentication credentials to access Loki over HTTP | username:password | null | +| `timeout` | timeout for requests to grafana loki in ms | 30000 | undefined | +| `basicAuth` | basic authentication credentials to access Loki over HTTP | username:password | undefined | +| `onConnectionError`| Loki error connection handler | (err) => console.error(err) | undefined | ### Example With default formatting: diff --git a/index.d.ts b/index.d.ts index 539e29c..2c0a77f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,10 +9,10 @@ declare interface LokiTransportOptions extends TransportStream.TransportStreamOp batching?: boolean; labels?: object; clearOnError?: boolean, - replaceOnError?: boolean, replaceTimestamp?: boolean, gracefulShutdown?: boolean, timeout?: number, + onConnectionError?(error: unknown): void } declare class LokiTransport extends TransportStream { diff --git a/index.js b/index.js index 595ae8e..5931c2c 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ class LokiTransport extends Transport { json: options.json, batching: options.batching !== false, clearOnError: options.clearOnError, - replaceOnError: options.replaceOnError, + onConnectionError: options.onConnectionError, replaceTimestamp: options.replaceTimestamp, gracefulShutdown: options.gracefulShutdown !== false, timeout: options.timeout diff --git a/package-lock.json b/package-lock.json index 5e8a913..9f15782 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "winston-loki", - "version": "6.0.3", + "version": "6.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -489,18 +489,6 @@ "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "dev": true }, - "ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, - "requires": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - } - }, "eslint-visitor-keys": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", @@ -1457,9 +1445,9 @@ } }, "ajv": { - "version": "6.11.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.11.0.tgz", - "integrity": "sha512-nCprB/0syFYy9fVYU1ox1l2KN8S9I+tziH8D4zdZuLT3N6RMlGSGt5FSTpAiHB/Whv8Qs1cWHma1aMKZyaHRKA==", + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1", @@ -2358,18 +2346,6 @@ "strip-json-comments": "^3.1.1" }, "dependencies": { - "ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, - "requires": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - } - }, "ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", @@ -7449,9 +7425,9 @@ }, "dependencies": { "ajv": { - "version": "8.9.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.9.0.tgz", - "integrity": "sha512-qOKJyNj/h+OWx7s5DePL6Zu1KeM9jPZhwBqs+7DzP6bGOvqzVCSf0xueYmVuaC/oQ/VtS2zLMLHdQFbkka+XDQ==", + "version": "8.10.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.10.0.tgz", + "integrity": "sha512-bzqAEZOjkrUMl2afH8dknrq5KEk2SrwdBROR+vH1EKVQTqaUbJVPdc/gEdggTMM0Se+s+Ja4ju4TlNcStKl2Hw==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1", diff --git a/src/batcher.js b/src/batcher.js index d857bed..2a07b2f 100644 --- a/src/batcher.js +++ b/src/batcher.js @@ -201,6 +201,9 @@ class Batcher { .catch(err => { // Clear the batch on error if enabled this.options.clearOnError && this.clearBatch() + + this.options.onConnectionError !== undefined && this.options.onConnectionError(err) + reject(err) }) }