modality-kit 0.5.7 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +23 -40
- package/dist/types/util_logger.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -105,7 +105,7 @@ class ModalityLogger {
|
|
|
105
105
|
setLogLevel(level) {
|
|
106
106
|
this.logLevel = level;
|
|
107
107
|
}
|
|
108
|
-
format(level,
|
|
108
|
+
format(level, categroy) {
|
|
109
109
|
const timestamp = this.getTimestamp();
|
|
110
110
|
let prefix = "";
|
|
111
111
|
switch (level) {
|
|
@@ -134,80 +134,63 @@ class ModalityLogger {
|
|
|
134
134
|
if (categroy) {
|
|
135
135
|
prefix += ` [${categroy}]`;
|
|
136
136
|
}
|
|
137
|
-
return
|
|
137
|
+
return prefix;
|
|
138
138
|
}
|
|
139
139
|
log(level, payload, categroy) {
|
|
140
140
|
if (!this.shouldLog(level))
|
|
141
141
|
return;
|
|
142
|
-
const
|
|
142
|
+
const prefix = this.format(level, categroy);
|
|
143
|
+
console.group(prefix);
|
|
143
144
|
switch (level) {
|
|
144
145
|
case "debug":
|
|
145
|
-
console.debug(
|
|
146
|
-
`, prefix, result, `
|
|
147
|
-
`);
|
|
146
|
+
console.debug(payload);
|
|
148
147
|
break;
|
|
149
148
|
case "info":
|
|
150
|
-
console.
|
|
151
|
-
`, prefix);
|
|
152
|
-
console.dir(result, {
|
|
149
|
+
console.dir(payload, {
|
|
153
150
|
depth: null,
|
|
154
151
|
colors: true,
|
|
155
152
|
maxArrayLength: null
|
|
156
153
|
});
|
|
157
|
-
console.log(`
|
|
158
|
-
`);
|
|
159
154
|
break;
|
|
160
155
|
case "warn":
|
|
161
|
-
console.
|
|
162
|
-
`, prefix);
|
|
163
|
-
console.warn(result);
|
|
156
|
+
console.warn(payload);
|
|
164
157
|
console.log(`
|
|
165
158
|
`);
|
|
166
159
|
break;
|
|
167
160
|
case "error":
|
|
168
|
-
const error =
|
|
169
|
-
if (error instanceof Error) {
|
|
170
|
-
delete
|
|
161
|
+
const error = payload.error;
|
|
162
|
+
if (error instanceof Error || error.stack) {
|
|
163
|
+
delete payload.error;
|
|
171
164
|
const { message, stack, ...restError } = error;
|
|
172
165
|
if (stack) {
|
|
173
166
|
if (Object.keys(restError).length) {
|
|
174
|
-
console.error(`
|
|
175
|
-
`,
|
|
176
|
-
`, stack, `
|
|
177
|
-
`);
|
|
167
|
+
console.error(restError, `
|
|
168
|
+
`, stack);
|
|
178
169
|
} else {
|
|
179
|
-
console.error(
|
|
180
|
-
`, prefix, `
|
|
181
|
-
`, stack, `
|
|
182
|
-
`);
|
|
170
|
+
console.error(stack);
|
|
183
171
|
}
|
|
184
172
|
} else {
|
|
185
173
|
if (message) {
|
|
186
|
-
|
|
174
|
+
payload.error = message;
|
|
187
175
|
}
|
|
188
|
-
console.error(
|
|
189
|
-
`, prefix, result, `
|
|
190
|
-
`);
|
|
176
|
+
console.error(payload);
|
|
191
177
|
}
|
|
192
178
|
} else {
|
|
193
|
-
console.error(
|
|
194
|
-
`, prefix, result, `
|
|
195
|
-
`);
|
|
179
|
+
console.error(payload);
|
|
196
180
|
}
|
|
197
181
|
break;
|
|
198
182
|
case "success":
|
|
199
|
-
console.
|
|
200
|
-
`, prefix, result, `
|
|
201
|
-
`);
|
|
183
|
+
console.error(payload);
|
|
202
184
|
break;
|
|
203
185
|
}
|
|
186
|
+
console.groupEnd();
|
|
204
187
|
}
|
|
205
|
-
cook(
|
|
206
|
-
const
|
|
188
|
+
cook(payload, data) {
|
|
189
|
+
const newPayload = typeof payload === "string" ? { message: payload } : payload;
|
|
207
190
|
if (data) {
|
|
208
|
-
|
|
191
|
+
newPayload.data = data;
|
|
209
192
|
}
|
|
210
|
-
return
|
|
193
|
+
return newPayload;
|
|
211
194
|
}
|
|
212
195
|
debug(message, data) {
|
|
213
196
|
this.log("debug", this.cook(message, data));
|
|
@@ -246,7 +229,7 @@ function withErrorHandling(fn, operation) {
|
|
|
246
229
|
return await fn(...args);
|
|
247
230
|
} catch (error) {
|
|
248
231
|
if (error instanceof ErrorCode) {
|
|
249
|
-
logger.error(`${operation || "
|
|
232
|
+
logger.error(`${operation || "Unknown operation"} failed: ${error.code}`, {
|
|
250
233
|
code: error.code,
|
|
251
234
|
cause: error.cause,
|
|
252
235
|
stack: error.stack
|
|
@@ -21,7 +21,7 @@ export declare class ModalityLogger {
|
|
|
21
21
|
* For control display logging level, the level could not set by user.
|
|
22
22
|
*/
|
|
23
23
|
log(level: LogLevel, payload: any, categroy?: string): void;
|
|
24
|
-
cook(
|
|
24
|
+
cook(payload: any, data?: any): any;
|
|
25
25
|
debug(message: string, data?: any): void;
|
|
26
26
|
info(message: string, data?: any): void;
|
|
27
27
|
warn(message: string, data?: any): void;
|
package/package.json
CHANGED