@cedvict/http-guardian-plugin-logger 0.0.1-next.10 → 0.0.1-next.8

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.
Files changed (2) hide show
  1. package/README.md +1 -54
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,62 +1,9 @@
1
1
  # @cedvict/http-guardian-plugin-logger
2
2
 
3
- Logger plugin for http-guardian. Adds a guard that logs request / response /
4
- error events to a `LoggerSink` (defaults to `console`).
3
+ Logger plugin for http-guardian.
5
4
 
6
5
  ## Usage
7
6
 
8
7
  ```ts
9
8
  import { loggerPlugin } from "@cedvict/http-guardian-plugin-logger";
10
- import { createHttpClient, createApiParserStructured, bearerAuth } from "@cedvict/http-guardian";
11
-
12
- const api = createHttpClient({
13
- baseUrl: "https://api.example.com",
14
- auth: bearerAuth(() => token),
15
- parser: createApiParserStructured(),
16
- plugins: [loggerPlugin({ label: "api" })],
17
- });
18
9
  ```
19
-
20
- Custom sink (e.g. pino, winston, browser-side ring buffer):
21
-
22
- ```ts
23
- loggerPlugin({
24
- sink: {
25
- log: (label, payload) => myStructuredLogger.info({ label, ...payload }),
26
- error: (label, payload) => myStructuredLogger.error({ label, ...payload }),
27
- },
28
- });
29
- ```
30
-
31
- ## Combining with `correlationIdGuard`
32
-
33
- When [`correlationIdGuard`](../http-guardian) is active, the resolved
34
- `correlationId` lives on `ctx.meta.correlationId`. Surface it in your structured
35
- logs by writing a small wrapper guard that reads `ctx.meta` and forwards
36
- the field:
37
-
38
- ```ts
39
- import { correlationIdGuard, type Guard } from "@cedvict/http-guardian";
40
-
41
- const correlationLog: Guard = async (ctx, next) => {
42
- const res = await next(ctx);
43
- myStructuredLogger.info({
44
- method: ctx.method,
45
- url: ctx.url,
46
- status: res.status,
47
- correlation_id: ctx.meta?.correlationId,
48
- trace_id: ctx.meta?.traceId,
49
- });
50
- return res;
51
- };
52
-
53
- createHttpClient({
54
- // ...
55
- guards: [correlationIdGuard(), correlationLog],
56
- plugins: [loggerPlugin()],
57
- });
58
- ```
59
-
60
- This pattern keeps `loggerPlugin` framework-agnostic while letting you ship the
61
- correlation/trace fields straight into your structured-log pipeline (Datadog,
62
- Loki, ELK, etc.).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedvict/http-guardian-plugin-logger",
3
- "version": "0.0.1-next.10",
3
+ "version": "0.0.1-next.8",
4
4
  "description": "Logger plugin for http-guardian.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -53,6 +53,6 @@
53
53
  "@typescript-eslint/eslint-plugin": "^8.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@cedvict/http-guardian": "^0.0.1-next.10"
56
+ "@cedvict/http-guardian": "^0.0.1-next.8"
57
57
  }
58
58
  }