@loglayer/transport-logflare 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 LogLayer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Logflare Transport for LogLayer
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/%40loglayer%2Ftransport-logflare)](https://www.npmjs.com/package/@loglayer/transport-logflare)
4
+ [![NPM Downloads](https://img.shields.io/npm/dm/%40loglayer%2Ftransport-logflare)](https://www.npmjs.com/package/@loglayer/transport-logflare)
5
+ [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
6
+
7
+ A Logflare transport for the [LogLayer](https://loglayer.dev) logging library.
8
+
9
+ Ships logs to [Logflare](https://logflare.app) using the HTTP transport with Logflare-specific configuration. Features include:
10
+ - Automatic Logflare JSON format
11
+ - Built on top of the robust HTTP transport
12
+ - Retry logic with exponential backoff
13
+ - Rate limiting support
14
+ - Batch sending with configurable size and timeout
15
+ - Error and debug callbacks
16
+ - Support for self-hosted Logflare instances
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install loglayer @loglayer/transport-logflare serialize-error
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```typescript
27
+ import { LogLayer } from 'loglayer'
28
+ import { LogflareTransport } from "@loglayer/transport-logflare"
29
+ import { serializeError } from "serialize-error";
30
+
31
+ const log = new LogLayer({
32
+ errorSerializer: serializeError,
33
+ contextFieldName: null, // recommended based on testing
34
+ metadataFieldName: null, // recommended based on testing
35
+ transport: new LogflareTransport({
36
+ sourceId: "YOUR-SOURCE-ID",
37
+ apiKey: "YOUR-API-KEY",
38
+
39
+ })
40
+ })
41
+
42
+ // Use the logger
43
+ log.info("This is a test message");
44
+ log.withMetadata({ userId: "123" }).error("User not found");
45
+ ```
46
+
47
+ ## Documentation
48
+
49
+ For more details, visit [https://loglayer.dev/transports/logflare](https://loglayer.dev/transports/logflare)
package/dist/index.cjs ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ LogflareTransport: () => LogflareTransport
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/LogflareTransport.ts
28
+ var import_transport_http = require("@loglayer/transport-http");
29
+ var LogflareTransport = class extends import_transport_http.HttpTransport {
30
+ constructor(config) {
31
+ const apiEndpoint = config.url ?? "https://api.logflare.app";
32
+ const fullUrl = `${apiEndpoint}/logs/json?source=${config.sourceId}`;
33
+ const payloadTemplate = config.payloadTemplate ?? (({ logLevel, message, data }) => {
34
+ const logEntry = {
35
+ message
36
+ };
37
+ if (data) {
38
+ logEntry.metadata = data;
39
+ }
40
+ return JSON.stringify(logEntry);
41
+ });
42
+ const httpConfig = { ...config };
43
+ delete httpConfig.sourceId;
44
+ delete httpConfig.apiKey;
45
+ delete httpConfig.url;
46
+ delete httpConfig.payloadTemplate;
47
+ super({
48
+ url: fullUrl,
49
+ method: "POST",
50
+ headers: {
51
+ "Content-Type": "application/json; charset=utf-8",
52
+ "X-API-KEY": config.apiKey
53
+ },
54
+ payloadTemplate,
55
+ batchMode: "field",
56
+ // Use Logflare's batch format
57
+ batchFieldName: "batch",
58
+ // Use Logflare's batch field name
59
+ ...httpConfig
60
+ });
61
+ }
62
+ };
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ LogflareTransport
66
+ });
67
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/LogflareTransport.ts"],"sourcesContent":["export { LogflareTransport, type LogflareTransportConfig } from \"./LogflareTransport.js\";\n","import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n/**\n * Configuration options for the Logflare transport.\n * This is essentially a wrapper around HttpTransport with Logflare specific defaults.\n */\nexport interface LogflareTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"headers\" | \"payloadTemplate\"> {\n /**\n * Your Logflare source ID\n */\n sourceId: string;\n /**\n * Your Logflare API key\n */\n apiKey: string;\n /**\n * Custom Logflare API endpoint (for self-hosted instances)\n * @default \"https://api.logflare.app\"\n */\n url?: string;\n /**\n * Function to transform log data into the payload format (optional, defaults to Logflare format)\n */\n payloadTemplate?: (data: { logLevel: string; message: string; data?: Record<string, any> }) => string;\n}\n\n/**\n * LogflareTransport is responsible for sending logs to Logflare.\n * It extends HttpTransport with Logflare-specific configuration.\n *\n * Features:\n * - Automatic Logflare JSON format\n * - Retry logic with exponential backoff (via HttpTransport)\n * - Rate limiting support (via HttpTransport)\n * - Batch sending with configurable size and timeout (via HttpTransport)\n * - Error and debug callbacks\n * - Support for self-hosted Logflare instances\n */\nexport class LogflareTransport extends HttpTransport {\n constructor(config: LogflareTransportConfig) {\n const apiEndpoint = config.url ?? \"https://api.logflare.app\";\n const fullUrl = `${apiEndpoint}/logs/json?source=${config.sourceId}`;\n\n const payloadTemplate = config.payloadTemplate ?? (({ logLevel, message, data }) => {\n const logEntry: Record<string, any> = {\n message,\n };\n\n // Only add metadata if data is provided\n if (data) {\n logEntry.metadata = data;\n }\n\n return JSON.stringify(logEntry);\n });\n\n // Create HTTP transport config, excluding Logflare-specific properties\n const httpConfig = { ...config };\n delete httpConfig.sourceId;\n delete httpConfig.apiKey;\n delete httpConfig.url;\n delete httpConfig.payloadTemplate;\n\n super({\n url: fullUrl,\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json; charset=utf-8\",\n \"X-API-KEY\": config.apiKey,\n },\n payloadTemplate,\n batchMode: \"field\", // Use Logflare's batch format\n batchFieldName: \"batch\", // Use Logflare's batch field name\n ...httpConfig,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,4BAA8B;AAsCvB,IAAM,oBAAN,cAAgC,oCAAc;AAAA,EACnD,YAAY,QAAiC;AAC3C,UAAM,cAAc,OAAO,OAAO;AAClC,UAAM,UAAU,GAAG,WAAW,qBAAqB,OAAO,QAAQ;AAElE,UAAM,kBAAkB,OAAO,oBAAoB,CAAC,EAAE,UAAU,SAAS,KAAK,MAAM;AAClF,YAAM,WAAgC;AAAA,QACpC;AAAA,MACF;AAGA,UAAI,MAAM;AACR,iBAAS,WAAW;AAAA,MACtB;AAEA,aAAO,KAAK,UAAU,QAAQ;AAAA,IAChC;AAGA,UAAM,aAAa,EAAE,GAAG,OAAO;AAC/B,WAAO,WAAW;AAClB,WAAO,WAAW;AAClB,WAAO,WAAW;AAClB,WAAO,WAAW;AAElB,UAAM;AAAA,MACJ,KAAK;AAAA,MACL,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,aAAa,OAAO;AAAA,MACtB;AAAA,MACA;AAAA,MACA,WAAW;AAAA;AAAA,MACX,gBAAgB;AAAA;AAAA,MAChB,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -0,0 +1,46 @@
1
+ import { HttpTransport, HttpTransportConfig } from '@loglayer/transport-http';
2
+
3
+ /**
4
+ * Configuration options for the Logflare transport.
5
+ * This is essentially a wrapper around HttpTransport with Logflare specific defaults.
6
+ */
7
+ interface LogflareTransportConfig extends Omit<HttpTransportConfig, "url" | "headers" | "payloadTemplate"> {
8
+ /**
9
+ * Your Logflare source ID
10
+ */
11
+ sourceId: string;
12
+ /**
13
+ * Your Logflare API key
14
+ */
15
+ apiKey: string;
16
+ /**
17
+ * Custom Logflare API endpoint (for self-hosted instances)
18
+ * @default "https://api.logflare.app"
19
+ */
20
+ url?: string;
21
+ /**
22
+ * Function to transform log data into the payload format (optional, defaults to Logflare format)
23
+ */
24
+ payloadTemplate?: (data: {
25
+ logLevel: string;
26
+ message: string;
27
+ data?: Record<string, any>;
28
+ }) => string;
29
+ }
30
+ /**
31
+ * LogflareTransport is responsible for sending logs to Logflare.
32
+ * It extends HttpTransport with Logflare-specific configuration.
33
+ *
34
+ * Features:
35
+ * - Automatic Logflare JSON format
36
+ * - Retry logic with exponential backoff (via HttpTransport)
37
+ * - Rate limiting support (via HttpTransport)
38
+ * - Batch sending with configurable size and timeout (via HttpTransport)
39
+ * - Error and debug callbacks
40
+ * - Support for self-hosted Logflare instances
41
+ */
42
+ declare class LogflareTransport extends HttpTransport {
43
+ constructor(config: LogflareTransportConfig);
44
+ }
45
+
46
+ export { LogflareTransport, type LogflareTransportConfig };
@@ -0,0 +1,46 @@
1
+ import { HttpTransport, HttpTransportConfig } from '@loglayer/transport-http';
2
+
3
+ /**
4
+ * Configuration options for the Logflare transport.
5
+ * This is essentially a wrapper around HttpTransport with Logflare specific defaults.
6
+ */
7
+ interface LogflareTransportConfig extends Omit<HttpTransportConfig, "url" | "headers" | "payloadTemplate"> {
8
+ /**
9
+ * Your Logflare source ID
10
+ */
11
+ sourceId: string;
12
+ /**
13
+ * Your Logflare API key
14
+ */
15
+ apiKey: string;
16
+ /**
17
+ * Custom Logflare API endpoint (for self-hosted instances)
18
+ * @default "https://api.logflare.app"
19
+ */
20
+ url?: string;
21
+ /**
22
+ * Function to transform log data into the payload format (optional, defaults to Logflare format)
23
+ */
24
+ payloadTemplate?: (data: {
25
+ logLevel: string;
26
+ message: string;
27
+ data?: Record<string, any>;
28
+ }) => string;
29
+ }
30
+ /**
31
+ * LogflareTransport is responsible for sending logs to Logflare.
32
+ * It extends HttpTransport with Logflare-specific configuration.
33
+ *
34
+ * Features:
35
+ * - Automatic Logflare JSON format
36
+ * - Retry logic with exponential backoff (via HttpTransport)
37
+ * - Rate limiting support (via HttpTransport)
38
+ * - Batch sending with configurable size and timeout (via HttpTransport)
39
+ * - Error and debug callbacks
40
+ * - Support for self-hosted Logflare instances
41
+ */
42
+ declare class LogflareTransport extends HttpTransport {
43
+ constructor(config: LogflareTransportConfig);
44
+ }
45
+
46
+ export { LogflareTransport, type LogflareTransportConfig };
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ // src/LogflareTransport.ts
2
+ import { HttpTransport } from "@loglayer/transport-http";
3
+ var LogflareTransport = class extends HttpTransport {
4
+ constructor(config) {
5
+ const apiEndpoint = config.url ?? "https://api.logflare.app";
6
+ const fullUrl = `${apiEndpoint}/logs/json?source=${config.sourceId}`;
7
+ const payloadTemplate = config.payloadTemplate ?? (({ logLevel, message, data }) => {
8
+ const logEntry = {
9
+ message
10
+ };
11
+ if (data) {
12
+ logEntry.metadata = data;
13
+ }
14
+ return JSON.stringify(logEntry);
15
+ });
16
+ const httpConfig = { ...config };
17
+ delete httpConfig.sourceId;
18
+ delete httpConfig.apiKey;
19
+ delete httpConfig.url;
20
+ delete httpConfig.payloadTemplate;
21
+ super({
22
+ url: fullUrl,
23
+ method: "POST",
24
+ headers: {
25
+ "Content-Type": "application/json; charset=utf-8",
26
+ "X-API-KEY": config.apiKey
27
+ },
28
+ payloadTemplate,
29
+ batchMode: "field",
30
+ // Use Logflare's batch format
31
+ batchFieldName: "batch",
32
+ // Use Logflare's batch field name
33
+ ...httpConfig
34
+ });
35
+ }
36
+ };
37
+ export {
38
+ LogflareTransport
39
+ };
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/LogflareTransport.ts"],"sourcesContent":["import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n/**\n * Configuration options for the Logflare transport.\n * This is essentially a wrapper around HttpTransport with Logflare specific defaults.\n */\nexport interface LogflareTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"headers\" | \"payloadTemplate\"> {\n /**\n * Your Logflare source ID\n */\n sourceId: string;\n /**\n * Your Logflare API key\n */\n apiKey: string;\n /**\n * Custom Logflare API endpoint (for self-hosted instances)\n * @default \"https://api.logflare.app\"\n */\n url?: string;\n /**\n * Function to transform log data into the payload format (optional, defaults to Logflare format)\n */\n payloadTemplate?: (data: { logLevel: string; message: string; data?: Record<string, any> }) => string;\n}\n\n/**\n * LogflareTransport is responsible for sending logs to Logflare.\n * It extends HttpTransport with Logflare-specific configuration.\n *\n * Features:\n * - Automatic Logflare JSON format\n * - Retry logic with exponential backoff (via HttpTransport)\n * - Rate limiting support (via HttpTransport)\n * - Batch sending with configurable size and timeout (via HttpTransport)\n * - Error and debug callbacks\n * - Support for self-hosted Logflare instances\n */\nexport class LogflareTransport extends HttpTransport {\n constructor(config: LogflareTransportConfig) {\n const apiEndpoint = config.url ?? \"https://api.logflare.app\";\n const fullUrl = `${apiEndpoint}/logs/json?source=${config.sourceId}`;\n\n const payloadTemplate = config.payloadTemplate ?? (({ logLevel, message, data }) => {\n const logEntry: Record<string, any> = {\n message,\n };\n\n // Only add metadata if data is provided\n if (data) {\n logEntry.metadata = data;\n }\n\n return JSON.stringify(logEntry);\n });\n\n // Create HTTP transport config, excluding Logflare-specific properties\n const httpConfig = { ...config };\n delete httpConfig.sourceId;\n delete httpConfig.apiKey;\n delete httpConfig.url;\n delete httpConfig.payloadTemplate;\n\n super({\n url: fullUrl,\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json; charset=utf-8\",\n \"X-API-KEY\": config.apiKey,\n },\n payloadTemplate,\n batchMode: \"field\", // Use Logflare's batch format\n batchFieldName: \"batch\", // Use Logflare's batch field name\n ...httpConfig,\n });\n }\n}\n"],"mappings":";AACA,SAAS,qBAAqB;AAsCvB,IAAM,oBAAN,cAAgC,cAAc;AAAA,EACnD,YAAY,QAAiC;AAC3C,UAAM,cAAc,OAAO,OAAO;AAClC,UAAM,UAAU,GAAG,WAAW,qBAAqB,OAAO,QAAQ;AAElE,UAAM,kBAAkB,OAAO,oBAAoB,CAAC,EAAE,UAAU,SAAS,KAAK,MAAM;AAClF,YAAM,WAAgC;AAAA,QACpC;AAAA,MACF;AAGA,UAAI,MAAM;AACR,iBAAS,WAAW;AAAA,MACtB;AAEA,aAAO,KAAK,UAAU,QAAQ;AAAA,IAChC;AAGA,UAAM,aAAa,EAAE,GAAG,OAAO;AAC/B,WAAO,WAAW;AAClB,WAAO,WAAW;AAClB,WAAO,WAAW;AAClB,WAAO,WAAW;AAElB,UAAM;AAAA,MACJ,KAAK;AAAA,MACL,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,aAAa,OAAO;AAAA,MACtB;AAAA,MACA;AAAA,MACA,WAAW;AAAA;AAAA,MACX,gBAAgB;AAAA;AAAA,MAChB,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@loglayer/transport-logflare",
3
+ "description": "Logflare transport for the LogLayer logging library.",
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "exports": {
9
+ "import": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "require": {
14
+ "types": "./dist/index.d.cts",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "types": "./dist/index.d.ts",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/loglayer/loglayer.git",
23
+ "directory": "packages/transports/logflare"
24
+ },
25
+ "author": "Theo Gravity <theo@suteki.nu>",
26
+ "keywords": [
27
+ "logging",
28
+ "log",
29
+ "loglayer",
30
+ "logflare",
31
+ "transport"
32
+ ],
33
+ "dependencies": {
34
+ "@loglayer/transport-http": "1.1.0"
35
+ },
36
+ "devDependencies": {
37
+ "dotenv": "17.2.3",
38
+ "@types/node": "24.6.1",
39
+ "serialize-error": "12.0.0",
40
+ "tsx": "4.20.6",
41
+ "tsup": "8.5.0",
42
+ "typescript": "5.9.3",
43
+ "vitest": "3.2.4",
44
+ "@loglayer/transport": "2.3.3",
45
+ "loglayer": "6.8.3",
46
+ "@internal/tsconfig": "2.1.0"
47
+ },
48
+ "bugs": "https://github.com/loglayer/loglayer/issues",
49
+ "engines": {
50
+ "node": ">=18"
51
+ },
52
+ "files": [
53
+ "dist"
54
+ ],
55
+ "homepage": "https://loglayer.dev",
56
+ "scripts": {
57
+ "build": "tsup src/index.ts",
58
+ "test": "vitest --run",
59
+ "clean": "rm -rf .turbo node_modules dist",
60
+ "lint": "biome check --no-errors-on-unmatched --write --unsafe src",
61
+ "lint:staged": "biome check --no-errors-on-unmatched --write --unsafe --staged src",
62
+ "verify-types": "tsc --noEmit",
63
+ "livetest": "tsx src/__tests__/livetest.ts"
64
+ }
65
+ }