@contractspec/lib.logger 1.56.1 → 1.58.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.
Files changed (108) hide show
  1. package/dist/context.browser.d.ts +44 -0
  2. package/dist/context.browser.d.ts.map +1 -0
  3. package/dist/context.browser.js +77 -0
  4. package/dist/context.d.ts +22 -0
  5. package/dist/context.d.ts.map +1 -0
  6. package/dist/context.js +1 -0
  7. package/dist/context.node.d.ts +43 -0
  8. package/dist/context.node.d.ts.map +1 -0
  9. package/dist/context.node.js +62 -0
  10. package/dist/elysia-plugin.d.ts +58 -0
  11. package/dist/elysia-plugin.d.ts.map +1 -0
  12. package/dist/elysia-plugin.js +793 -0
  13. package/dist/formatters.d.ts +25 -0
  14. package/dist/formatters.d.ts.map +1 -0
  15. package/dist/formatters.js +232 -0
  16. package/dist/index.browser.d.ts +8 -0
  17. package/dist/index.browser.d.ts.map +1 -0
  18. package/dist/index.browser.js +728 -0
  19. package/dist/index.d.ts +9 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +800 -0
  22. package/dist/logger.browser.d.ts +48 -0
  23. package/dist/logger.browser.d.ts.map +1 -0
  24. package/dist/logger.browser.js +722 -0
  25. package/dist/logger.d.ts +2 -0
  26. package/dist/logger.d.ts.map +1 -0
  27. package/dist/logger.js +707 -0
  28. package/dist/logger.node.d.ts +48 -0
  29. package/dist/logger.node.d.ts.map +1 -0
  30. package/dist/logger.node.js +707 -0
  31. package/dist/node/context.js +0 -0
  32. package/dist/node/context.node.js +61 -0
  33. package/dist/node/elysia-plugin.js +792 -0
  34. package/dist/node/formatters.js +231 -0
  35. package/dist/node/index.js +799 -0
  36. package/dist/node/logger.js +706 -0
  37. package/dist/node/logger.node.js +706 -0
  38. package/dist/node/timer.js +122 -0
  39. package/dist/node/tracer.js +274 -0
  40. package/dist/node/tracer.node.js +274 -0
  41. package/dist/node/types.js +13 -0
  42. package/dist/timer.d.ts +99 -0
  43. package/dist/timer.d.ts.map +1 -0
  44. package/dist/timer.js +123 -0
  45. package/dist/tracer.browser.d.ts +47 -0
  46. package/dist/tracer.browser.d.ts.map +1 -0
  47. package/dist/tracer.browser.js +290 -0
  48. package/dist/tracer.d.ts +2 -0
  49. package/dist/tracer.d.ts.map +1 -0
  50. package/dist/tracer.js +275 -0
  51. package/dist/tracer.node.d.ts +47 -0
  52. package/dist/tracer.node.d.ts.map +1 -0
  53. package/dist/tracer.node.js +275 -0
  54. package/dist/types.d.ts +68 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/types.js +14 -0
  57. package/package.json +112 -42
  58. package/dist/context.browser.d.mts +0 -49
  59. package/dist/context.browser.d.mts.map +0 -1
  60. package/dist/context.browser.mjs +0 -89
  61. package/dist/context.browser.mjs.map +0 -1
  62. package/dist/context.d.mts +0 -17
  63. package/dist/context.d.mts.map +0 -1
  64. package/dist/context.mjs +0 -1
  65. package/dist/context.node.d.mts +0 -48
  66. package/dist/context.node.d.mts.map +0 -1
  67. package/dist/context.node.mjs +0 -79
  68. package/dist/context.node.mjs.map +0 -1
  69. package/dist/elysia-plugin.d.mts +0 -63
  70. package/dist/elysia-plugin.d.mts.map +0 -1
  71. package/dist/elysia-plugin.mjs +0 -84
  72. package/dist/elysia-plugin.mjs.map +0 -1
  73. package/dist/formatters.d.mts +0 -29
  74. package/dist/formatters.d.mts.map +0 -1
  75. package/dist/formatters.mjs +0 -180
  76. package/dist/formatters.mjs.map +0 -1
  77. package/dist/index.browser.d.mts +0 -7
  78. package/dist/index.browser.mjs +0 -8
  79. package/dist/index.d.mts +0 -8
  80. package/dist/index.mjs +0 -9
  81. package/dist/logger.browser.d.mts +0 -51
  82. package/dist/logger.browser.d.mts.map +0 -1
  83. package/dist/logger.browser.mjs +0 -190
  84. package/dist/logger.browser.mjs.map +0 -1
  85. package/dist/logger.d.mts +0 -2
  86. package/dist/logger.mjs +0 -3
  87. package/dist/logger.node.d.mts +0 -51
  88. package/dist/logger.node.d.mts.map +0 -1
  89. package/dist/logger.node.mjs +0 -190
  90. package/dist/logger.node.mjs.map +0 -1
  91. package/dist/timer.d.mts +0 -103
  92. package/dist/timer.d.mts.map +0 -1
  93. package/dist/timer.mjs +0 -165
  94. package/dist/timer.mjs.map +0 -1
  95. package/dist/tracer.browser.d.mts +0 -51
  96. package/dist/tracer.browser.d.mts.map +0 -1
  97. package/dist/tracer.browser.mjs +0 -116
  98. package/dist/tracer.browser.mjs.map +0 -1
  99. package/dist/tracer.d.mts +0 -2
  100. package/dist/tracer.mjs +0 -3
  101. package/dist/tracer.node.d.mts +0 -51
  102. package/dist/tracer.node.d.mts.map +0 -1
  103. package/dist/tracer.node.mjs +0 -116
  104. package/dist/tracer.node.mjs.map +0 -1
  105. package/dist/types.d.mts +0 -71
  106. package/dist/types.d.mts.map +0 -1
  107. package/dist/types.mjs +0 -14
  108. package/dist/types.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractspec/lib.logger",
