@ricdotnet/logger 0.4.0 → 0.4.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/dist/formatters/pretty.d.ts +2 -0
- package/dist/formatters/pretty.js +14 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/logger.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
export class PrettyFormatter {
|
|
2
|
+
indent = 2;
|
|
2
3
|
format(entry) {
|
|
3
4
|
const timestamp = new Date(entry.timestamp).toLocaleString();
|
|
4
|
-
const context = entry.context
|
|
5
|
-
return `[${timestamp}] [${entry.level.toUpperCase()}] ${entry.message}
|
|
5
|
+
const context = this.unwrapContext(entry.context ?? {}).join('\n');
|
|
6
|
+
return `[${timestamp}] [${entry.level.toUpperCase()}] ${entry.message}\n${context}`;
|
|
7
|
+
}
|
|
8
|
+
unwrapContext(context, unwrapped = [], level = 1) {
|
|
9
|
+
for (const key in context) {
|
|
10
|
+
if (typeof context[key] === 'object') {
|
|
11
|
+
unwrapped.push(`${' '.repeat(level * this.indent)}${key}`);
|
|
12
|
+
this.unwrapContext(context[key], unwrapped, level + 1);
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
unwrapped.push(`${' '.repeat(level * this.indent)}${key}=${context[key]}`);
|
|
16
|
+
}
|
|
17
|
+
return unwrapped;
|
|
6
18
|
}
|
|
7
19
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/logger.js
CHANGED