@subsquid/logger 0.1.0 → 0.3.0
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/README.md +6 -6
- package/lib/demo.js +9 -1
- package/lib/demo.js.map +1 -1
- package/lib/logger.d.ts +1 -1
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +4 -0
- package/lib/logger.js.map +1 -1
- package/lib/sinks/pretty.d.ts +4 -3
- package/lib/sinks/pretty.d.ts.map +1 -1
- package/lib/sinks/pretty.js +46 -88
- package/lib/sinks/pretty.js.map +1 -1
- package/package.json +3 -3
- package/src/demo.ts +14 -1
- package/src/logger.ts +4 -1
- package/src/sinks/pretty.ts +53 -86
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ log.debug('message with severity debug')
|
|
|
15
15
|
log.info({foo: 1, bar: 2}, 'message and some additional attributes')
|
|
16
16
|
|
|
17
17
|
// info message consisting only of attributes
|
|
18
|
-
log.info({a: 1, b: 2, c: 3, array: [4, 5]})
|
|
18
|
+
log.info({a: 1, b: 2, c: 3, array: [4, 5], obj: {foo: 'foo', bar: "bar"}})
|
|
19
19
|
|
|
20
20
|
// pass an Error object inplace of attributes
|
|
21
21
|
log.warn(new Error('Some error occured'))
|
|
@@ -63,9 +63,9 @@ When `stderr` is connected to a terminal, log records will be pretty printed.
|
|
|
63
63
|
Otherwise, log records will be written as JSON lines.
|
|
64
64
|
|
|
65
65
|
```
|
|
66
|
-
{"level":2,"time":
|
|
67
|
-
{"level":2,"time":
|
|
68
|
-
{"level":2,"time":
|
|
69
|
-
{"level":3,"time":
|
|
70
|
-
{"level":4,"time":
|
|
66
|
+
{"level":2,"time":1669387525765,"ns":"sqd:demo","msg":"message with severity info"}
|
|
67
|
+
{"level":2,"time":1669387525766,"ns":"sqd:demo","msg":"message and some additional attributes","foo":1,"bar":2}
|
|
68
|
+
{"level":2,"time":1669387525766,"ns":"sqd:demo","a":1,"b":2,"c":3,"array":[4,5,6],"obj":{"foo":"foo","bar":"bar"}}
|
|
69
|
+
{"level":3,"time":1669387525766,"ns":"sqd:demo","err":{"stack":"Error: Some error occured\n at Object.<anonymous> (/Users/eldar/dev/squid/util/logger/lib/demo.js:11:10)\n at Module._compile (node:internal/modules/cjs/loader:1159:14)\n at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)\n at Module.load (node:internal/modules/cjs/loader:1037:32)\n at Module._load (node:internal/modules/cjs/loader:878:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n at node:internal/main/run_main_module:23:47"}}
|
|
70
|
+
{"level":4,"time":1669387525766,"ns":"sqd:demo","msg":"weird","err":{"stack":"Error: Another error\n at Object.<anonymous> (/Users/eldar/dev/squid/util/logger/lib/demo.js:13:18)\n at Module._compile (node:internal/modules/cjs/loader:1159:14)\n at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)\n at Module.load (node:internal/modules/cjs/loader:1037:32)\n at Module._load (node:internal/modules/cjs/loader:878:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n at node:internal/main/run_main_module:23:47"},"a":1,"b":2}
|
|
71
71
|
```
|
package/lib/demo.js
CHANGED
|
@@ -6,7 +6,7 @@ log.info('message with severity info');
|
|
|
6
6
|
log.debug('message with severity debug');
|
|
7
7
|
log.info({ foo: 1, bar: 2 }, 'message and some additional attributes');
|
|
8
8
|
// info message consisting only of attributes
|
|
9
|
-
log.info({ a: 1, b: 2, c: 3, array: [4, 5,
|
|
9
|
+
log.info({ a: 1, b: 2, c: 3, array: [4, 5, 6], obj: { foo: 'foo', bar: "bar" } });
|
|
10
10
|
// pass an Error object inplace of attributes
|
|
11
11
|
log.warn(new Error('Some error occured'));
|
|
12
12
|
// Error together with some other attributes and message
|
|
@@ -16,4 +16,12 @@ log.error({ err: new Error('Another error'), a: 1, b: 2 }, 'weird');
|
|
|
16
16
|
const sqlLog = log.child('sql', { req: 1 });
|
|
17
17
|
sqlLog.debug('connecting to database');
|
|
18
18
|
sqlLog.debug({ sql: 'SELECT max(id) FROM status' });
|
|
19
|
+
log.info(new Map([['a', 1], ['b', 2], ['c', 3]]));
|
|
20
|
+
const recursive = {};
|
|
21
|
+
recursive.self = recursive;
|
|
22
|
+
log.info({ recursive });
|
|
23
|
+
const err = new Error('Error with properties');
|
|
24
|
+
err.foo = 1;
|
|
25
|
+
err.bar = 2;
|
|
26
|
+
log.error(err);
|
|
19
27
|
//# sourceMappingURL=demo.js.map
|
package/lib/demo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":";;AAAA,mCAAoC;AAEpC,MAAM,GAAG,GAAG,IAAA,oBAAY,EAAC,UAAU,CAAC,CAAA;AAEpC,GAAG,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;AACtC,GAAG,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;AAExC,GAAG,CAAC,IAAI,CAAC,EAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC,EAAE,wCAAwC,CAAC,CAAA;AAEpE,6CAA6C;AAC7C,GAAG,CAAC,IAAI,CAAC,EAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":";;AAAA,mCAAoC;AAEpC,MAAM,GAAG,GAAG,IAAA,oBAAY,EAAC,UAAU,CAAC,CAAA;AAEpC,GAAG,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;AACtC,GAAG,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;AAExC,GAAG,CAAC,IAAI,CAAC,EAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC,EAAE,wCAAwC,CAAC,CAAA;AAEp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,GAAG,GAAG,CAAC,CAAA;AACX,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA"}
|
package/lib/logger.d.ts
CHANGED
package/lib/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,QAAQ,EAAC,MAAM,SAAS,CAAA;AAGxC,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,QAAQ,CAAA;IACf,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,KAAK,CAAA;CACd;AAGD,oBAAY,IAAI,GAAG,CAAC,GAAG,EAAE,SAAS,KAAK,IAAI,CAAA;AAG3C,qBAAa,MAAM;IAEX,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,UAAU,CAAC;gBAFX,IAAI,EAAE,IAAI,EACV,EAAE,EAAE,MAAM,EACV,UAAU,CAAC,oBAAQ;IAI/B,IAAI,KAAK,IAAI,QAAQ,CAEpB;IAED,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IACjC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;IAkB9C,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAC1C,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAwB/D,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IACzB,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAK9C,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IACzB,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAK9C,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IACxB,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAK7C,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IACxB,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAK7C,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IACzB,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAK9C,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAChC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAKrD,OAAO,IAAI,OAAO;IAIlB,OAAO,IAAI,OAAO;IAIlB,MAAM,IAAI,OAAO;IAIjB,MAAM,IAAI,OAAO;IAIjB,OAAO,IAAI,OAAO;IAIlB,OAAO,IAAI,OAAO;CAGrB"}
|
package/lib/logger.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Logger = void 0;
|
|
4
|
+
const util_internal_json_1 = require("@subsquid/util-internal-json");
|
|
4
5
|
const level_1 = require("./level");
|
|
5
6
|
class Logger {
|
|
6
7
|
constructor(sink, ns, attributes) {
|
|
@@ -41,6 +42,9 @@ class Logger {
|
|
|
41
42
|
if (attributes instanceof Error) {
|
|
42
43
|
attributes = { err: attributes };
|
|
43
44
|
}
|
|
45
|
+
else if (attributes instanceof Map || attributes instanceof Set) {
|
|
46
|
+
attributes = (0, util_internal_json_1.toJSON)(attributes);
|
|
47
|
+
}
|
|
44
48
|
let rec = {
|
|
45
49
|
level,
|
|
46
50
|
time: Date.now(),
|
package/lib/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAexC,MAAa,MAAM;IACf,YACY,IAAU,EACV,EAAU,EACV,UAAmB;QAFnB,SAAI,GAAJ,IAAI,CAAM;QACV,OAAE,GAAF,EAAE,CAAQ;QACV,eAAU,GAAV,UAAU,CAAS;IAE/B,CAAC;IAED,IAAI,KAAK;QACL,OAAO,cAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC9B,CAAC;IAID,KAAK,CAAC,cAA+B,EAAE,UAAmB;QACtD,IAAI,EAAE,GAAG,IAAI,CAAC,EAAE,CAAA;QAChB,IAAI,OAAO,cAAc,IAAI,QAAQ,EAAE;YACnC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,cAAc,EAAE,CAAC,CAAC,CAAC,cAAc,CAAA;SACvD;aAAM;YACH,UAAU,GAAG,cAAc,CAAA;SAC9B;QACD,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,UAAU,EAAE;gBACZ,UAAU,GAAG,EAAC,GAAG,IAAI,CAAC,UAAU,EAAE,GAAG,UAAU,EAAC,CAAA;aACnD;iBAAM;gBACH,UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;aAC/B;SACJ;QACD,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,CAAA;IAChD,CAAC;IAID,KAAK,CAAC,KAAe,EAAE,UAAgB,EAAE,GAAS;QAC9C,IA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AC,KAAK,IAAI,gBAAQ,CAAC,KAAK,CAAA;IACvC,CAAC;CACJ;AAnHD,wBAmHC;AAGD,SAAS,aAAa,CAAC,GAAQ,EAAE,MAAW;IACxC,KAAK,IAAI,GAAG,IAAI,GAAG,EAAE;QACjB,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QAClB,QAAQ,GAAG,EAAE;YACT,KAAK,MAAM,CAAC;YACZ,KAAK,OAAO,CAAC;YACb,KAAK,IAAI,CAAC;YACV,KAAK,KAAK;gBACN,MAAK;YACT;gBACI,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAA;SACxB;KACJ;AACL,CAAC"}
|
package/lib/sinks/pretty.d.ts
CHANGED
|
@@ -3,16 +3,17 @@ export declare class Printer {
|
|
|
3
3
|
private out;
|
|
4
4
|
private hasColor;
|
|
5
5
|
private prefix?;
|
|
6
|
-
private
|
|
7
|
-
private style?;
|
|
8
|
-
private seenRecursion;
|
|
6
|
+
private color?;
|
|
9
7
|
constructor(out: (line: string) => void, hasColor: boolean);
|
|
8
|
+
private applyColor;
|
|
9
|
+
private style;
|
|
10
10
|
private line;
|
|
11
11
|
private text;
|
|
12
12
|
private begin;
|
|
13
13
|
private end;
|
|
14
14
|
private property;
|
|
15
15
|
print(rec: LogRecord): void;
|
|
16
|
+
private formatHead;
|
|
16
17
|
reset(): void;
|
|
17
18
|
}
|
|
18
19
|
export declare function prettyStderrSink(rec: LogRecord): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pretty.d.ts","sourceRoot":"","sources":["../../src/sinks/pretty.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pretty.d.ts","sourceRoot":"","sources":["../../src/sinks/pretty.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAA;AAGnC,qBAAa,OAAO;IAIJ,OAAO,CAAC,GAAG;IAA0B,OAAO,CAAC,QAAQ;IAHjE,OAAO,CAAC,MAAM,CAAC,CAAQ;IACvB,OAAO,CAAC,KAAK,CAAC,CAAQ;gBAEF,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAAU,QAAQ,EAAE,OAAO;IAE1E,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,IAAI;IASZ,OAAO,CAAC,IAAI;IAMZ,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,GAAG;IAKX,OAAO,CAAC,QAAQ;IAmChB,KAAK,CAAC,GAAG,EAAE,SAAS;IA+BpB,OAAO,CAAC,UAAU;IAelB,KAAK,IAAI,IAAI;CAIhB;AAkED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAcrD"}
|
package/lib/sinks/pretty.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.prettyStderrSink = exports.Printer = void 0;
|
|
7
7
|
const util_internal_hex_1 = require("@subsquid/util-internal-hex");
|
|
8
|
+
const util_internal_json_1 = require("@subsquid/util-internal-json");
|
|
8
9
|
const assert_1 = __importDefault(require("assert"));
|
|
9
10
|
const supports_color_1 = require("supports-color");
|
|
10
11
|
const level_1 = require("../level");
|
|
@@ -12,13 +13,26 @@ class Printer {
|
|
|
12
13
|
constructor(out, hasColor) {
|
|
13
14
|
this.out = out;
|
|
14
15
|
this.hasColor = hasColor;
|
|
15
|
-
this.visited = new Set();
|
|
16
|
-
this.seenRecursion = false;
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
17
|
+
applyColor(s) {
|
|
18
|
+
if (this.hasColor && this.color && s) {
|
|
19
|
+
return `\u001b[${this.color}m${s}\u001b[0m`;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return s;
|
|
21
23
|
}
|
|
24
|
+
}
|
|
25
|
+
style(style, s) {
|
|
26
|
+
if (this.hasColor && style && s) {
|
|
27
|
+
s = style + s + '\u001b[0m';
|
|
28
|
+
if (this.color) {
|
|
29
|
+
s = `\u001b[0m` + s + `\u001b[${this.color}m`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return s;
|
|
33
|
+
}
|
|
34
|
+
line(s) {
|
|
35
|
+
s = this.applyColor(s);
|
|
22
36
|
if (this.prefix) {
|
|
23
37
|
this.out(this.prefix.prepend(s));
|
|
24
38
|
}
|
|
@@ -33,10 +47,7 @@ class Printer {
|
|
|
33
47
|
}
|
|
34
48
|
begin(prefix, width) {
|
|
35
49
|
width = width == null ? prefix.length : width;
|
|
36
|
-
|
|
37
|
-
prefix = this.style.open + prefix + this.style.close;
|
|
38
|
-
}
|
|
39
|
-
this.prefix = new Prefix(prefix, width, this.prefix);
|
|
50
|
+
this.prefix = new Prefix(this.applyColor(prefix), width, this.prefix);
|
|
40
51
|
}
|
|
41
52
|
end() {
|
|
42
53
|
(0, assert_1.default)(this.prefix != null);
|
|
@@ -65,71 +76,28 @@ class Printer {
|
|
|
65
76
|
else if (typeof val?.toJSON == 'function') {
|
|
66
77
|
this.property(prefix, val.toJSON());
|
|
67
78
|
}
|
|
68
|
-
else if (Array.isArray(val)) {
|
|
69
|
-
if (val.length == 0) {
|
|
70
|
-
this.line(`${prefix} []`);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
if (this.visited.has(val)) {
|
|
74
|
-
this.seenRecursion = true;
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
this.visited.add(val);
|
|
79
|
-
}
|
|
80
|
-
this.line(prefix);
|
|
81
|
-
for (let item of val) {
|
|
82
|
-
this.property(' -', item);
|
|
83
|
-
}
|
|
84
|
-
this.visited.delete(val);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
79
|
else if (val == null) {
|
|
88
80
|
this.line(`${prefix} null`);
|
|
89
81
|
}
|
|
90
82
|
else {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
this.visited.add(val);
|
|
83
|
+
let text;
|
|
84
|
+
try {
|
|
85
|
+
text = JSON.stringify((0, util_internal_json_1.toJSON)(val));
|
|
97
86
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
props = { ...val, stack: val.stack || val.toString() };
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
props = val;
|
|
104
|
-
}
|
|
105
|
-
let has = false;
|
|
106
|
-
for (let key in props) {
|
|
107
|
-
if (!has) {
|
|
108
|
-
if (prefix == ' -') {
|
|
109
|
-
this.begin(prefix);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this.line(prefix);
|
|
113
|
-
this.begin(' ');
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
has = true;
|
|
117
|
-
this.property(key + ':', props[key]);
|
|
87
|
+
catch (e) {
|
|
88
|
+
text = this.style('\u001b[31m', `failed to serialize logged value: ${e}`);
|
|
118
89
|
}
|
|
119
|
-
|
|
120
|
-
this.end();
|
|
121
|
-
}
|
|
122
|
-
this.visited.delete(val);
|
|
90
|
+
this.line(`${prefix} ${text}`);
|
|
123
91
|
}
|
|
124
92
|
break;
|
|
125
93
|
}
|
|
126
94
|
}
|
|
127
95
|
print(rec) {
|
|
128
|
-
this.begin(formatHead(rec
|
|
96
|
+
this.begin(this.formatHead(rec), 14 + (rec.ns ? rec.ns.length + 1 : 0));
|
|
129
97
|
if (rec.msg) {
|
|
130
98
|
this.text(rec.msg);
|
|
131
99
|
}
|
|
132
|
-
this.
|
|
100
|
+
this.color = '2'; // dim
|
|
133
101
|
if (rec.err instanceof Error) {
|
|
134
102
|
this.text(rec.err.stack || rec.err.toString());
|
|
135
103
|
}
|
|
@@ -143,8 +111,10 @@ class Printer {
|
|
|
143
111
|
default:
|
|
144
112
|
if (key == 'err' && rec.err instanceof Error) {
|
|
145
113
|
// already printed the stack trace above
|
|
146
|
-
// print only the rest of props
|
|
147
|
-
|
|
114
|
+
// print only the rest of props and indented like the stack trace
|
|
115
|
+
for (let k in rec.err) {
|
|
116
|
+
this.property(` ${k}:`, rec.err[k]);
|
|
117
|
+
}
|
|
148
118
|
}
|
|
149
119
|
else {
|
|
150
120
|
this.property(key + ':', rec[key]);
|
|
@@ -152,39 +122,27 @@ class Printer {
|
|
|
152
122
|
}
|
|
153
123
|
}
|
|
154
124
|
this.end();
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
125
|
+
}
|
|
126
|
+
formatHead(rec) {
|
|
127
|
+
let time = formatTime(rec.time);
|
|
128
|
+
let level = level_1.LogLevel[rec.level].padEnd(5, ' ');
|
|
129
|
+
let ns = rec.ns;
|
|
130
|
+
if (this.hasColor) {
|
|
131
|
+
level = `\u001b[1m\u001b[${getLevelColor(rec.level)}m${level}\u001b[0m`;
|
|
132
|
+
ns = `\u001b[1m\u001b[34m${ns}\u001b[0m`;
|
|
133
|
+
}
|
|
134
|
+
let head = time + ' ' + level;
|
|
135
|
+
if (rec.ns) {
|
|
136
|
+
head += ' ' + ns;
|
|
164
137
|
}
|
|
138
|
+
return head;
|
|
165
139
|
}
|
|
166
140
|
reset() {
|
|
167
|
-
this.visited.clear();
|
|
168
141
|
this.prefix = undefined;
|
|
169
|
-
this.
|
|
170
|
-
this.seenRecursion = false;
|
|
142
|
+
this.color = undefined;
|
|
171
143
|
}
|
|
172
144
|
}
|
|
173
145
|
exports.Printer = Printer;
|
|
174
|
-
function formatHead(rec, withColor) {
|
|
175
|
-
let time = formatTime(rec.time);
|
|
176
|
-
let level = level_1.LogLevel[rec.level].padEnd(5, ' ');
|
|
177
|
-
let ns = rec.ns;
|
|
178
|
-
if (withColor) {
|
|
179
|
-
level = `\u001b[1m\u001b[${getLevelColor(rec.level)}m${level}\u001b[0m`;
|
|
180
|
-
ns = `\u001b[1m\u001b[34m${ns}\u001b[0m`;
|
|
181
|
-
}
|
|
182
|
-
let head = time + ' ' + level;
|
|
183
|
-
if (rec.ns) {
|
|
184
|
-
head += ' ' + ns;
|
|
185
|
-
}
|
|
186
|
-
return head;
|
|
187
|
-
}
|
|
188
146
|
function getLevelColor(level) {
|
|
189
147
|
switch (level) {
|
|
190
148
|
case level_1.LogLevel.TRACE:
|
package/lib/sinks/pretty.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pretty.js","sourceRoot":"","sources":["../../src/sinks/pretty.ts"],"names":[],"mappings":";;;;;;AAAA,mEAAiD;AACjD,oDAA2B;AAC3B,mDAAoD;AACpD,oCAAiC;AAIjC,MAAa,OAAO;
|
|
1
|
+
{"version":3,"file":"pretty.js","sourceRoot":"","sources":["../../src/sinks/pretty.ts"],"names":[],"mappings":";;;;;;AAAA,mEAAiD;AACjD,qEAAmD;AACnD,oDAA2B;AAC3B,mDAAoD;AACpD,oCAAiC;AAIjC,MAAa,OAAO;IAIhB,YAAoB,GAA2B,EAAU,QAAiB;QAAtD,QAAG,GAAH,GAAG,CAAwB;QAAU,aAAQ,GAAR,QAAQ,CAAS;IAAG,CAAC;IAEtE,UAAU,CAAC,CAAS;QACxB,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,EAAE;YAClC,OAAO,UAAU,IAAI,CAAC,KAAK,IAAI,CAAC,WAAW,CAAA;SAC9C;aAAM;YACH,OAAO,CAAC,CAAA;SACX;IACL,CAAC;IAEO,KAAK,CAAC,KAAa,EAAE,CAAS;QAClC,IAAI,IAAI,CAAC,QAAQ,IAAI,KAAK,IAAI,CAAC,EAAE;YAC7B,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,WAAW,CAAA;YAC3B,IAAI,IAAI,CAAC,KAAK,EAAE;gBACZ,CAAC,GAAG,WAAW,GAAG,CAAC,GAAG,UAAU,IAAI,CAAC,KAAK,GAAG,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,CAAA;AAGjB,SAAgB,gBAAgB,CAAC,GAAc;IAC3C,IAAI;QACA,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;KACrB;IAAC,OAAM,CAAM,EAAE;QACZ,OAAO,CAAC,KAAK,EAAE,CAAA;QACf,OAAO,CAAC,KAAK,CAAC;YACV,EAAE,EAAE,KAAK;YACT,KAAK,EAAE,gBAAQ,CAAC,KAAK;YACrB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,GAAG,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,EAAE;SAC/B,CAAC,CAAA;KACL;YAAS;QACN,OAAO,CAAC,KAAK,EAAE,CAAA;KAClB;AACL,CAAC;AAdD,4CAcC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subsquid/logger",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Lightweight library for structured logging",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": "git@github.com:subsquid/squid.git",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"main": "lib/index.js",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@subsquid/util-internal-hex": "^0.0.1",
|
|
17
|
-
"@subsquid/util-internal-json": "^0.
|
|
17
|
+
"@subsquid/util-internal-json": "^0.2.0",
|
|
18
18
|
"supports-color": "^8.1.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"build": "rm -rf lib && tsc",
|
|
30
30
|
"test": "mocha lib/**/*.test.js"
|
|
31
31
|
},
|
|
32
|
-
"readme": "# @subsquid/logger\n\nLightweight structured logger for squid framework.\n\n## Usage\n\n```typescript\nimport {createLogger} from \"@subsquid/logger\"\n\nconst log = createLogger('sqd:demo')\n\nlog.info('message with severity info')\nlog.debug('message with severity debug')\n\nlog.info({foo: 1, bar: 2}, 'message and some additional attributes')\n\n// info message consisting only of attributes\nlog.info({a: 1, b: 2, c: 3, array: [4, 5]}) \n\n// pass an Error object inplace of attributes\nlog.warn(new Error('Some error occured'))\n\n// Error together with some other attributes and message\nlog.error({err: new Error('Another error'), a: 1, b: 2}, 'weird')\n\n// create a child logger instance with namespace `sqd:demo:sql` \n// and `req: 1` attribute attached to every log record\nconst sqlLog = log.child('sql', {req: 1})\nsqlLog.debug('connecting to database')\nsqlLog.debug({sql: 'SELECT max(id) FROM status'})\n```\n\n## Configuration\n\nThere are 6 log levels available: `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`.\n\nThe log level of each logger instance is solely determined by its namespace and specified\nvia set of `SQD_TRACE`, ..., `SQD_FATAL` environment variables.\nThe default log level is `INFO`. \n\nUsers override the default log level by setting in appropriate \nenvironment variable a pattern which matches the logger's namespace.\n\n* `SQD_DEBUG=*` - sets the log level to `DEBUG` for all loggers.\n* `SQD_DEBUG=foo` - loggers `foo`, `foo:bar`, `foo:a:b`, etc will have a `DEBUG` level.\n* `SQD_DEBUG=a:b*:c,d` - loggers `a:b:c`, `a:baz:c`, `a:baz:c:foo`, `d`, etc will have a `DEBUG` level, logger `a:z:c` will not.\n\nWhen logger is matched by multiple `SQD_*` variables, the match with the highest specificity wins.\nWhen specificities are equal, the most verbose matched log level will be effective.\n\nSpecificity is computed as a number of namespace characters \nwhich are not matched by wildcards and which are not part of a child namespace.\nFor example, given a pattern `foo*bar`, the specificity of `foo:bar:baz:qux`, `foobar` and `foobazbar` is `6`.\n\n## Output\n\nThe logger always writes to `stderr`. \n\nWhen `stderr` is connected to a terminal, log records will be pretty printed.\n\n\n\nOtherwise, log records will be written as JSON lines.\n\n```\n{\"level\":2,\"time\":
|
|
32
|
+
"readme": "# @subsquid/logger\n\nLightweight structured logger for squid framework.\n\n## Usage\n\n```typescript\nimport {createLogger} from \"@subsquid/logger\"\n\nconst log = createLogger('sqd:demo')\n\nlog.info('message with severity info')\nlog.debug('message with severity debug')\n\nlog.info({foo: 1, bar: 2}, 'message and some additional attributes')\n\n// info message consisting only of attributes\nlog.info({a: 1, b: 2, c: 3, array: [4, 5], obj: {foo: 'foo', bar: \"bar\"}}) \n\n// pass an Error object inplace of attributes\nlog.warn(new Error('Some error occured'))\n\n// Error together with some other attributes and message\nlog.error({err: new Error('Another error'), a: 1, b: 2}, 'weird')\n\n// create a child logger instance with namespace `sqd:demo:sql` \n// and `req: 1` attribute attached to every log record\nconst sqlLog = log.child('sql', {req: 1})\nsqlLog.debug('connecting to database')\nsqlLog.debug({sql: 'SELECT max(id) FROM status'})\n```\n\n## Configuration\n\nThere are 6 log levels available: `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`.\n\nThe log level of each logger instance is solely determined by its namespace and specified\nvia set of `SQD_TRACE`, ..., `SQD_FATAL` environment variables.\nThe default log level is `INFO`. \n\nUsers override the default log level by setting in appropriate \nenvironment variable a pattern which matches the logger's namespace.\n\n* `SQD_DEBUG=*` - sets the log level to `DEBUG` for all loggers.\n* `SQD_DEBUG=foo` - loggers `foo`, `foo:bar`, `foo:a:b`, etc will have a `DEBUG` level.\n* `SQD_DEBUG=a:b*:c,d` - loggers `a:b:c`, `a:baz:c`, `a:baz:c:foo`, `d`, etc will have a `DEBUG` level, logger `a:z:c` will not.\n\nWhen logger is matched by multiple `SQD_*` variables, the match with the highest specificity wins.\nWhen specificities are equal, the most verbose matched log level will be effective.\n\nSpecificity is computed as a number of namespace characters \nwhich are not matched by wildcards and which are not part of a child namespace.\nFor example, given a pattern `foo*bar`, the specificity of `foo:bar:baz:qux`, `foobar` and `foobazbar` is `6`.\n\n## Output\n\nThe logger always writes to `stderr`. \n\nWhen `stderr` is connected to a terminal, log records will be pretty printed.\n\n\n\nOtherwise, log records will be written as JSON lines.\n\n```\n{\"level\":2,\"time\":1669387525765,\"ns\":\"sqd:demo\",\"msg\":\"message with severity info\"}\n{\"level\":2,\"time\":1669387525766,\"ns\":\"sqd:demo\",\"msg\":\"message and some additional attributes\",\"foo\":1,\"bar\":2}\n{\"level\":2,\"time\":1669387525766,\"ns\":\"sqd:demo\",\"a\":1,\"b\":2,\"c\":3,\"array\":[4,5,6],\"obj\":{\"foo\":\"foo\",\"bar\":\"bar\"}}\n{\"level\":3,\"time\":1669387525766,\"ns\":\"sqd:demo\",\"err\":{\"stack\":\"Error: Some error occured\\n at Object.<anonymous> (/Users/eldar/dev/squid/util/logger/lib/demo.js:11:10)\\n at Module._compile (node:internal/modules/cjs/loader:1159:14)\\n at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)\\n at Module.load (node:internal/modules/cjs/loader:1037:32)\\n at Module._load (node:internal/modules/cjs/loader:878:12)\\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\\n at node:internal/main/run_main_module:23:47\"}}\n{\"level\":4,\"time\":1669387525766,\"ns\":\"sqd:demo\",\"msg\":\"weird\",\"err\":{\"stack\":\"Error: Another error\\n at Object.<anonymous> (/Users/eldar/dev/squid/util/logger/lib/demo.js:13:18)\\n at Module._compile (node:internal/modules/cjs/loader:1159:14)\\n at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)\\n at Module.load (node:internal/modules/cjs/loader:1037:32)\\n at Module._load (node:internal/modules/cjs/loader:878:12)\\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\\n at node:internal/main/run_main_module:23:47\"},\"a\":1,\"b\":2}\n```\n"
|
|
33
33
|
}
|
package/src/demo.ts
CHANGED
|
@@ -8,7 +8,7 @@ log.debug('message with severity debug')
|
|
|
8
8
|
log.info({foo: 1, bar: 2}, 'message and some additional attributes')
|
|
9
9
|
|
|
10
10
|
// info message consisting only of attributes
|
|
11
|
-
log.info({a: 1, b: 2, c: 3, array: [4, 5,
|
|
11
|
+
log.info({a: 1, b: 2, c: 3, array: [4, 5, 6], obj: {foo: 'foo', bar: "bar"}})
|
|
12
12
|
|
|
13
13
|
// pass an Error object inplace of attributes
|
|
14
14
|
log.warn(new Error('Some error occured'))
|
|
@@ -21,3 +21,16 @@ log.error({err: new Error('Another error'), a: 1, b: 2}, 'weird')
|
|
|
21
21
|
const sqlLog = log.child('sql', {req: 1})
|
|
22
22
|
sqlLog.debug('connecting to database')
|
|
23
23
|
sqlLog.debug({sql: 'SELECT max(id) FROM status'})
|
|
24
|
+
|
|
25
|
+
log.info(new Map([['a', 1], ['b', 2], ['c', 3]]))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const recursive: any = {}
|
|
29
|
+
recursive.self = recursive
|
|
30
|
+
|
|
31
|
+
log.info({recursive})
|
|
32
|
+
|
|
33
|
+
const err: any = new Error('Error with properties')
|
|
34
|
+
err.foo = 1
|
|
35
|
+
err.bar = 2
|
|
36
|
+
log.error(err)
|
package/src/logger.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {toJSON} from '@subsquid/util-internal-json'
|
|
2
|
+
import {LEVELS, LogLevel} from './level'
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
export interface LogRecord {
|
|
@@ -55,6 +56,8 @@ export class Logger {
|
|
|
55
56
|
}
|
|
56
57
|
if (attributes instanceof Error) {
|
|
57
58
|
attributes = {err: attributes}
|
|
59
|
+
} else if (attributes instanceof Map || attributes instanceof Set) {
|
|
60
|
+
attributes = toJSON(attributes)
|
|
58
61
|
}
|
|
59
62
|
let rec: any = {
|
|
60
63
|
level,
|
package/src/sinks/pretty.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {toHex} from "@subsquid/util-internal-hex"
|
|
2
|
+
import {toJSON} from '@subsquid/util-internal-json'
|
|
2
3
|
import assert from "assert"
|
|
3
4
|
import {stderr as stderrColor} from "supports-color"
|
|
4
5
|
import {LogLevel} from "../level"
|
|
@@ -7,16 +8,30 @@ import {LogRecord} from "../logger"
|
|
|
7
8
|
|
|
8
9
|
export class Printer {
|
|
9
10
|
private prefix?: Prefix
|
|
10
|
-
private
|
|
11
|
-
private style?: {open: string, close: string}
|
|
12
|
-
private seenRecursion = false
|
|
11
|
+
private color?: string
|
|
13
12
|
|
|
14
13
|
constructor(private out: (line: string) => void, private hasColor: boolean) {}
|
|
15
14
|
|
|
16
|
-
private
|
|
17
|
-
if (
|
|
18
|
-
|
|
15
|
+
private applyColor(s: string): string {
|
|
16
|
+
if (this.hasColor && this.color && s) {
|
|
17
|
+
return `\u001b[${this.color}m${s}\u001b[0m`
|
|
18
|
+
} else {
|
|
19
|
+
return s
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private style(style: string, s: string): string {
|
|
24
|
+
if (this.hasColor && style && s) {
|
|
25
|
+
s = style + s + '\u001b[0m'
|
|
26
|
+
if (this.color) {
|
|
27
|
+
s = `\u001b[0m` + s + `\u001b[${this.color}m`
|
|
28
|
+
}
|
|
19
29
|
}
|
|
30
|
+
return s
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private line(s: string): void {
|
|
34
|
+
s = this.applyColor(s)
|
|
20
35
|
if (this.prefix) {
|
|
21
36
|
this.out(this.prefix.prepend(s))
|
|
22
37
|
} else {
|
|
@@ -32,10 +47,11 @@ export class Printer {
|
|
|
32
47
|
|
|
33
48
|
private begin(prefix: string, width?: number): void {
|
|
34
49
|
width = width == null ? prefix.length : width
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
50
|
+
this.prefix = new Prefix(
|
|
51
|
+
this.applyColor(prefix),
|
|
52
|
+
width,
|
|
53
|
+
this.prefix
|
|
54
|
+
)
|
|
39
55
|
}
|
|
40
56
|
|
|
41
57
|
private end(): void {
|
|
@@ -63,65 +79,27 @@ export class Printer {
|
|
|
63
79
|
this.line(`${prefix} ${val}`)
|
|
64
80
|
} else if (typeof (val as any)?.toJSON == 'function') {
|
|
65
81
|
this.property(prefix, (val as any).toJSON())
|
|
66
|
-
} else if (Array.isArray(val)) {
|
|
67
|
-
if (val.length == 0) {
|
|
68
|
-
this.line(`${prefix} []`)
|
|
69
|
-
} else {
|
|
70
|
-
if (this.visited.has(val)) {
|
|
71
|
-
this.seenRecursion = true
|
|
72
|
-
return
|
|
73
|
-
} else {
|
|
74
|
-
this.visited.add(val)
|
|
75
|
-
}
|
|
76
|
-
this.line(prefix)
|
|
77
|
-
for (let item of val) {
|
|
78
|
-
this.property(' -', item)
|
|
79
|
-
}
|
|
80
|
-
this.visited.delete(val)
|
|
81
|
-
}
|
|
82
82
|
} else if (val == null) {
|
|
83
83
|
this.line(`${prefix} null`)
|
|
84
84
|
} else {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
this.
|
|
90
|
-
}
|
|
91
|
-
let props: any
|
|
92
|
-
if (val instanceof Error) {
|
|
93
|
-
props = {...val, stack: val.stack || val.toString()}
|
|
94
|
-
} else {
|
|
95
|
-
props = val
|
|
96
|
-
}
|
|
97
|
-
let has = false
|
|
98
|
-
for (let key in props) {
|
|
99
|
-
if (!has) {
|
|
100
|
-
if (prefix == ' -') {
|
|
101
|
-
this.begin(prefix)
|
|
102
|
-
} else {
|
|
103
|
-
this.line(prefix)
|
|
104
|
-
this.begin(' ')
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
has = true
|
|
108
|
-
this.property(key + ':', props[key])
|
|
109
|
-
}
|
|
110
|
-
if (has) {
|
|
111
|
-
this.end()
|
|
85
|
+
let text
|
|
86
|
+
try {
|
|
87
|
+
text = JSON.stringify(toJSON(val))
|
|
88
|
+
} catch(e: any) {
|
|
89
|
+
text = this.style('\u001b[31m', `failed to serialize logged value: ${e}`)
|
|
112
90
|
}
|
|
113
|
-
this.
|
|
91
|
+
this.line(`${prefix} ${text}`)
|
|
114
92
|
}
|
|
115
93
|
break
|
|
116
94
|
}
|
|
117
95
|
}
|
|
118
96
|
|
|
119
97
|
print(rec: LogRecord) {
|
|
120
|
-
this.begin(formatHead(rec
|
|
98
|
+
this.begin(this.formatHead(rec), 14 + (rec.ns ? rec.ns.length + 1 : 0))
|
|
121
99
|
if (rec.msg) {
|
|
122
100
|
this.text(rec.msg)
|
|
123
101
|
}
|
|
124
|
-
this.
|
|
102
|
+
this.color = '2' // dim
|
|
125
103
|
if (rec.err instanceof Error) {
|
|
126
104
|
this.text(rec.err.stack || rec.err.toString())
|
|
127
105
|
}
|
|
@@ -135,48 +113,37 @@ export class Printer {
|
|
|
135
113
|
default:
|
|
136
114
|
if (key == 'err' && rec.err instanceof Error) {
|
|
137
115
|
// already printed the stack trace above
|
|
138
|
-
// print only the rest of props
|
|
139
|
-
|
|
116
|
+
// print only the rest of props and indented like the stack trace
|
|
117
|
+
for (let k in rec.err) {
|
|
118
|
+
this.property(` ${k}:`, (rec.err as any)[k])
|
|
119
|
+
}
|
|
140
120
|
} else {
|
|
141
121
|
this.property(key + ':', (rec as any)[key])
|
|
142
122
|
}
|
|
143
123
|
}
|
|
144
124
|
}
|
|
145
125
|
this.end()
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private formatHead(rec: LogRecord): string {
|
|
129
|
+
let time = formatTime(rec.time)
|
|
130
|
+
let level = LogLevel[rec.level].padEnd(5, ' ')
|
|
131
|
+
let ns = rec.ns
|
|
132
|
+
if (this.hasColor) {
|
|
133
|
+
level = `\u001b[1m\u001b[${getLevelColor(rec.level)}m${level}\u001b[0m`
|
|
134
|
+
ns = `\u001b[1m\u001b[34m${ns}\u001b[0m`
|
|
135
|
+
}
|
|
136
|
+
let head = time + ' ' + level
|
|
137
|
+
if (rec.ns) {
|
|
138
|
+
head += ' ' + ns
|
|
155
139
|
}
|
|
140
|
+
return head
|
|
156
141
|
}
|
|
157
142
|
|
|
158
143
|
reset(): void {
|
|
159
|
-
this.visited.clear()
|
|
160
144
|
this.prefix = undefined
|
|
161
|
-
this.
|
|
162
|
-
this.seenRecursion = false
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
function formatHead(rec: LogRecord, withColor?: boolean): string {
|
|
168
|
-
let time = formatTime(rec.time)
|
|
169
|
-
let level = LogLevel[rec.level].padEnd(5, ' ')
|
|
170
|
-
let ns = rec.ns
|
|
171
|
-
if (withColor) {
|
|
172
|
-
level = `\u001b[1m\u001b[${getLevelColor(rec.level)}m${level}\u001b[0m`
|
|
173
|
-
ns = `\u001b[1m\u001b[34m${ns}\u001b[0m`
|
|
174
|
-
}
|
|
175
|
-
let head = time + ' ' + level
|
|
176
|
-
if (rec.ns) {
|
|
177
|
-
head += ' ' + ns
|
|
145
|
+
this.color = undefined
|
|
178
146
|
}
|
|
179
|
-
return head
|
|
180
147
|
}
|
|
181
148
|
|
|
182
149
|
|