@loglayer/transport-posthog 0.0.1
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 +21 -0
- package/README.md +48 -0
- package/dist/index.cjs +23 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +22 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Theo Gravity
|
|
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,48 @@
|
|
|
1
|
+
# PostHog Transport for LogLayer
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@loglayer/transport-posthog)
|
|
4
|
+
[](https://www.npmjs.com/package/@loglayer/transport-posthog)
|
|
5
|
+
[](http://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
The PostHog transport for the [LogLayer](https://loglayer.dev) logging library.
|
|
8
|
+
|
|
9
|
+
[posthog-js](https://posthog.com/docs/logs/installation/javascript) is PostHog's official JavaScript logging SDK.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install loglayer @loglayer/transport-posthog posthog-js serialize-error
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { posthog } from 'posthog-js'
|
|
21
|
+
import { serializeError } from 'serialize-error'
|
|
22
|
+
import { LogLayer } from 'loglayer'
|
|
23
|
+
import { PosthogTransport } from "@loglayer/transport-posthog"
|
|
24
|
+
|
|
25
|
+
// Initialize PostHog with logs configuration
|
|
26
|
+
posthog.init('<ph_project_token>', {
|
|
27
|
+
api_host: 'https://us.i.posthog.com',
|
|
28
|
+
defaults: '2026-01-30',
|
|
29
|
+
logs: {
|
|
30
|
+
serviceName: 'my-app',
|
|
31
|
+
environment: 'production',
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const log = new LogLayer({
|
|
36
|
+
transport: new PosthogTransport({
|
|
37
|
+
logger: posthog,
|
|
38
|
+
}),
|
|
39
|
+
errorSerializer: serializeError,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
log.info('hello from LogLayer')
|
|
43
|
+
log.withMetadata({ order_id: 'ord_123' }).info('checkout completed')
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Documentation
|
|
47
|
+
|
|
48
|
+
For more details, visit [https://loglayer.dev/transports/posthog](https://loglayer.dev/transports/posthog)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _loglayer_transport = require("@loglayer/transport");
|
|
3
|
+
//#region src/PosthogTransport.ts
|
|
4
|
+
/**
|
|
5
|
+
* Transport that sends logs to PostHog via the posthog-js SDK's structured logger.
|
|
6
|
+
*
|
|
7
|
+
* Requires an initialized PostHog client instance with the `logs` configuration set.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://posthog.com/docs/logs/installation/javascript}
|
|
10
|
+
*/
|
|
11
|
+
var PosthogTransport = class extends _loglayer_transport.BaseTransport {
|
|
12
|
+
shipToLogger(params) {
|
|
13
|
+
const { logLevel, messages, data, hasData } = params;
|
|
14
|
+
const message = messages.join(" ");
|
|
15
|
+
const logger = this.logger.logger;
|
|
16
|
+
const method = logLevel;
|
|
17
|
+
if (hasData && data) logger[method](message, data);
|
|
18
|
+
else logger[method](message);
|
|
19
|
+
return messages;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.PosthogTransport = PosthogTransport;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseTransport, LogLayerTransportParams } from "@loglayer/transport";
|
|
2
|
+
import { PostHog } from "posthog-js";
|
|
3
|
+
|
|
4
|
+
//#region src/PosthogTransport.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Transport that sends logs to PostHog via the posthog-js SDK's structured logger.
|
|
7
|
+
*
|
|
8
|
+
* Requires an initialized PostHog client instance with the `logs` configuration set.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://posthog.com/docs/logs/installation/javascript}
|
|
11
|
+
*/
|
|
12
|
+
declare class PosthogTransport extends BaseTransport<PostHog> {
|
|
13
|
+
shipToLogger(params: LogLayerTransportParams): any[];
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { PosthogTransport };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseTransport, LogLayerTransportParams } from "@loglayer/transport";
|
|
2
|
+
import { PostHog } from "posthog-js";
|
|
3
|
+
|
|
4
|
+
//#region src/PosthogTransport.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Transport that sends logs to PostHog via the posthog-js SDK's structured logger.
|
|
7
|
+
*
|
|
8
|
+
* Requires an initialized PostHog client instance with the `logs` configuration set.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://posthog.com/docs/logs/installation/javascript}
|
|
11
|
+
*/
|
|
12
|
+
declare class PosthogTransport extends BaseTransport<PostHog> {
|
|
13
|
+
shipToLogger(params: LogLayerTransportParams): any[];
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { PosthogTransport };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseTransport } from "@loglayer/transport";
|
|
2
|
+
//#region src/PosthogTransport.ts
|
|
3
|
+
/**
|
|
4
|
+
* Transport that sends logs to PostHog via the posthog-js SDK's structured logger.
|
|
5
|
+
*
|
|
6
|
+
* Requires an initialized PostHog client instance with the `logs` configuration set.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link https://posthog.com/docs/logs/installation/javascript}
|
|
9
|
+
*/
|
|
10
|
+
var PosthogTransport = class extends BaseTransport {
|
|
11
|
+
shipToLogger(params) {
|
|
12
|
+
const { logLevel, messages, data, hasData } = params;
|
|
13
|
+
const message = messages.join(" ");
|
|
14
|
+
const logger = this.logger.logger;
|
|
15
|
+
const method = logLevel;
|
|
16
|
+
if (hasData && data) logger[method](message, data);
|
|
17
|
+
else logger[method](message);
|
|
18
|
+
return messages;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { PosthogTransport };
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@loglayer/transport-posthog",
|
|
3
|
+
"description": "PostHog transport for the LogLayer logging library.",
|
|
4
|
+
"version": "0.0.1",
|
|
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
|
+
"sideEffects": false,
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/loglayer/loglayer.git",
|
|
24
|
+
"directory": "packages/transports/posthog"
|
|
25
|
+
},
|
|
26
|
+
"author": "Theo Gravity <theo@suteki.nu>",
|
|
27
|
+
"keywords": [
|
|
28
|
+
"logging",
|
|
29
|
+
"log",
|
|
30
|
+
"loglayer",
|
|
31
|
+
"posthog",
|
|
32
|
+
"posthog logs",
|
|
33
|
+
"browser",
|
|
34
|
+
"transport"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsdown src/index.ts",
|
|
38
|
+
"test": "vitest --run",
|
|
39
|
+
"clean": "rm -rf .turbo node_modules dist",
|
|
40
|
+
"lint": "biome check --no-errors-on-unmatched --write --unsafe src",
|
|
41
|
+
"lint:staged": "biome check --no-errors-on-unmatched --write --unsafe --staged src",
|
|
42
|
+
"verify-types": "tsc --noEmit"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@loglayer/transport": "workspace:*"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@internal/tsconfig": "workspace:*",
|
|
49
|
+
"@types/node": "25.9.1",
|
|
50
|
+
"global-jsdom": "29.0.0",
|
|
51
|
+
"loglayer": "workspace:*",
|
|
52
|
+
"posthog-js": "1.376.4",
|
|
53
|
+
"serialize-error": "13.0.1",
|
|
54
|
+
"tsdown": "0.22.1",
|
|
55
|
+
"typescript": "6.0.3",
|
|
56
|
+
"vitest": "4.1.7"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"posthog-js": ">=1.368.0"
|
|
60
|
+
},
|
|
61
|
+
"bugs": "https://github.com/loglayer/loglayer/issues",
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=18"
|
|
64
|
+
},
|
|
65
|
+
"files": [
|
|
66
|
+
"dist"
|
|
67
|
+
],
|
|
68
|
+
"homepage": "https://loglayer.dev",
|
|
69
|
+
"packageManager": "pnpm@10.20.0"
|
|
70
|
+
}
|