3
- "version": "1.56.1",
3
+ "version": "1.58.0",
4
4
  "description": "Comprehensive logging library optimized for Bun with ElysiaJS integration",
5
5
  "keywords": [
6
6
  "contractspec",
@@ -18,16 +18,17 @@
18
18
  "lint:check": "eslint src",
19
19
  "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
20
20
  "publish:pkg:canary": "bun publish:pkg --tag canary",
21
- "build": "bun build:types && bun build:bundle",
22
- "build:bundle": "tsdown",
23
- "build:types": "tsc --noEmit",
24
- "dev": "bun build:bundle --watch"
21
+ "build": "bun run prebuild && bun run build:bundle && bun run build:types",
22
+ "build:bundle": "contractspec-bun-build transpile",
23
+ "build:types": "contractspec-bun-build types",
24
+ "dev": "contractspec-bun-build dev",
25
+ "prebuild": "contractspec-bun-build prebuild",
26
+ "typecheck": "tsc --noEmit"
25
27
  },
26
28
  "devDependencies": {
27
- "@contractspec/tool.typescript": "1.56.1",
28
- "@contractspec/tool.tsdown": "1.56.1",
29
- "tsdown": "^0.19.0",
30
- "typescript": "^5.9.3"
29
+ "@contractspec/tool.typescript": "1.58.0",
30
+ "typescript": "^5.9.3",
31
+ "@contractspec/tool.bun": "1.57.0"
31
32
  },
