@lssm/lib.logger 1.42.0 → 1.42.2
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 +3 -0
- package/dist/context.browser.d.mts +49 -0
- package/dist/context.browser.d.mts.map +1 -0
- package/dist/context.browser.mjs +89 -1
- package/dist/context.browser.mjs.map +1 -0
- package/dist/context.d.mts +17 -0
- package/dist/context.d.mts.map +1 -0
- package/dist/context.mjs +1 -1
- package/dist/context.node.d.mts +48 -0
- package/dist/context.node.d.mts.map +1 -0
- package/dist/context.node.mjs +79 -1
- package/dist/context.node.mjs.map +1 -0
- package/dist/elysia-plugin.d.mts +64 -0
- package/dist/elysia-plugin.d.mts.map +1 -0
- package/dist/elysia-plugin.mjs +85 -1
- package/dist/elysia-plugin.mjs.map +1 -0
- package/dist/formatters.d.mts +29 -0
- package/dist/formatters.d.mts.map +1 -0
- package/dist/formatters.mjs +180 -9
- package/dist/formatters.mjs.map +1 -0
- package/dist/index.browser.d.mts +7 -0
- package/dist/index.browser.mjs +8 -1
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +9 -1
- package/dist/logger.browser.d.mts +51 -0
- package/dist/logger.browser.d.mts.map +1 -0
- package/dist/logger.browser.mjs +190 -1
- package/dist/logger.browser.mjs.map +1 -0
- package/dist/logger.d.mts +2 -0
- package/dist/logger.mjs +3 -1
- package/dist/logger.node.d.mts +51 -0
- package/dist/logger.node.d.mts.map +1 -0
- package/dist/logger.node.mjs +190 -1
- package/dist/logger.node.mjs.map +1 -0
- package/dist/timer.d.mts +103 -0
- package/dist/timer.d.mts.map +1 -0
- package/dist/timer.mjs +165 -1
- package/dist/timer.mjs.map +1 -0
- package/dist/tracer.browser.d.mts +51 -0
- package/dist/tracer.browser.d.mts.map +1 -0
- package/dist/tracer.browser.mjs +116 -1
- package/dist/tracer.browser.mjs.map +1 -0
- package/dist/tracer.d.mts +2 -0
- package/dist/tracer.mjs +3 -1
- package/dist/tracer.node.d.mts +51 -0
- package/dist/tracer.node.d.mts.map +1 -0
- package/dist/tracer.node.mjs +116 -1
- package/dist/tracer.node.mjs.map +1 -0
- package/dist/types.d.mts +71 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +14 -1
- package/dist/types.mjs.map +1 -0
- package/package.json +29 -22
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
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
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/dist/context.browser.mjs
CHANGED
|
@@ -1 +1,89 @@
|
|
|
1
|
-
import"zone.js";
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.browser.mjs","names":["contextData: LogContextData","mergedContext: ContextData"],"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,MAAMA,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,MAAMC,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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/dist/context.node.mjs
CHANGED
|
@@ -1 +1,79 @@
|
|
|
1
|
-
import{AsyncLocalStorage
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.node.mjs","names":["contextData: LogContextData","mergedContext: ContextData"],"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,MAAMA,cAA8B;GAClC,SAAS,EAAE,GAAG,SAAS;GACvB,OAAO,KAAK,iBAAiB;GAC9B;AACD,SAAO,KAAK,QAAQ,IAAI,aAAa,GAAG;;;;;CAM1C,OAAU,mBAAyC,IAAgB;EAEjE,MAAMC,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"}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
declare const createElysiaLogger: typeof elysiaLogger;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { ElysiaLoggerConfig, createElysiaLogger, elysiaLogger };
|
|
64
|
+
//# sourceMappingURL=elysia-plugin.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;EA4GZ,QAAA,EAAA,CAAA,CAAA;;;;;;;;;;;mDA7BiC;iDAK5B,kBAEG;2EAMM,MAAI,QAAQ,SAC5B,QAAQ;;;;;YAAD,OAAA,CAAA;mDAd4B;iDAK5B,kBAEG;2EAMM,MAAI,QAAQ,SAC5B,QAAQ;;;cAeN,2BAAkB"}
|
package/dist/elysia-plugin.mjs
CHANGED
|
@@ -1 +1,85 @@
|
|
|
1
|
-
import{LogContext
|
|
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
|
+
const createElysiaLogger = elysiaLogger;
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
export { createElysiaLogger, elysiaLogger };
|
|
85
|
+
//# sourceMappingURL=elysia-plugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elysia-plugin.mjs","names":["requestContext: ContextData"],"sources":["../src/elysia-plugin.ts"],"sourcesContent":["import { Logger } from './logger.node';\nimport { LogContext } from './context.node';\nimport type { ContextData } from './types';\nimport { Elysia } from 'elysia';\n\nexport interface ElysiaLoggerConfig {\n logger?: Logger;\n logRequests?: boolean;\n logResponses?: boolean;\n excludePaths?: string[];\n}\n\n/**\n * Simple ElysiaJS Logger Plugin\n * Provides automatic request logging and tracing\n */\nexport function elysiaLogger<T extends Elysia>(\n config: ElysiaLoggerConfig = {}\n) {\n const {\n logger = new Logger(),\n logRequests = true,\n logResponses = true,\n excludePaths = ['/health', '/metrics'],\n } = config;\n\n const context = LogContext.getInstance();\n\n // For type compatibility, we use a factory function\n return function (app: T) {\n return app\n .derive((ctx) => {\n const { request, path } = ctx;\n\n // Skip excluded paths\n if (excludePaths.some((excludePath) => path.startsWith(excludePath))) {\n return { logger };\n }\n\n // Create request context\n const url = new URL(request.url);\n const requestContext: ContextData = {\n requestId: context.generateId(),\n method: request.method,\n url: request.url,\n path: url.pathname,\n userAgent: request.headers.get('user-agent') || undefined,\n timestamp: new Date().toISOString(),\n };\n\n const startTime = performance.now();\n\n // Run in context\n context.run(requestContext, () => {\n // Log request\n if (logRequests) {\n logger.info(`→ ${request.method} ${path}`, {\n method: request.method,\n path,\n userAgent: requestContext.userAgent,\n requestId: requestContext.requestId,\n });\n }\n });\n\n return {\n logger,\n requestContext,\n startTime,\n };\n })\n .onAfterHandle((ctx) => {\n const { request, startTime, requestContext, logger } = ctx;\n\n if (!startTime || !requestContext) return;\n\n const duration = performance.now() - startTime;\n const path = new URL(request.url).pathname;\n\n if (logResponses) {\n logger.info(`← 200 ${request.method} ${path}`, {\n method: request.method,\n path,\n duration: `${duration.toFixed(2)}ms`,\n requestId: requestContext.requestId,\n });\n }\n })\n .onError((ctx) => {\n const { request, error, code, startTime, requestContext, logger } = ctx;\n\n if (!startTime || !requestContext) return;\n\n const duration = performance.now() - startTime;\n const path = new URL(request.url).pathname;\n\n logger?.error(`✖ ${code} ${request.method} ${path}`, {\n method: request.method,\n path,\n error: error?.toString?.() || 'Unknown error',\n code,\n duration: `${duration.toFixed(2)}ms`,\n requestId: requestContext.requestId,\n });\n })\n .derive(() => ({\n // Helper functions available in route handlers\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n logInfo: (message: string, metadata?: Record<string, any>) => {\n logger.info(message, metadata);\n },\n logError: (\n message: string,\n error?: Error,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata?: Record<string, any>\n ) => {\n logger.error(message, metadata, error);\n },\n traceOperation: async <T>(\n operationName: string,\n operation: () => T | Promise<T>\n ): Promise<T> => {\n return logger.trace(\n {\n operationType: 'custom',\n operationName,\n autoTiming: true,\n },\n operation\n );\n },\n }));\n };\n}\n\n// Export convenience functions\nexport const createElysiaLogger = elysiaLogger;\n"],"mappings":";;;;;;;;;AAgBA,SAAgB,aACd,SAA6B,EAAE,EAC/B;CACA,MAAM,EACJ,SAAS,IAAI,QAAQ,EACrB,cAAc,MACd,eAAe,MACf,eAAe,CAAC,WAAW,WAAW,KACpC;CAEJ,MAAM,UAAU,WAAW,aAAa;AAGxC,QAAO,SAAU,KAAQ;AACvB,SAAO,IACJ,QAAQ,QAAQ;GACf,MAAM,EAAE,SAAS,SAAS;AAG1B,OAAI,aAAa,MAAM,gBAAgB,KAAK,WAAW,YAAY,CAAC,CAClE,QAAO,EAAE,QAAQ;GAInB,MAAM,MAAM,IAAI,IAAI,QAAQ,IAAI;GAChC,MAAMA,iBAA8B;IAClC,WAAW,QAAQ,YAAY;IAC/B,QAAQ,QAAQ;IAChB,KAAK,QAAQ;IACb,MAAM,IAAI;IACV,WAAW,QAAQ,QAAQ,IAAI,aAAa,IAAI;IAChD,4BAAW,IAAI,MAAM,EAAC,aAAa;IACpC;GAED,MAAM,YAAY,YAAY,KAAK;AAGnC,WAAQ,IAAI,sBAAsB;AAEhC,QAAI,YACF,QAAO,KAAK,KAAK,QAAQ,OAAO,GAAG,QAAQ;KACzC,QAAQ,QAAQ;KAChB;KACA,WAAW,eAAe;KAC1B,WAAW,eAAe;KAC3B,CAAC;KAEJ;AAEF,UAAO;IACL;IACA;IACA;IACD;IACD,CACD,eAAe,QAAQ;GACtB,MAAM,EAAE,SAAS,WAAW,gBAAgB,qBAAW;AAEvD,OAAI,CAAC,aAAa,CAAC,eAAgB;GAEnC,MAAM,WAAW,YAAY,KAAK,GAAG;GACrC,MAAM,OAAO,IAAI,IAAI,QAAQ,IAAI,CAAC;AAElC,OAAI,aACF,UAAO,KAAK,SAAS,QAAQ,OAAO,GAAG,QAAQ;IAC7C,QAAQ,QAAQ;IAChB;IACA,UAAU,GAAG,SAAS,QAAQ,EAAE,CAAC;IACjC,WAAW,eAAe;IAC3B,CAAC;IAEJ,CACD,SAAS,QAAQ;GAChB,MAAM,EAAE,SAAS,OAAO,MAAM,WAAW,gBAAgB,qBAAW;AAEpE,OAAI,CAAC,aAAa,CAAC,eAAgB;GAEnC,MAAM,WAAW,YAAY,KAAK,GAAG;GACrC,MAAM,OAAO,IAAI,IAAI,QAAQ,IAAI,CAAC;AAElC,aAAQ,MAAM,KAAK,KAAK,GAAG,QAAQ,OAAO,GAAG,QAAQ;IACnD,QAAQ,QAAQ;IAChB;IACA,OAAO,OAAO,YAAY,IAAI;IAC9B;IACA,UAAU,GAAG,SAAS,QAAQ,EAAE,CAAC;IACjC,WAAW,eAAe;IAC3B,CAAC;IACF,CACD,cAAc;GAGb,UAAU,SAAiB,aAAmC;AAC5D,WAAO,KAAK,SAAS,SAAS;;GAEhC,WACE,SACA,OAEA,aACG;AACH,WAAO,MAAM,SAAS,UAAU,MAAM;;GAExC,gBAAgB,OACd,eACA,cACe;AACf,WAAO,OAAO,MACZ;KACE,eAAe;KACf;KACA,YAAY;KACb,EACD,UACD;;GAEJ,EAAE;;;AAKT,MAAa,qBAAqB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Formatter, LogEntry } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/formatters.d.ts
|
|
4
|
+
declare class DevFormatter implements Formatter {
|
|
5
|
+
private enableColors;
|
|
6
|
+
constructor(enableColors?: boolean);
|
|
7
|
+
format(entry: LogEntry): string;
|
|
8
|
+
private formatTimestamp;
|
|
9
|
+
private formatTraceInfo;
|
|
10
|
+
private formatDuration;
|
|
11
|
+
private formatContext;
|
|
12
|
+
private formatMetadata;
|
|
13
|
+
private formatError;
|
|
14
|
+
private formatObject;
|
|
15
|
+
private formatValue;
|
|
16
|
+
private colorize;
|
|
17
|
+
}
|
|
18
|
+
declare class ProductionFormatter implements Formatter {
|
|
19
|
+
format(entry: LogEntry): string;
|
|
20
|
+
}
|
|
21
|
+
declare class CustomFormatter implements Formatter {
|
|
22
|
+
private template;
|
|
23
|
+
private dateFormat;
|
|
24
|
+
constructor(template?: string, dateFormat?: (date: Date) => string);
|
|
25
|
+
format(entry: LogEntry): string;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { CustomFormatter, DevFormatter, ProductionFormatter };
|
|
29
|
+
//# sourceMappingURL=formatters.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.mts","names":[],"sources":["../src/formatters.ts"],"sourcesContent":[],"mappings":";;;cAkCa,YAAA,YAAwB;;EAAxB,WAAA,CAAA,YAOG,CAPU,EAOV,OAAA;EAkJH,MAAA,CAAA,KAAA,EAlJG,QAkJiB,CAAA,EAAA,MAAA;EAkDpB,QAAA,eAAgB;EAML,QAAA,eAAA;EAMR,QAAA,cAAA;EAZwB,QAAA,aAAA;EAAS,QAAA,cAAA;;;;;;cAlDpC,mBAAA,YAA+B;gBAC5B;;cAiDH,eAAA,YAA2B;;;qDAMhB;gBAMR"}
|