@prosopo/logger 1.0.2 → 1.0.3

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.
@@ -0,0 +1,18 @@
1
+
2
+ > @prosopo/logger@1.0.3 build:cjs
3
+ > NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV
4
+
5
+ ViteCommonJSConfig: .
6
+ {
7
+ tsConfigPaths: [ '/home/runner/work/captcha/captcha/packages/util/tsconfig.json' ]
8
+ }
9
+ { externals: [ '@prosopo/util' ] }
10
+ vite v6.4.1 building SSR bundle for production...
11
+ Bundle build started
12
+ transforming...
13
+ Build end
14
+ ✓ 2 modules transformed.
15
+ rendering chunks...
16
+ dist/cjs/index.cjs 0.79 kB
17
+ dist/cjs/logger.cjs 5.38 kB
18
+ ✓ built in 171ms
@@ -0,0 +1,17 @@
1
+
2
+ > @prosopo/logger@1.0.3 build:tsc
3
+ > tsc --build --verbose
4
+
5
+ 7:45:03 PM - Projects in this build:
6
+ * ../../dev/config/tsconfig.json
7
+ * ../util/tsconfig.json
8
+ * tsconfig.json
9
+
10
+ 7:45:03 PM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/webpack/webpack.config.ts' is older than output '../../dev/config/tsconfig.tsbuildinfo'
11
+
12
+ 7:45:03 PM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/tsconfig.tsbuildinfo'
13
+
14
+ 7:45:03 PM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
15
+
16
+ 7:45:03 PM - Building project '/home/runner/work/captcha/captcha/packages/logger/tsconfig.json'...
17
+
@@ -1,20 +1,22 @@
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
- vite v6.4.1 building SSR bundle for production...
14
- Bundle build started
15
- transforming (1) src/index.tsBuild end
16
- ✓ 2 modules transformed.
17
- rendering chunks (1)...rendering chunks (2)...dist/index.js 0.41 kB
18
- dist/logger.js 5.83 kB
19
- ✓ built in 57ms
20
- ⠙⠙
1
+
2
+ > @prosopo/logger@1.0.3 build
3
+ > npm run build:cross-env -- --mode ${NODE_ENV:-development}
4
+
5
+
6
+ > @prosopo/logger@1.0.3 build:cross-env
7
+ > vite build --config vite.esm.config.ts --mode production
8
+
9
+ ViteEsmConfig: .
10
+ {
11
+ tsConfigPaths: [ '/home/runner/work/captcha/captcha/packages/util/tsconfig.json' ]
12
+ }
13
+ { externals: [ '@prosopo/util' ] }
14
+ vite v6.4.1 building SSR bundle for production...
15
+ Bundle build started
16
+ transforming...
17
+ Build end
18
+ ✓ 2 modules transformed.
19
+ rendering chunks...
20
+ dist/index.js 0.44 kB
21
+ dist/logger.js 5.06 kB
22
+ ✓ built in 167ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @prosopo/logger
2
2
 
3
+ ## 1.0.3
4
+ ### Patch Changes
5
+
6
+ - Updated dependencies [55b1388]
7
+ - @prosopo/util@3.3.0
8
+
3
9
  ## 1.0.2
4
10
  ### Patch Changes