32
33
  "peerDependencies": {
33
34
  "elysia": ">=1.0.0"
@@ -40,48 +41,117 @@
40
41
  "dependencies": {
41
42
  "zone.js": "^0.16.0"
42
43
  },
43
- "types": "./dist/index.d.mts",
44
+ "types": "./dist/index.d.ts",
44
45
  "files": [
45
46
  "dist",
46
47
  "README.md"
47
48
  ],
48
49
  "exports": {
49
- ".": "./dist/index.mjs",
50
- "./context": "./dist/context.mjs",
51
- "./context.browser": "./dist/context.browser.mjs",
52
- "./context.node": "./dist/context.node.mjs",
53
- "./elysia-plugin": "./dist/elysia-plugin.mjs",
54
- "./formatters": "./dist/formatters.mjs",
55
- "./index.browser": "./dist/index.browser.mjs",
56
- "./logger": "./dist/logger.mjs",
57
- "./logger.browser": "./dist/logger.browser.mjs",
58
- "./logger.node": "./dist/logger.node.mjs",
59
- "./timer": "./dist/timer.mjs",
60
- "./tracer": "./dist/tracer.mjs",
61
- "./tracer.browser": "./dist/tracer.browser.mjs",
62
- "./tracer.node": "./dist/tracer.node.mjs",
63
- "./types": "./dist/types.mjs",
64
- "./*": "./*"
50
+ ".": "./src/index.ts",
51
+ "./context": "./src/context.ts",
52
+ "./context.browser": "./src/context.browser.ts",
53
+ "./context.node": "./src/context.node.ts",
54
+ "./elysia-plugin": "./src/elysia-plugin.ts",
55
+ "./formatters": "./src/formatters.ts",
56
+ "./index.browser": "./src/index.browser.ts",
57
+ "./logger": "./src/logger.ts",
58
+ "./logger.browser": "./src/logger.browser.ts",
59
+ "./logger.node": "./src/logger.node.ts",
60
+ "./timer": "./src/timer.ts",
61
+ "./tracer": "./src/tracer.ts",
62
+ "./tracer.browser": "./src/tracer.browser.ts",
63
+ "./tracer.node": "./src/tracer.node.ts",
64
+ "./types": "./src/types.ts"
65
65
  },
66
66
  "publishConfig": {
67
67
  "access": "public",
68
68
  "exports": {
69
- ".": "./dist/index.mjs",
70
- "./context": "./dist/context.mjs",
71
- "./context.browser": "./dist/context.browser.mjs",
72
- "./context.node": "./dist/context.node.mjs",
73
- "./elysia-plugin": "./dist/elysia-plugin.mjs",
74
- "./formatters": "./dist/formatters.mjs",
75
- "./index.browser": "./dist/index.browser.mjs",
76
- "./logger": "./dist/logger.mjs",
77
- "./logger.browser": "./dist/logger.browser.mjs",
78
- "./logger.node": "./dist/logger.node.mjs",
79
- "./timer": "./dist/timer.mjs",
80
- "./tracer": "./dist/tracer.mjs",
81
- "./tracer.browser": "./dist/tracer.browser.mjs",
82
- "./tracer.node": "./dist/tracer.node.mjs",
83
- "./types": "./dist/types.mjs",
84
- "./*": "./*"
69
+ ".": {
70
+ "types": "./dist/index.d.ts",
71
+ "bun": "./dist/index.browser.js",
72
+ "node": "./dist/node/index.mjs",
73
+ "default": "./dist/index.browser.js"
74
+ },
75
+ "./context": {
76
+ "types": "./dist/context.d.ts",
77
+ "bun": "./dist/context.node.js",
78
+ "node": "./dist/node/context.node.mjs",
79
+ "default": "./dist/context.node.js"
80
+ },
81
+ "./context.browser": {
82
+ "types": "./dist/context.browser.d.ts",
83
+ "bun": "./dist/context.browser.js",
84
+ "default": "./dist/context.browser.js"
85
+ },
86
+ "./context.node": {
87
+ "types": "./dist/context.node.d.ts",
88
+ "bun": "./dist/context.node.js",
89
+ "node": "./dist/node/context.node.mjs",
90
+ "default": "./dist/context.node.js"
91
+ },
92
+ "./elysia-plugin": {
93
+ "types": "./dist/elysia-plugin.d.ts",
94
+ "bun": "./dist/elysia-plugin.js",
95
+ "node": "./dist/node/elysia-plugin.mjs",
96
+ "default": "./dist/elysia-plugin.js"
97
+ },
98
+ "./formatters": {
99
+ "types": "./dist/formatters.d.ts",
100
+ "bun": "./dist/formatters.js",
101
+ "node": "./dist/node/formatters.mjs",
102
+ "default": "./dist/formatters.js"
103
+ },
104
+ "./index.browser": {
105
+ "types": "./dist/index.browser.d.ts",
106
+ "bun": "./dist/index.browser.js",
107
+ "default": "./dist/index.browser.js"
108
+ },
109
+ "./logger": {
110
+ "types": "./dist/logger.d.ts",
111
+ "bun": "./dist/logger.node.js",
112
+ "node": "./dist/node/logger.node.mjs",
113
+ "default": "./dist/logger.node.js"
114
+ },
115
+ "./logger.browser": {
116
+ "types": "./dist/logger.browser.d.ts",
117
+ "bun": "./dist/logger.browser.js",
118
+ "default": "./dist/logger.browser.js"
119
+ },
120
+ "./logger.node": {
121
+ "types": "./dist/logger.node.d.ts",
122
+ "bun": "./dist/logger.node.js",
123
+ "node": "./dist/node/logger.node.mjs",
124
+ "default": "./dist/logger.node.js"
125
+ },
126
+ "./timer": {
127
+ "types": "./dist/timer.d.ts",
128
+ "bun": "./dist/timer.js",
129
+ "node": "./dist/node/timer.mjs",
130
+ "default": "./dist/timer.js"
131
+ },
132
+ "./tracer": {
133
+ "types": "./dist/tracer.d.ts",
134
+ "bun": "./dist/tracer.node.js",
135
+ "node": "./dist/node/tracer.node.mjs",
136
+ "default": "./dist/tracer.node.js"
137
+ },
138
+ "./tracer.browser": {
139
+ "types": "./dist/tracer.browser.d.ts",
140
+ "bun": "./dist/tracer.browser.js",
141
+ "default": "./dist/tracer.browser.js"
142
+ },
143
+ "./tracer.node": {
144
+ "types": "./dist/tracer.node.d.ts",
145
+ "bun": "./dist/tracer.node.js",
146
+ "node": "./dist/node/tracer.node.mjs",
147
+ "default": "./dist/tracer.node.js"
148
+ },
149
+ "./types": {
150
+ "types": "./dist/types.d.ts",
151
+ "bun": "./dist/types.js",
152
+ "node": "./dist/node/types.mjs",
153
+ "default": "./dist/types.js"
154
+ }
85
155
  },
86
156
  "registry": "https://registry.npmjs.org/"
87
157
  },
@@ -1,49 +0,0 @@
1
- import { ContextData, TraceContext } from "./types.mjs";
2
- import "zone.js";
3
-
4
- //#region src/context.browser.d.ts
5
-
6
- /**
7
- * Browser implementation of LogContext using Zone.js for async context
8
- * propagation (similar to AsyncLocalStorage in Node).
9
- */
10
- declare class LogContext {
11
- private static instance;
12
- private static fallbackCounter;
13
- static getInstance(): LogContext;
14
- /**
15
- * Run a function with a new context
16
- */
17
- run<T>(context: ContextData, fn: () => T): T;
18
- /**
19
- * Run a function with an extended context (merges with current)
20
- */
21
- extend<T>(additionalContext: Partial<ContextData>, fn: () => T): T;
22
- /**
23
- * Set context data for the current execution context
24
- */
25
- set(key: string, value: unknown): void;
26
- /**
27
- * Get a specific context value
28
- */
29
- get<T>(key: string): T | undefined;
30
- /**
31
- * Get all context data
32
- */
33
- getContext(): ContextData;
34
- /**
35
- * Set trace context
36
- */
37
- setTrace(trace: TraceContext): void;
38
- /**
39
- * Get current trace context
40
- */
41
- getCurrentTrace(): TraceContext | undefined;
42
- /**
43
- * Generate a unique ID for requests/operations
44
- */
45
- generateId(): string;
46
- }
47
- //#endregion
48
- export { LogContext };
49
- //# sourceMappingURL=context.browser.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.browser.d.mts","names":[],"sources":["../src/context.browser.ts"],"sourcesContent":[],"mappings":";;;;;;;AAmCA;;AAckB,cAdL,UAAA,CAcK;EAAuB,eAAA,QAAA;EAAI,eAAA,eAAA;EAqBN,OAAA,WAAA,CAAA,CAAA,EA/Bf,UA+Be;EAAR;;;EAsBR,GAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EA3CL,WA2CK,EAAA,EAAA,EAAA,GAAA,GA3CkB,CA2ClB,CAAA,EA3CsB,CA2CtB;EAQP;;;EAkBiB,MAAA,CAAA,CAAA,CAAA,CAAA,iBAAA,EAhDF,OAgDE,CAhDM,WAgDN,CAAA,EAAA,EAAA,EAAA,GAAA,GAhD8B,CAgD9B,CAAA,EAhDkC,CAgDlC;;;;;;;;uBA1BV;;;;gBAQP;;;;kBAQE;;;;qBAUG"}
@@ -1,89 +0,0 @@
1
- import "zone.js";
2
-
3
- //#region src/context.browser.ts
4
- const ZONE = globalThis.Zone;
5
- const STORE_KEY = "__lssm_log_context_data__";
6
- function getStore() {
7
- if (!ZONE) return void 0;
8
- return ZONE.current.get(STORE_KEY);
9
- }
10
- /**
11
- * Browser implementation of LogContext using Zone.js for async context
12
- * propagation (similar to AsyncLocalStorage in Node).
13
- */
14
- var LogContext = class LogContext {
15
- static instance;
16
- static fallbackCounter = 0;
17
- static getInstance() {
18
- if (!LogContext.instance) LogContext.instance = new LogContext();
19
- return LogContext.instance;
20
- }
21
- /**
22
- * Run a function with a new context
23
- */
24
- run(context, fn) {
25
- const contextData = {
26
- context: { ...context },
27
- trace: this.getCurrentTrace()
28
- };
29
- if (!ZONE) return fn();
30
- return ZONE.current.fork({
31
- name: "log-context",
32
- properties: { [STORE_KEY]: contextData }
33
- }).run(fn);
34
- }
35
- /**
36
- * Run a function with an extended context (merges with current)
37
- */
38
- extend(additionalContext, fn) {
39
- const mergedContext = {
40
- ...this.getContext(),
41
- ...additionalContext
42
- };
43
- return this.run(mergedContext, fn);
44
- }
45
- /**
46
- * Set context data for the current execution context
47
- */
48
- set(key, value) {
49
- const current = getStore();
50
- if (current) current.context[key] = value;
51
- }
52
- /**
53
- * Get a specific context value
54
- */
55
- get(key) {
56
- return getStore()?.context?.[key];
57
- }
58
- /**
59
- * Get all context data
60
- */
61
- getContext() {
62
- return getStore()?.context || {};
63
- }
64
- /**
65
- * Set trace context
66
- */
67
- setTrace(trace) {
68
- const current = getStore();
69
- if (current) current.trace = trace;
70
- }
71
- /**
72
- * Get current trace context
73
- */
74
- getCurrentTrace() {
75
- return getStore()?.trace;
76
- }
77
- /**
78
- * Generate a unique ID for requests/operations
79
- */
80
- generateId() {
81
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
82
- LogContext.fallbackCounter += 1;
83
- return `log-${LogContext.fallbackCounter}`;
84
- }
85
- };
86
-
87
- //#endregion
88
- export { LogContext };
89
- //# sourceMappingURL=context.browser.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.browser.mjs","names":[],"sources":["../src/context.browser.ts"],"sourcesContent":["import 'zone.js';\nimport type { ContextData, TraceContext } from './types';\n\ninterface LogContextData {\n context: ContextData;\n trace?: TraceContext;\n}\n\ninterface ZoneForkSpec {\n name?: string;\n properties?: Record<string, unknown>;\n}\n\ninterface ZoneLike {\n fork(spec: ZoneForkSpec): ZoneLike;\n run<T>(fn: () => T): T;\n get<T>(key: string): T | undefined;\n}\n\ninterface ZoneStaticLike {\n current: ZoneLike;\n}\n\nconst ZONE = (globalThis as unknown as { Zone?: ZoneStaticLike }).Zone;\nconst STORE_KEY = '__lssm_log_context_data__';\n\nfunction getStore(): LogContextData | undefined {\n if (!ZONE) return undefined;\n return ZONE.current.get<LogContextData>(STORE_KEY);\n}\n\n/**\n * Browser implementation of LogContext using Zone.js for async context\n * propagation (similar to AsyncLocalStorage in Node).\n */\nexport class LogContext {\n private static instance: LogContext;\n private static fallbackCounter = 0;\n\n static getInstance(): LogContext {\n if (!LogContext.instance) {\n LogContext.instance = new LogContext();\n }\n return LogContext.instance;\n }\n\n /**\n * Run a function with a new context\n */\n run<T>(context: ContextData, fn: () => T): T {\n const contextData: LogContextData = {\n context: { ...context },\n trace: this.getCurrentTrace(),\n };\n\n if (!ZONE) {\n return fn();\n }\n\n const zone = ZONE.current.fork({\n name: 'log-context',\n properties: { [STORE_KEY]: contextData },\n });\n\n return zone.run(fn);\n }\n\n /**\n * Run a function with an extended context (merges with current)\n */\n extend<T>(additionalContext: Partial<ContextData>, fn: () => T): T {\n const currentContext = this.getContext();\n const mergedContext: ContextData = {\n ...currentContext,\n ...additionalContext,\n };\n return this.run(mergedContext, fn);\n }\n\n /**\n * Set context data for the current execution context\n */\n set(key: string, value: unknown): void {\n const current = getStore();\n if (current) {\n current.context[key] = value;\n }\n }\n\n /**\n * Get a specific context value\n */\n get<T>(key: string): T | undefined {\n const current = getStore();\n return current?.context?.[key] as T | undefined;\n }\n\n /**\n * Get all context data\n */\n getContext(): ContextData {\n const current = getStore();\n return current?.context || {};\n }\n\n /**\n * Set trace context\n */\n setTrace(trace: TraceContext): void {\n const current = getStore();\n if (current) {\n current.trace = trace;\n }\n }\n\n /**\n * Get current trace context\n */\n getCurrentTrace(): TraceContext | undefined {\n const current = getStore();\n return current?.trace;\n }\n\n /**\n * Generate a unique ID for requests/operations\n */\n generateId(): string {\n if (\n typeof crypto !== 'undefined' &&\n typeof (crypto as unknown as { randomUUID?: unknown }).randomUUID ===\n 'function'\n ) {\n return crypto.randomUUID();\n }\n\n LogContext.fallbackCounter += 1;\n return `log-${LogContext.fallbackCounter}`;\n }\n}\n"],"mappings":";;;AAuBA,MAAM,OAAQ,WAAoD;AAClE,MAAM,YAAY;AAElB,SAAS,WAAuC;AAC9C,KAAI,CAAC,KAAM,QAAO;AAClB,QAAO,KAAK,QAAQ,IAAoB,UAAU;;;;;;AAOpD,IAAa,aAAb,MAAa,WAAW;CACtB,OAAe;CACf,OAAe,kBAAkB;CAEjC,OAAO,cAA0B;AAC/B,MAAI,CAAC,WAAW,SACd,YAAW,WAAW,IAAI,YAAY;AAExC,SAAO,WAAW;;;;;CAMpB,IAAO,SAAsB,IAAgB;EAC3C,MAAM,cAA8B;GAClC,SAAS,EAAE,GAAG,SAAS;GACvB,OAAO,KAAK,iBAAiB;GAC9B;AAED,MAAI,CAAC,KACH,QAAO,IAAI;AAQb,SALa,KAAK,QAAQ,KAAK;GAC7B,MAAM;GACN,YAAY,GAAG,YAAY,aAAa;GACzC,CAAC,CAEU,IAAI,GAAG;;;;;CAMrB,OAAU,mBAAyC,IAAgB;EAEjE,MAAM,gBAA6B;GACjC,GAFqB,KAAK,YAAY;GAGtC,GAAG;GACJ;AACD,SAAO,KAAK,IAAI,eAAe,GAAG;;;;;CAMpC,IAAI,KAAa,OAAsB;EACrC,MAAM,UAAU,UAAU;AAC1B,MAAI,QACF,SAAQ,QAAQ,OAAO;;;;;CAO3B,IAAO,KAA4B;AAEjC,SADgB,UAAU,EACV,UAAU;;;;;CAM5B,aAA0B;AAExB,SADgB,UAAU,EACV,WAAW,EAAE;;;;;CAM/B,SAAS,OAA2B;EAClC,MAAM,UAAU,UAAU;AAC1B,MAAI,QACF,SAAQ,QAAQ;;;;;CAOpB,kBAA4C;AAE1C,SADgB,UAAU,EACV;;;;;CAMlB,aAAqB;AACnB,MACE,OAAO,WAAW,eAClB,OAAQ,OAA+C,eACrD,WAEF,QAAO,OAAO,YAAY;AAG5B,aAAW,mBAAmB;AAC9B,SAAO,OAAO,WAAW"}
@@ -1,17 +0,0 @@
1
- import { ContextData, TraceContext } from "./types.mjs";
2
-
3
- //#region src/context.d.ts
4
-
5
- interface LogContextApi {
6
- run<T>(context: ContextData, fn: () => T): T;
7
- extend<T>(additionalContext: Partial<ContextData>, fn: () => T): T;
8
- set(key: string, value: unknown): void;
9
- get<T>(key: string): T | undefined;
10
- getContext(): ContextData;
11
- setTrace(trace: TraceContext): void;
12
- getCurrentTrace(): TraceContext | undefined;
13
- generateId(): string;
14
- }
15
- //#endregion
16
- export { type ContextData, LogContextApi, type TraceContext };
17
- //# sourceMappingURL=context.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.d.mts","names":[],"sources":["../src/context.ts"],"sourcesContent":[],"mappings":";;;;AAmBuB,UAPN,aAAA,CAOM;EAAC,GAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EAPM,WAON,EAAA,EAAA,EAAA,GAAA,GANmC,CAMnC,CAAA,EANuC,CAMvC;EACqB,MAAA,CAAA,CAAA,CAAA,CAAA,iBAAA,EALtB,OAKsB,CAPmB,WAAA,CAOnB,EAAA,EAAA,EAAA,GAAA,GAJ/B,CAI+B,CAAA,EAHxC,CAGwC;EACG,GAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,OAAA,CAAA,EAAA,IAAA;EACG,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAH5B,CAG4B,GAAA,SAAA;gBAH3B;kBACqB;qBACG,YAAA"}
package/dist/context.mjs DELETED
@@ -1 +0,0 @@
1
- export { };
@@ -1,48 +0,0 @@
1
- import { ContextData, TraceContext } from "./types.mjs";
2
-
3
- //#region src/context.node.d.ts
4
-
5
- /**
6
- * Node.js implementation of LogContext using AsyncLocalStorage.
7
- */
8
- declare class LogContext {
9
- private static instance;
10
- private storage;
11
- constructor();
12
- static getInstance(): LogContext;
13
- /**
14
- * Run a function with a new context
15
- */
16
- run<T>(context: ContextData, fn: () => T): T;
17
- /**
18
- * Run a function with an extended context (merges with current)
19
- */
20
- extend<T>(additionalContext: Partial<ContextData>, fn: () => T): T;
21
- /**
22
- * Set context data for the current execution context
23
- */
24
- set(key: string, value: unknown): void;
25
- /**
26
- * Get a specific context value
27
- */
28
- get<T>(key: string): T | undefined;
29
- /**
30
- * Get all context data
31
- */
32
- getContext(): ContextData;
33
- /**
34
- * Set trace context
35
- */
36
- setTrace(trace: TraceContext): void;
37
- /**
38
- * Get current trace context
39
- */
40
- getCurrentTrace(): TraceContext | undefined;
41
- /**
42
- * Generate a unique ID for requests/operations
43
- */
44
- generateId(): string;
45
- }
46
- //#endregion
47
- export { LogContext };
48
- //# sourceMappingURL=context.node.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.node.d.mts","names":[],"sources":["../src/context.node.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;AAQwB,cARX,UAAA,CAQW;EAUN,eAAA,QAAA;EAAuB,QAAA,OAAA;EAAI,WAAA,CAAA;EAWN,OAAA,WAAA,CAAA,CAAA,EArBf,UAqBe;EAAR;;;EAsBR,GAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EAjCL,WAiCK,EAAA,EAAA,EAAA,GAAA,GAjCkB,CAiClB,CAAA,EAjCsB,CAiCtB;EAQP;;;EAkBiB,MAAA,CAAA,CAAA,CAAA,CAAA,iBAAA,EAhDF,OAgDE,CAhDM,WAgDN,CAAA,EAAA,EAAA,EAAA,GAAA,GAhD8B,CAgD9B,CAAA,EAhDkC,CAgDlC;;;;;;;;uBA1BV;;;;gBAQP;;;;kBAQE;;;;qBAUG"}
@@ -1,79 +0,0 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
-
3
- //#region src/context.node.ts
4
- /**
5
- * Node.js implementation of LogContext using AsyncLocalStorage.
6
- */
7
- var LogContext = class LogContext {
8
- static instance;
9
- storage;
10
- constructor() {
11
- this.storage = new AsyncLocalStorage();
12
- }
13
- static getInstance() {
14
- if (!LogContext.instance) LogContext.instance = new LogContext();
15
- return LogContext.instance;
16
- }
17
- /**
18
- * Run a function with a new context
19
- */
20
- run(context, fn) {
21
- const contextData = {
22
- context: { ...context },
23
- trace: this.getCurrentTrace()
24
- };
25
- return this.storage.run(contextData, fn);
26
- }
27
- /**
28
- * Run a function with an extended context (merges with current)
29
- */
30
- extend(additionalContext, fn) {
31
- const mergedContext = {
32
- ...this.getContext(),
33
- ...additionalContext
34
- };
35
- return this.run(mergedContext, fn);
36
- }
37
- /**
38
- * Set context data for the current execution context
39
- */
40
- set(key, value) {
41
- const current = this.storage.getStore();
42
- if (current) current.context[key] = value;
43
- }
44
- /**
45
- * Get a specific context value
46
- */
47
- get(key) {
48
- return this.storage.getStore()?.context?.[key];
49
- }
50
- /**
51
- * Get all context data
52
- */
53
- getContext() {
54
- return this.storage.getStore()?.context || {};
55
- }
56
- /**
57
- * Set trace context
58
- */
59
- setTrace(trace) {
60
- const current = this.storage.getStore();
61
- if (current) current.trace = trace;
62
- }
63
- /**
64
- * Get current trace context
65
- */
66
- getCurrentTrace() {
67
- return this.storage.getStore()?.trace;
68
- }
69
- /**
70
- * Generate a unique ID for requests/operations
71
- */
72
- generateId() {
73
- return crypto.randomUUID();
74
- }
75
- };
76
-
77
- //#endregion
78
- export { LogContext };
79
- //# sourceMappingURL=context.node.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.node.mjs","names":[],"sources":["../src/context.node.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport type { ContextData, TraceContext } from './types';\n\ninterface LogContextData {\n context: ContextData;\n trace?: TraceContext;\n}\n\n/**\n * Node.js implementation of LogContext using AsyncLocalStorage.\n */\nexport class LogContext {\n private static instance: LogContext;\n private storage: AsyncLocalStorage<LogContextData>;\n\n constructor() {\n this.storage = new AsyncLocalStorage<LogContextData>();\n }\n\n static getInstance(): LogContext {\n if (!LogContext.instance) {\n LogContext.instance = new LogContext();\n }\n return LogContext.instance;\n }\n\n /**\n * Run a function with a new context\n */\n run<T>(context: ContextData, fn: () => T): T {\n const contextData: LogContextData = {\n context: { ...context },\n trace: this.getCurrentTrace(),\n };\n return this.storage.run(contextData, fn) as T;\n }\n\n /**\n * Run a function with an extended context (merges with current)\n */\n extend<T>(additionalContext: Partial<ContextData>, fn: () => T): T {\n const currentContext = this.getContext();\n const mergedContext: ContextData = {\n ...currentContext,\n ...additionalContext,\n };\n return this.run(mergedContext, fn);\n }\n\n /**\n * Set context data for the current execution context\n */\n set(key: string, value: unknown): void {\n const current = this.storage.getStore();\n if (current) {\n current.context[key] = value;\n }\n }\n\n /**\n * Get a specific context value\n */\n get<T>(key: string): T | undefined {\n const current = this.storage.getStore();\n return current?.context?.[key] as T | undefined;\n }\n\n /**\n * Get all context data\n */\n getContext(): ContextData {\n const current = this.storage.getStore();\n return current?.context || {};\n }\n\n /**\n * Set trace context\n */\n setTrace(trace: TraceContext): void {\n const current = this.storage.getStore();\n if (current) {\n current.trace = trace;\n }\n }\n\n /**\n * Get current trace context\n */\n getCurrentTrace(): TraceContext | undefined {\n const current = this.storage.getStore();\n return current?.trace;\n }\n\n /**\n * Generate a unique ID for requests/operations\n */\n generateId(): string {\n return crypto.randomUUID();\n }\n}\n"],"mappings":";;;;;;AAWA,IAAa,aAAb,MAAa,WAAW;CACtB,OAAe;CACf,AAAQ;CAER,cAAc;AACZ,OAAK,UAAU,IAAI,mBAAmC;;CAGxD,OAAO,cAA0B;AAC/B,MAAI,CAAC,WAAW,SACd,YAAW,WAAW,IAAI,YAAY;AAExC,SAAO,WAAW;;;;;CAMpB,IAAO,SAAsB,IAAgB;EAC3C,MAAM,cAA8B;GAClC,SAAS,EAAE,GAAG,SAAS;GACvB,OAAO,KAAK,iBAAiB;GAC9B;AACD,SAAO,KAAK,QAAQ,IAAI,aAAa,GAAG;;;;;CAM1C,OAAU,mBAAyC,IAAgB;EAEjE,MAAM,gBAA6B;GACjC,GAFqB,KAAK,YAAY;GAGtC,GAAG;GACJ;AACD,SAAO,KAAK,IAAI,eAAe,GAAG;;;;;CAMpC,IAAI,KAAa,OAAsB;EACrC,MAAM,UAAU,KAAK,QAAQ,UAAU;AACvC,MAAI,QACF,SAAQ,QAAQ,OAAO;;;;;CAO3B,IAAO,KAA4B;AAEjC,SADgB,KAAK,QAAQ,UAAU,EACvB,UAAU;;;;;CAM5B,aAA0B;AAExB,SADgB,KAAK,QAAQ,UAAU,EACvB,WAAW,EAAE;;;;;CAM/B,SAAS,OAA2B;EAClC,MAAM,UAAU,KAAK,QAAQ,UAAU;AACvC,MAAI,QACF,SAAQ,QAAQ;;;;;CAOpB,kBAA4C;AAE1C,SADgB,KAAK,QAAQ,UAAU,EACvB;;;;;CAMlB,aAAqB;AACnB,SAAO,OAAO,YAAY"}
@@ -1,63 +0,0 @@
1
- import { ContextData } from "./types.mjs";
2
- import { Logger } from "./logger.node.mjs";
3
- import * as elysia0 from "elysia";
4
- import { Elysia } from "elysia";
5
-
6
- //#region src/elysia-plugin.d.ts
7
- interface ElysiaLoggerConfig {
8
- logger?: Logger;
9
- logRequests?: boolean;
10
- logResponses?: boolean;
11
- excludePaths?: string[];
12
- }
13
- /**
14
- * Simple ElysiaJS Logger Plugin
15
- * Provides automatic request logging and tracing
16
- */
17
- declare function elysiaLogger<T extends Elysia>(config?: ElysiaLoggerConfig): (app: T) => Elysia<"", {
18
- decorator: {};
19
- store: {};
20
- derive: {};
21
- resolve: {};
22
- }, {
23
- typebox: {};
24
- error: {};
25
- }, {
26
- schema: {};
27
- standaloneSchema: {};
28
- macro: {};
29
- macroFn: {};
30
- parser: {};
31
- response: {};
32
- }, {}, {
33
- derive: {};
34
- resolve: {};
35
- schema: {};
36
- standaloneSchema: {};
37
- response: {};
38
- }, {
39
- derive: ({
40
- readonly logger: Logger;
41
- readonly requestContext?: undefined;
42
- readonly startTime?: undefined;
43
- } | {
44
- readonly logger: Logger;
45
- readonly requestContext: ContextData;
46
- readonly startTime: number;
47
- }) & {
48
- readonly logInfo: (message: string, metadata?: Record<string, any>) => void;
49
- readonly logError: (message: string, error?: Error, metadata?: Record<string, any>) => void;
50
- readonly traceOperation: <T_1>(operationName: string, operation: () => T_1 | Promise<T_1>) => Promise<T_1>;
51
- };
52
- resolve: {};
53
- schema: {};
54
- standaloneSchema: {};
55
- response: elysia0.ExtractErrorFromHandle<{
56
- readonly logInfo: (message: string, metadata?: Record<string, any>) => void;
57
- readonly logError: (message: string, error?: Error, metadata?: Record<string, any>) => void;
58
- readonly traceOperation: <T_1>(operationName: string, operation: () => T_1 | Promise<T_1>) => Promise<T_1>;
59
- }>;
60
- }>;
61
- //#endregion
62
- export { ElysiaLoggerConfig, elysiaLogger };
63
- //# sourceMappingURL=elysia-plugin.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"elysia-plugin.d.mts","names":[],"sources":["../src/elysia-plugin.ts"],"sourcesContent":[],"mappings":";;;;;;UAKiB,kBAAA;WACN;;EADM,YAAA,CAAA,EAAA,OAAkB;EAWnB,YAAA,CAAA,EAAY,MAAA,EAAA;;;;;;iBAAZ,uBAAuB,iBAC7B,2BAYc,MAAC;EA+EqB,SAAA,EAAA,CAAA,CAAA;EAK5B,KAAA,EAAA,CAAA,CAAA;EAEG,MAAA,EAAA,CAAA,CAAA;EAMM,OAAA,EAAA,CAAA,CAAA;CAAY,EAAA;EAAR,OAAA,EAAA,CAAA,CAAA;EACZ,KAAA,EAAA,CAAA,CAAA;CAAR,EAAA;EAdmC,MAAA,EAAA,CAAA,CAAA;EAK5B,gBAAA,EAAA,CAAA,CAAA;EAEG,KAAA,EAAA,CAAA,CAAA;EAMM,OAAA,EAAA,CAAA,CAAA;EAAY,MAAA,EAAA,CAAA,CAAA;EAAR,QAAA,EAAA,CAAA,CAAA;CACZ,EAAA,CAAA,CAAA,EAAA;EAAR,MAAA,EAAA,CAAA,CAAA;EAAO,OAAA,EAAA,CAAA,CAAA;EA7FO,MAAA,EAAA,CAAA,CAAA;EAAA,gBAAA,EAAA,CAAA,CAAA;;;;;;;;;;;;mDA+EqB;iDAK5B,kBAEG;2EAMM,MAAI,QAAQ,SAC5B,QAAQ;;;;;YAAD,OAAA,CAAA;mDAd4B;iDAK5B,kBAEG;2EAMM,MAAI,QAAQ,SAC5B,QAAQ"}
@@ -1,84 +0,0 @@
1
- import { LogContext } from "./context.node.mjs";
2
- import { Logger } from "./logger.node.mjs";
3
- import { Elysia } from "elysia";
4
-
5
- //#region src/elysia-plugin.ts
6
- /**
7
- * Simple ElysiaJS Logger Plugin
8
- * Provides automatic request logging and tracing
9
- */
10
- function elysiaLogger(config = {}) {
11
- const { logger = new Logger(), logRequests = true, logResponses = true, excludePaths = ["/health", "/metrics"] } = config;
12
- const context = LogContext.getInstance();
13
- return function(app) {
14
- return app.derive((ctx) => {
15
- const { request, path } = ctx;
16
- if (excludePaths.some((excludePath) => path.startsWith(excludePath))) return { logger };
17
- const url = new URL(request.url);
18
- const requestContext = {
19
- requestId: context.generateId(),
20
- method: request.method,
21
- url: request.url,
22
- path: url.pathname,
23
- userAgent: request.headers.get("user-agent") || void 0,
24
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
25
- };
26
- const startTime = performance.now();
27
- context.run(requestContext, () => {
28
- if (logRequests) logger.info(`→ ${request.method} ${path}`, {
29
- method: request.method,
30
- path,
31
- userAgent: requestContext.userAgent,
32
- requestId: requestContext.requestId
33
- });
34
- });
35
- return {
36
- logger,
37
- requestContext,
38
- startTime
39
- };
40
- }).onAfterHandle((ctx) => {
41
- const { request, startTime, requestContext, logger: logger$1 } = ctx;
42
- if (!startTime || !requestContext) return;
43
- const duration = performance.now() - startTime;
44
- const path = new URL(request.url).pathname;
45
- if (logResponses) logger$1.info(`← 200 ${request.method} ${path}`, {
46
- method: request.method,
47
- path,
48
- duration: `${duration.toFixed(2)}ms`,
49
- requestId: requestContext.requestId
50
- });
51
- }).onError((ctx) => {
52
- const { request, error, code, startTime, requestContext, logger: logger$1 } = ctx;
53
- if (!startTime || !requestContext) return;
54
- const duration = performance.now() - startTime;
55
- const path = new URL(request.url).pathname;
56
- logger$1?.error(`✖ ${code} ${request.method} ${path}`, {
57
- method: request.method,
58
- path,
59
- error: error?.toString?.() || "Unknown error",
60
- code,
61
- duration: `${duration.toFixed(2)}ms`,
62
- requestId: requestContext.requestId
63
- });
64
- }).derive(() => ({
65
- logInfo: (message, metadata) => {
66
- logger.info(message, metadata);
67
- },
68
- logError: (message, error, metadata) => {
69
- logger.error(message, metadata, error);
70
- },
71
- traceOperation: async (operationName, operation) => {
72
- return logger.trace({
73
- operationType: "custom",
74
- operationName,
75
- autoTiming: true
76
- }, operation);
77
- }
78
- }));
79
- };
80
- }
81
-
82
- //#endregion
83
- export { elysiaLogger };
84
- //# sourceMappingURL=elysia-plugin.mjs.map