@prosopo/logger 1.0.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/.turbo/turbo-build.log +20 -0
- package/CHANGELOG.md +15 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +77 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +201 -0
- package/dist/logger.js.map +1 -0
- package/dist/tests/logger.unit.test.d.ts +2 -0
- package/dist/tests/logger.unit.test.d.ts.map +1 -0
- package/dist/tests/logger.unit.test.js +104 -0
- package/dist/tests/logger.unit.test.js.map +1 -0
- package/entries.ts +17 -0
- package/package.json +61 -0
- package/vite.cjs.config.ts +25 -0
- package/vite.esm.config.ts +25 -0
- package/vite.test.config.ts +34 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @prosopo/logger@1.0.0 build
|
|
4
|
+
> npm run build:cross-env -- --mode ${NODE_ENV:-development}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
> @prosopo/logger@1.0.0 build:cross-env
|
|
8
|
+
> vite build --config vite.esm.config.ts --mode production
|
|
9
|
+
|
|
10
|
+
ViteEsmConfig: .
|
|
11
|
+
{ tsConfigPaths: [] }
|
|
12
|
+
{ externals: [] }
|
|
13
|
+
[36mvite v6.4.1 [32mbuilding SSR bundle for production...[36m[39m
|
|
14
|
+
Bundle build started
|
|
15
|
+
[2K[1Gtransforming (1) [2msrc/index.ts[22mBuild end
|
|
16
|
+
[2K[1G[32m✓[39m 2 modules transformed.
|
|
17
|
+
[2K[1Grendering chunks (1)...[2K[1Grendering chunks (2)...[2K[1G[2K[1G[2mdist/[22m[36mindex.js [39m[1m[2m0.41 kB[22m[1m[22m
|
|
18
|
+
[2mdist/[22m[36mlogger.js [39m[1m[2m5.83 kB[22m[1m[22m
|
|
19
|
+
[32m✓ built in 57ms[39m
|
|
20
|
+
⠙[1G[0K⠙[1G[0K
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @prosopo/logger
|
|
2
|
+
|
|
3
|
+
## 1.0.2
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- 97cf7bd: Fix log level numeric ordering to use conventional ascending severity (trace=0, fatal=5) matching Winston, Pino, and Log4j. Also fixes the emitted level field which was recording the threshold instead of the message level.
|
|
7
|
+
- 6ca1125: Move stringifyBigInts to @prosopo/util where generic utilities belong. Re-exported from @prosopo/logger for backward compatibility.
|
|
8
|
+
- 32a591b: Replace hardcoded field allowlist in unpackError with Object.getOwnPropertyNames so all custom subclass fields are captured automatically. Fixes duplicate cause assignment and updates errData type.
|
|
9
|
+
- Updated dependencies [6ca1125]
|
|
10
|
+
- @prosopo/util@3.2.15
|
|
11
|
+
|
|
12
|
+
## 1.0.1
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 0fd81af: Extract the logger into its own `@prosopo/logger` package, out of `@prosopo/common`. Consumers now import logger symbols from `@prosopo/logger`; `@prosopo/common` no longer re-exports them. Unused `@prosopo/common` dependencies pruned where the only usage was the logger.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,cAAc,aAAa,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { stringifyBigInts } from "@prosopo/util";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export { stringifyBigInts };
|
|
4
|
+
export type LogObject = object;
|
|
5
|
+
export type LogRecord = {
|
|
6
|
+
err?: unknown;
|
|
7
|
+
data?: LogObject;
|
|
8
|
+
msg?: string;
|
|
9
|
+
};
|
|
10
|
+
export type LogRecordFn = () => LogRecord;
|
|
11
|
+
export type Logger = {
|
|
12
|
+
setLogLevel(level: LogLevel): void;
|
|
13
|
+
getLogLevel(): LogLevel;
|
|
14
|
+
getScope(): string;
|
|
15
|
+
info(fn: LogRecordFn): void;
|
|
16
|
+
debug(fn: LogRecordFn): void;
|
|
17
|
+
trace(fn: LogRecordFn): void;
|
|
18
|
+
warn(fn: LogRecordFn): void;
|
|
19
|
+
error(fn: LogRecordFn): void;
|
|
20
|
+
fatal(fn: LogRecordFn): void;
|
|
21
|
+
log(level: LogLevel, fn: LogRecordFn): void;
|
|
22
|
+
with(obj: LogObject): Logger;
|
|
23
|
+
getPretty(): boolean;
|
|
24
|
+
setPretty(pretty: boolean): void;
|
|
25
|
+
getPrintStack(): boolean;
|
|
26
|
+
setPrintStack(printStack: boolean): void;
|
|
27
|
+
getFormat(): Format;
|
|
28
|
+
setFormat(format: Format): void;
|
|
29
|
+
};
|
|
30
|
+
export declare const InfoLevel = "info";
|
|
31
|
+
export declare const DebugLevel = "debug";
|
|
32
|
+
export declare const TraceLevel = "trace";
|
|
33
|
+
export declare const WarnLevel = "warn";
|
|
34
|
+
export declare const ErrorLevel = "error";
|
|
35
|
+
export declare const FatalLevel = "fatal";
|
|
36
|
+
export declare const LogLevel: z.ZodEnum<["info", "debug", "trace", "warn", "error", "fatal"]>;
|
|
37
|
+
export type LogLevel = z.infer<typeof LogLevel>;
|
|
38
|
+
export type LevelMap = {
|
|
39
|
+
[K in LogLevel]: number;
|
|
40
|
+
};
|
|
41
|
+
export declare function parseLogLevel(level: string | undefined, or?: LogLevel): LogLevel;
|
|
42
|
+
export declare function getLogger(logLevel: LogLevel, scope: string): Logger;
|
|
43
|
+
export declare const FormatJson = "json";
|
|
44
|
+
export declare const FormatPlain = "plain";
|
|
45
|
+
export declare const Format: z.ZodEnum<["json", "plain"]>;
|
|
46
|
+
export type Format = z.infer<typeof Format>;
|
|
47
|
+
export declare class NativeLogger implements Logger {
|
|
48
|
+
private scope;
|
|
49
|
+
private levelMap;
|
|
50
|
+
private defaultData;
|
|
51
|
+
private level;
|
|
52
|
+
private levelNum;
|
|
53
|
+
private pretty;
|
|
54
|
+
private printStack;
|
|
55
|
+
private format;
|
|
56
|
+
constructor(scope: string, levelMap?: LevelMap);
|
|
57
|
+
setFormat(format: Format): void;
|
|
58
|
+
getFormat(): Format;
|
|
59
|
+
with(obj: LogObject): Logger;
|
|
60
|
+
getPrintStack(): boolean;
|
|
61
|
+
setPrintStack(printStack: boolean): void;
|
|
62
|
+
getPretty(): boolean;
|
|
63
|
+
setPretty(pretty: boolean): void;
|
|
64
|
+
getScope(): string;
|
|
65
|
+
setLogLevel(level: LogLevel): void;
|
|
66
|
+
getLogLevel(): LogLevel;
|
|
67
|
+
private unpackError;
|
|
68
|
+
private print;
|
|
69
|
+
info(fn: LogRecordFn): void;
|
|
70
|
+
debug(fn: LogRecordFn): void;
|
|
71
|
+
trace(fn: LogRecordFn): void;
|
|
72
|
+
warn(fn: LogRecordFn): void;
|
|
73
|
+
error(fn: LogRecordFn): void;
|
|
74
|
+
fatal(fn: LogRecordFn): void;
|
|
75
|
+
log(level: LogLevel, fn: LogRecordFn): void;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAC/B,MAAM,MAAM,SAAS,GAAG;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EA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,WAAW,IAAI,QAAQ;IAIvB,OAAO,CAAC,WAAW;IAoCnB,OAAO,CAAC,KAAK;IAmEb,IAAI,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI;IAI3B,KAAK,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI;IAI5B,KAAK,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI;IAI5B,IAAI,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI;IAI3B,KAAK,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI;IAI5B,KAAK,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI;IAI5B,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI;CAwB3C"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { stringifyBigInts } from "@prosopo/util";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export { stringifyBigInts };
|
|
4
|
+
export const InfoLevel = "info";
|
|
5
|
+
export const DebugLevel = "debug";
|
|
6
|
+
export const TraceLevel = "trace";
|
|
7
|
+
export const WarnLevel = "warn";
|
|
8
|
+
export const ErrorLevel = "error";
|
|
9
|
+
export const FatalLevel = "fatal";
|
|
10
|
+
export const LogLevel = z.enum([
|
|
11
|
+
InfoLevel,
|
|
12
|
+
DebugLevel,
|
|
13
|
+
TraceLevel,
|
|
14
|
+
WarnLevel,
|
|
15
|
+
ErrorLevel,
|
|
16
|
+
FatalLevel,
|
|
17
|
+
]);
|
|
18
|
+
const logLevelMap = {
|
|
19
|
+
[TraceLevel]: 0,
|
|
20
|
+
[DebugLevel]: 1,
|
|
21
|
+
[InfoLevel]: 2,
|
|
22
|
+
[WarnLevel]: 3,
|
|
23
|
+
[ErrorLevel]: 4,
|
|
24
|
+
[FatalLevel]: 5,
|
|
25
|
+
};
|
|
26
|
+
export function parseLogLevel(level, or = InfoLevel) {
|
|
27
|
+
const result = LogLevel.safeParse(level);
|
|
28
|
+
return result.success ? result.data : or;
|
|
29
|
+
}
|
|
30
|
+
export function getLogger(logLevel, scope) {
|
|
31
|
+
const logger = new NativeLogger(scope);
|
|
32
|
+
logger.setLogLevel(logLevel);
|
|
33
|
+
return logger;
|
|
34
|
+
}
|
|
35
|
+
const inBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
36
|
+
export const FormatJson = "json";
|
|
37
|
+
export const FormatPlain = "plain";
|
|
38
|
+
export const Format = z.enum([FormatJson, FormatPlain]);
|
|
39
|
+
export class NativeLogger {
|
|
40
|
+
constructor(scope, levelMap = logLevelMap) {
|
|
41
|
+
this.scope = scope;
|
|
42
|
+
this.levelMap = levelMap;
|
|
43
|
+
this.pretty = 0;
|
|
44
|
+
this.printStack = false;
|
|
45
|
+
this.format = FormatJson;
|
|
46
|
+
this.level = InfoLevel;
|
|
47
|
+
this.levelNum = this.levelMap[this.level];
|
|
48
|
+
}
|
|
49
|
+
setFormat(format) {
|
|
50
|
+
this.format = format;
|
|
51
|
+
if (this.format !== FormatJson) {
|
|
52
|
+
throw new Error("Only JSON format implemented for now");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
getFormat() {
|
|
56
|
+
return this.format;
|
|
57
|
+
}
|
|
58
|
+
with(obj) {
|
|
59
|
+
const newLogger = new NativeLogger(this.scope);
|
|
60
|
+
newLogger.defaultData = { ...this.defaultData, ...obj };
|
|
61
|
+
newLogger.setLogLevel(this.getLogLevel());
|
|
62
|
+
return newLogger;
|
|
63
|
+
}
|
|
64
|
+
getPrintStack() {
|
|
65
|
+
return this.printStack;
|
|
66
|
+
}
|
|
67
|
+
setPrintStack(printStack) {
|
|
68
|
+
this.printStack = printStack;
|
|
69
|
+
}
|
|
70
|
+
getPretty() {
|
|
71
|
+
return this.pretty > 0;
|
|
72
|
+
}
|
|
73
|
+
setPretty(pretty) {
|
|
74
|
+
this.pretty = pretty ? 2 : 0;
|
|
75
|
+
}
|
|
76
|
+
getScope() {
|
|
77
|
+
return this.scope;
|
|
78
|
+
}
|
|
79
|
+
setLogLevel(level) {
|
|
80
|
+
this.level = level;
|
|
81
|
+
this.levelNum = this.levelMap[level];
|
|
82
|
+
}
|
|
83
|
+
getLogLevel() {
|
|
84
|
+
return this.level;
|
|
85
|
+
}
|
|
86
|
+
unpackError(err) {
|
|
87
|
+
const e = err;
|
|
88
|
+
const data = {};
|
|
89
|
+
for (const key of Object.getOwnPropertyNames(err)) {
|
|
90
|
+
if (!this.printStack && (key === "stack" || key === "stacktrace"))
|
|
91
|
+
continue;
|
|
92
|
+
data[key] = e[key];
|
|
93
|
+
}
|
|
94
|
+
if (!data.name) {
|
|
95
|
+
data.name = err.name ?? "Error";
|
|
96
|
+
}
|
|
97
|
+
const cause = e.cause;
|
|
98
|
+
if (cause !== undefined) {
|
|
99
|
+
if (cause instanceof Error ||
|
|
100
|
+
(typeof cause === "object" && cause !== null)) {
|
|
101
|
+
data.cause = this.unpackError(cause);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
data.cause = cause;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const msg = String(e.translationKey ?? e.message ?? e.msg ?? "");
|
|
108
|
+
return { msg, data };
|
|
109
|
+
}
|
|
110
|
+
print(dest, fn, level) {
|
|
111
|
+
if (this.levelMap[level] < this.levelNum) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const ts = new Date().toISOString();
|
|
115
|
+
let { data, msg, err } = fn();
|
|
116
|
+
let errMsg;
|
|
117
|
+
let errData;
|
|
118
|
+
if (err) {
|
|
119
|
+
if (err instanceof Error || typeof err === "object") {
|
|
120
|
+
const result = this.unpackError(err);
|
|
121
|
+
errMsg = result.msg;
|
|
122
|
+
errData = result.data;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
errMsg = String(err);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (this.defaultData) {
|
|
129
|
+
data = { ...this.defaultData, ...data };
|
|
130
|
+
}
|
|
131
|
+
const baseRecord = { scope: this.scope, ts, level };
|
|
132
|
+
if (data) {
|
|
133
|
+
baseRecord.data = data;
|
|
134
|
+
}
|
|
135
|
+
if (msg) {
|
|
136
|
+
baseRecord.msg = msg;
|
|
137
|
+
}
|
|
138
|
+
if (errMsg) {
|
|
139
|
+
baseRecord.err = errMsg;
|
|
140
|
+
}
|
|
141
|
+
if (errData) {
|
|
142
|
+
baseRecord.errData = errData;
|
|
143
|
+
}
|
|
144
|
+
if (inBrowser) {
|
|
145
|
+
if (msg || errMsg) {
|
|
146
|
+
dest(msg || errMsg, baseRecord);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
dest(baseRecord);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
const logRecord = stringifyBigInts(baseRecord);
|
|
154
|
+
const output = JSON.stringify(logRecord, null, this.pretty);
|
|
155
|
+
dest(output);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
info(fn) {
|
|
159
|
+
this.print(console.info.bind(console), fn, InfoLevel);
|
|
160
|
+
}
|
|
161
|
+
debug(fn) {
|
|
162
|
+
this.print(console.debug.bind(console), fn, DebugLevel);
|
|
163
|
+
}
|
|
164
|
+
trace(fn) {
|
|
165
|
+
this.print(console.trace.bind(console), fn, TraceLevel);
|
|
166
|
+
}
|
|
167
|
+
warn(fn) {
|
|
168
|
+
this.print(console.warn.bind(console), fn, WarnLevel);
|
|
169
|
+
}
|
|
170
|
+
error(fn) {
|
|
171
|
+
this.print(console.error.bind(console), fn, ErrorLevel);
|
|
172
|
+
}
|
|
173
|
+
fatal(fn) {
|
|
174
|
+
this.print(console.error.bind(console), fn, FatalLevel);
|
|
175
|
+
}
|
|
176
|
+
log(level, fn) {
|
|
177
|
+
switch (level) {
|
|
178
|
+
case "trace":
|
|
179
|
+
this.trace(fn);
|
|
180
|
+
break;
|
|
181
|
+
case "debug":
|
|
182
|
+
this.debug(fn);
|
|
183
|
+
break;
|
|
184
|
+
case "info":
|
|
185
|
+
this.info(fn);
|
|
186
|
+
break;
|
|
187
|
+
case "warn":
|
|
188
|
+
this.warn(fn);
|
|
189
|
+
break;
|
|
190
|
+
case "error":
|
|
191
|
+
this.error(fn);
|
|
192
|
+
break;
|
|
193
|
+
case "fatal":
|
|
194
|
+
this.fatal(fn);
|
|
195
|
+
break;
|
|
196
|
+
default:
|
|
197
|
+
throw new Error(`Unknown log level: ${level}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAmC5B,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC;AAChC,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC;AAClC,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC;AAClC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC;AAChC,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC;AAClC,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC;AAElC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC;IAC9B,SAAS;IACT,UAAU;IACV,UAAU;IACV,SAAS;IACT,UAAU;IACV,UAAU;CACV,CAAC,CAAC;AAOH,MAAM,WAAW,GAAa;IAC7B,CAAC,UAAU,CAAC,EAAE,CAAC;IACf,CAAC,UAAU,CAAC,EAAE,CAAC;IACf,CAAC,SAAS,CAAC,EAAE,CAAC;IACd,CAAC,SAAS,CAAC,EAAE,CAAC;IACd,CAAC,UAAU,CAAC,EAAE,CAAC;IACf,CAAC,UAAU,CAAC,EAA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I,CAAC,EAAE,CAAC,CAAC;gBACd,MAAM;YACP,KAAK,MAAM;gBACV,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACd,MAAM;YACP,KAAK,OAAO;gBACX,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACf,MAAM;YACP,KAAK,OAAO;gBACX,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACf,MAAM;YACP;gBACC,MAAM,IAAI,KAAK,CAAC,sBAAsB,KAAK,EAAE,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.unit.test.d.ts","sourceRoot":"","sources":["../../src/tests/logger.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { getLogger, stringifyBigInts } from "../logger.js";
|
|
3
|
+
describe("unpackError", () => {
|
|
4
|
+
let captured = [];
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
captured = [];
|
|
7
|
+
vi.spyOn(console, "error").mockImplementation((...args) => {
|
|
8
|
+
captured.push(String(args[0]));
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
vi.restoreAllMocks();
|
|
13
|
+
});
|
|
14
|
+
function lastRecord() {
|
|
15
|
+
const raw = captured[captured.length - 1] ?? "";
|
|
16
|
+
return JSON.parse(raw);
|
|
17
|
+
}
|
|
18
|
+
it("captures name from Error prototype chain", () => {
|
|
19
|
+
const logger = getLogger("error", "test");
|
|
20
|
+
const err = new TypeError("bad input");
|
|
21
|
+
logger.error(() => ({ err }));
|
|
22
|
+
const record = lastRecord();
|
|
23
|
+
const errData = record.errData;
|
|
24
|
+
expect(errData.name).toBe("TypeError");
|
|
25
|
+
});
|
|
26
|
+
it("captures message field", () => {
|
|
27
|
+
const logger = getLogger("error", "test");
|
|
28
|
+
const err = new Error("something went wrong");
|
|
29
|
+
logger.error(() => ({ err }));
|
|
30
|
+
const errData = lastRecord().errData;
|
|
31
|
+
expect(errData.message).toBe("something went wrong");
|
|
32
|
+
});
|
|
33
|
+
it("captures custom own properties from subclass errors", () => {
|
|
34
|
+
const logger = getLogger("error", "test");
|
|
35
|
+
const err = Object.assign(new Error("custom"), { statusCode: 404 });
|
|
36
|
+
logger.error(() => ({ err }));
|
|
37
|
+
const errData = lastRecord().errData;
|
|
38
|
+
expect(errData.statusCode).toBe(404);
|
|
39
|
+
});
|
|
40
|
+
it("recursively unpacks cause", () => {
|
|
41
|
+
const logger = getLogger("error", "test");
|
|
42
|
+
const cause = new Error("root cause");
|
|
43
|
+
const err = new Error("outer");
|
|
44
|
+
err.cause = cause;
|
|
45
|
+
logger.error(() => ({ err }));
|
|
46
|
+
const errData = lastRecord().errData;
|
|
47
|
+
const causeData = errData.cause;
|
|
48
|
+
expect(causeData).toBeDefined();
|
|
49
|
+
});
|
|
50
|
+
it("suppresses stack when printStack is false (default)", () => {
|
|
51
|
+
const logger = getLogger("error", "test");
|
|
52
|
+
const err = new Error("test");
|
|
53
|
+
logger.error(() => ({ err }));
|
|
54
|
+
const errData = lastRecord().errData;
|
|
55
|
+
expect(errData.stack).toBeUndefined();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe("stringifyBigInts", () => {
|
|
59
|
+
it("should strigify big int", () => {
|
|
60
|
+
const bigInt = BigInt(12345678901234567890n);
|
|
61
|
+
const stringified = stringifyBigInts(bigInt);
|
|
62
|
+
expect(stringified).toEqual(bigInt.toString());
|
|
63
|
+
});
|
|
64
|
+
it("should strinfigy big int in object properties", () => {
|
|
65
|
+
const bigInt1 = BigInt(12345678901234567890n);
|
|
66
|
+
const bigInt2 = BigInt(23456789012345678901n);
|
|
67
|
+
const stringified = stringifyBigInts({
|
|
68
|
+
first: bigInt1,
|
|
69
|
+
second: {
|
|
70
|
+
inner: {
|
|
71
|
+
field: bigInt2,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
third: "third",
|
|
75
|
+
});
|
|
76
|
+
expect(stringified).toEqual({
|
|
77
|
+
first: bigInt1.toString(),
|
|
78
|
+
second: {
|
|
79
|
+
inner: {
|
|
80
|
+
field: bigInt2.toString(),
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
third: "third",
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
it("should stringify big int inside array", () => {
|
|
87
|
+
const bigInt1 = BigInt(12345678901234567890n);
|
|
88
|
+
const bigInt2 = BigInt(23456789012345678901n);
|
|
89
|
+
const bigInt3 = BigInt(34567890123456789012n);
|
|
90
|
+
const stringified = stringifyBigInts([
|
|
91
|
+
bigInt1,
|
|
92
|
+
["inner", bigInt2],
|
|
93
|
+
{ name: "object", value: bigInt3 },
|
|
94
|
+
"third",
|
|
95
|
+
]);
|
|
96
|
+
expect(stringified).toEqual([
|
|
97
|
+
bigInt1.toString(),
|
|
98
|
+
["inner", bigInt2.toString()],
|
|
99
|
+
{ name: "object", value: bigInt3.toString() },
|
|
100
|
+
"third",
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=logger.unit.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.unit.test.js","sourceRoot":"","sources":["../../src/tests/logger.unit.test.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC3D,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC5B,IAAI,QAAQ,GAAa,EAAE,CAAC;IAE5B,UAAU,CAAC,GAAG,EAAE;QACf,QAAQ,GAAG,EAAE,CAAC;QACd,EAAE,CAAC,KAAK,C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O;SACd,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAChD,MAAM,OAAO,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAE9C,MAAM,WAAW,GAAG,gBAAgB,CAAC;YACpC,OAAO;YACP,CAAC,OAAO,EAAE,OAAO,CAAC;YAClB,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE;YAClC,OAAO;SACP,CAAC,CAAC;QAEH,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC;YAC3B,OAAO,CAAC,QAAQ,EAAE;YAClB,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC7B,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE;YAC7C,OAAO;SACP,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/entries.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
export const entries: Record<string, string> = {
|
|
16
|
+
index: "src/index.ts",
|
|
17
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prosopo/logger",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Prosopo logger library",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": "^24",
|
|
10
|
+
"npm": "^11"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/cjs/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "del-cli --verbose dist tsconfig.tsbuildinfo",
|
|
21
|
+
"build": "npm run build:cross-env -- --mode ${NODE_ENV:-development}",
|
|
22
|
+
"build:cross-env": "vite build --config vite.esm.config.ts",
|
|
23
|
+
"build:tsc": "tsc --build --verbose",
|
|
24
|
+
"build:cjs": "NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV",
|
|
25
|
+
"typecheck": "tsc --project tsconfig.types.json",
|
|
26
|
+
"test": "NODE_ENV=${NODE_ENV:-test}; npx vitest run --config ./vite.test.config.ts"
|
|
27
|
+
},
|
|
28
|
+
"author": "Prosopo Limited",
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@prosopo/util": "3.2.15",
|
|
32
|
+
"zod": "3.23.8"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@prosopo/config": "3.3.1",
|
|
36
|
+
"@types/node": "22.10.2",
|
|
37
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
38
|
+
"concurrently": "9.0.1",
|
|
39
|
+
"del-cli": "6.0.0",
|
|
40
|
+
"dotenv": "16.4.5",
|
|
41
|
+
"npm-run-all": "4.1.5",
|
|
42
|
+
"tslib": "2.7.0",
|
|
43
|
+
"tsx": "4.20.3",
|
|
44
|
+
"typescript": "5.6.2",
|
|
45
|
+
"vite": "6.4.1",
|
|
46
|
+
"vitest": "3.2.4"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/prosopo/captcha.git",
|
|
51
|
+
"directory": "packages/logger"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/prosopo/captcha/issues"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://github.com/prosopo/captcha#readme",
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"registry": "https://registry.npmjs.org"
|
|
59
|
+
},
|
|
60
|
+
"sideEffects": false
|
|
61
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import { ViteCommonJSConfig } from "@prosopo/config";
|
|
17
|
+
import { entries } from "./entries.js";
|
|
18
|
+
|
|
19
|
+
export default function () {
|
|
20
|
+
return ViteCommonJSConfig(
|
|
21
|
+
path.basename("."),
|
|
22
|
+
path.resolve("./tsconfig.json"),
|
|
23
|
+
entries,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import { ViteEsmConfig } from "@prosopo/config";
|
|
17
|
+
import { entries } from "./entries.js";
|
|
18
|
+
|
|
19
|
+
export default function () {
|
|
20
|
+
return ViteEsmConfig(
|
|
21
|
+
path.basename("."),
|
|
22
|
+
path.resolve("./tsconfig.json"),
|
|
23
|
+
entries,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import fs from "node:fs";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { ViteTestConfig } from "@prosopo/config";
|
|
18
|
+
import dotenv from "dotenv";
|
|
19
|
+
|
|
20
|
+
process.env.NODE_ENV = "test";
|
|
21
|
+
// if .env.test exists at this level, use it, otherwise use the one at the root
|
|
22
|
+
const envFile = `.env.${process.env.NODE_ENV || "development"}`;
|
|
23
|
+
let envPath = envFile;
|
|
24
|
+
if (fs.existsSync(envFile)) {
|
|
25
|
+
envPath = path.resolve(envFile);
|
|
26
|
+
} else if (fs.existsSync(`../../${envFile}`)) {
|
|
27
|
+
envPath = path.resolve(`../../${envFile}`);
|
|
28
|
+
} else {
|
|
29
|
+
throw new Error(`No ${envFile} file found`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
dotenv.config({ path: envPath });
|
|
33
|
+
|
|
34
|
+
export default ViteTestConfig();
|