5
11
 
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const logger = require("./logger.cjs");
4
+ const util = require("@prosopo/util");
5
+ exports.DebugLevel = logger.DebugLevel;
6
+ exports.ErrorLevel = logger.ErrorLevel;
7
+ exports.FatalLevel = logger.FatalLevel;
8
+ exports.Format = logger.Format;
9
+ exports.FormatJson = logger.FormatJson;
10
+ exports.FormatPlain = logger.FormatPlain;
11
+ exports.InfoLevel = logger.InfoLevel;
12
+ exports.LogLevel = logger.LogLevel;
13
+ exports.NativeLogger = logger.NativeLogger;
14
+ exports.TraceLevel = logger.TraceLevel;
15
+ exports.WarnLevel = logger.WarnLevel;
16
+ exports.getLogger = logger.getLogger;
17
+ exports.parseLogLevel = logger.parseLogLevel;
18
+ Object.defineProperty(exports, "stringifyBigInts", {
19
+ enumerable: true,
20
+ get: () => util.stringifyBigInts
21
+ });
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const util = require("@prosopo/util");
4
+ const zod = require("zod");
5
+ const InfoLevel = "info";
6
+ const DebugLevel = "debug";
7
+ const TraceLevel = "trace";
8
+ const WarnLevel = "warn";
9
+ const ErrorLevel = "error";
10
+ const FatalLevel = "fatal";
11
+ const LogLevel = zod.z.enum([
12
+ InfoLevel,
13
+ DebugLevel,
14
+ TraceLevel,
15
+ WarnLevel,
16
+ ErrorLevel,
17
+ FatalLevel
18
+ ]);
19
+ const logLevelMap = {
20
+ [TraceLevel]: 0,
21
+ [DebugLevel]: 1,
22
+ [InfoLevel]: 2,
23
+ [WarnLevel]: 3,
24
+ [ErrorLevel]: 4,
25
+ [FatalLevel]: 5
26
+ };
27
+ function parseLogLevel(level, or = InfoLevel) {
28
+ const result = LogLevel.safeParse(level);
29
+ return result.success ? result.data : or;
30
+ }
31
+ function getLogger(logLevel, scope) {
32
+ const logger = new NativeLogger(scope);
33
+ logger.setLogLevel(logLevel);
34
+ return logger;
35
+ }
36
+ const inBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
37
+ const FormatJson = "json";
38
+ const FormatPlain = "plain";
39
+ const Format = zod.z.enum([FormatJson, FormatPlain]);
40
+ class NativeLogger {
41
+ constructor(scope, levelMap = logLevelMap) {
42
+ this.scope = scope;
43
+ this.levelMap = levelMap;
44
+ this.pretty = 0;
45
+ this.printStack = false;
46
+ this.format = FormatJson;
47
+ this.level = InfoLevel;
48
+ this.levelNum = this.levelMap[this.level];
49
+ }
50
+ setFormat(format) {
51
+ this.format = format;
52
+ if (this.format !== FormatJson) {
53
+ throw new Error("Only JSON format implemented for now");
54
+ }
55
+ }
56
+ getFormat() {
57
+ return this.format;
58
+ }
59
+ with(obj) {
60
+ const newLogger = new NativeLogger(this.scope);
61
+ newLogger.defaultData = { ...this.defaultData, ...obj };
62
+ newLogger.setLogLevel(this.getLogLevel());
63
+ return newLogger;
64
+ }
65
+ getPrintStack() {
66
+ return this.printStack;
67
+ }
68
+ setPrintStack(printStack) {
69
+ this.printStack = printStack;
70
+ }
71
+ getPretty() {
72
+ return this.pretty > 0;
73
+ }
74
+ setPretty(pretty) {
75
+ this.pretty = pretty ? 2 : 0;
76
+ }
77
+ getScope() {
78
+ return this.scope;
79
+ }
80
+ setLogLevel(level) {
81
+ this.level = level;
82
+ this.levelNum = this.levelMap[level];
83
+ }
84
+ getLogLevel() {
85
+ return this.level;
86
+ }
87
+ unpackError(err) {
88
+ const e = err;
89
+ const data = {};
90
+ for (const key of Object.getOwnPropertyNames(err)) {
91
+ if (!this.printStack && (key === "stack" || key === "stacktrace"))
92
+ continue;
93
+ data[key] = e[key];
94
+ }
95
+ if (!data.name) {
96
+ data.name = err.name ?? "Error";
97
+ }
98
+ const cause = e.cause;
99
+ if (cause !== void 0) {
100
+ if (cause instanceof Error || typeof cause === "object" && cause !== null) {
101
+ data.cause = this.unpackError(cause);
102
+ } else {
103
+ data.cause = cause;
104
+ }
105
+ }
106
+ const msg = String(e.translationKey ?? e.message ?? e.msg ?? "");
107
+ return { msg, data };
108
+ }
109
+ print(dest, fn, level) {
110
+ if (this.levelMap[level] < this.levelNum) {
111
+ return;
112
+ }
113
+ const ts = (/* @__PURE__ */ new Date()).toISOString();
114
+ let { data, msg, err } = fn();
115
+ let errMsg;
116
+ let errData;
117
+ if (err) {
118
+ if (err instanceof Error || typeof err === "object") {
119
+ const result = this.unpackError(err);
120
+ errMsg = result.msg;
121
+ errData = result.data;
122
+ } else {
123
+ errMsg = String(err);
124
+ }
125
+ }
126
+ if (this.defaultData) {
127
+ data = { ...this.defaultData, ...data };
128
+ }
129
+ const baseRecord = { scope: this.scope, ts, level };
130
+ if (data) {
131
+ baseRecord.data = data;
132
+ }
133
+ if (msg) {
134
+ baseRecord.msg = msg;
135
+ }
136
+ if (errMsg) {
137
+ baseRecord.err = errMsg;
138
+ }
139
+ if (errData) {
140
+ baseRecord.errData = errData;
141
+ }
142
+ if (inBrowser) {
143
+ if (msg || errMsg) {
144
+ dest(msg || errMsg, baseRecord);
145
+ } else {
146
+ dest(baseRecord);
147
+ }
148
+ } else {
149
+ const logRecord = util.stringifyBigInts(baseRecord);
150
+ const output = JSON.stringify(logRecord, null, this.pretty);
151
+ dest(output);
152
+ }
153
+ }
154
+ info(fn) {
155
+ this.print(console.info.bind(console), fn, InfoLevel);
156
+ }
157
+ debug(fn) {
158
+ this.print(console.debug.bind(console), fn, DebugLevel);
159
+ }
160
+ trace(fn) {
161
+ this.print(console.trace.bind(console), fn, TraceLevel);
162
+ }
163
+ warn(fn) {
164
+ this.print(console.warn.bind(console), fn, WarnLevel);
165
+ }
166
+ error(fn) {
167
+ this.print(console.error.bind(console), fn, ErrorLevel);
168
+ }
169
+ fatal(fn) {
170
+ this.print(console.error.bind(console), fn, FatalLevel);
171
+ }
172
+ log(level, fn) {
173
+ switch (level) {
174
+ case "trace":
175
+ this.trace(fn);
176
+ break;
177
+ case "debug":
178
+ this.debug(fn);
179
+ break;
180
+ case "info":
181
+ this.info(fn);
182
+ break;
183
+ case "warn":
184
+ this.warn(fn);
185
+ break;
186
+ case "error":
187
+ this.error(fn);
188
+ break;
189
+ case "fatal":
190
+ this.fatal(fn);
191
+ break;
192
+ default:
193
+ throw new Error(`Unknown log level: ${level}`);
194
+ }
195
+ }
196
+ }
197
+ Object.defineProperty(exports, "stringifyBigInts", {
198
+ enumerable: true,
199
+ get: () => util.stringifyBigInts
200
+ });
201
+ exports.DebugLevel = DebugLevel;
202
+ exports.ErrorLevel = ErrorLevel;
203
+ exports.FatalLevel = FatalLevel;
204
+ exports.Format = Format;
205
+ exports.FormatJson = FormatJson;
206
+ exports.FormatPlain = FormatPlain;
207
+ exports.InfoLevel = InfoLevel;
208
+ exports.LogLevel = LogLevel;
209
+ exports.NativeLogger = NativeLogger;
210
+ exports.TraceLevel = TraceLevel;
211
+ exports.WarnLevel = WarnLevel;
212
+ exports.getLogger = getLogger;
213
+ exports.parseLogLevel = parseLogLevel;
package/dist/index.js CHANGED
@@ -1,2 +1,18 @@
1
- export * from "./logger.js";
2
- //# sourceMappingURL=index.js.map
1
+ import { DebugLevel, ErrorLevel, FatalLevel, Format, FormatJson, FormatPlain, InfoLevel, LogLevel, NativeLogger, TraceLevel, WarnLevel, getLogger, parseLogLevel } from "./logger.js";
2
+ import { stringifyBigInts } from "@prosopo/util";
3
+ export {
4
+ DebugLevel,
5
+ ErrorLevel,
6
+ FatalLevel,
7
+ Format,
8
+ FormatJson,
9
+ FormatPlain,
10
+ InfoLevel,
11
+ LogLevel,
12
+ NativeLogger,
13
+ TraceLevel,
14
+ WarnLevel,
15
+ getLogger,
16
+ parseLogLevel,
17
+ stringifyBigInts
18
+ };