@lodestar/logger 1.35.0-dev.f80d2d52da → 1.35.0-dev.fcf8d024ea
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/lib/browser.d.ts.map +1 -0
- package/lib/browser.js +17 -17
- package/lib/browser.js.map +1 -1
- package/lib/empty.d.ts.map +1 -0
- package/lib/env.d.ts +1 -2
- package/lib/env.d.ts.map +1 -0
- package/lib/env.js.map +1 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/interface.d.ts +1 -1
- package/lib/interface.d.ts.map +1 -0
- package/lib/interface.js +1 -1
- package/lib/interface.js.map +1 -1
- package/lib/node.d.ts +1 -1
- package/lib/node.d.ts.map +1 -0
- package/lib/node.js +2 -0
- package/lib/node.js.map +1 -1
- package/lib/utils/consoleTransport.d.ts.map +1 -0
- package/lib/utils/consoleTransport.js +5 -1
- package/lib/utils/consoleTransport.js.map +1 -1
- package/lib/utils/format.d.ts.map +1 -0
- package/lib/utils/format.js +1 -1
- package/lib/utils/format.js.map +1 -1
- package/lib/utils/json.d.ts.map +1 -0
- package/lib/utils/timeFormat.d.ts.map +1 -0
- package/lib/winston.d.ts +1 -1
- package/lib/winston.d.ts.map +1 -0
- package/lib/winston.js +1 -0
- package/lib/winston.js.map +1 -1
- package/package.json +13 -10
- package/src/browser.ts +80 -0
- package/src/empty.ts +21 -0
- package/src/env.ts +26 -0
- package/src/index.ts +1 -0
- package/src/interface.ts +48 -0
- package/src/node.ts +158 -0
- package/src/utils/consoleTransport.ts +46 -0
- package/src/utils/format.ts +101 -0
- package/src/utils/json.ts +132 -0
- package/src/utils/timeFormat.ts +15 -0
- package/src/winston.ts +90 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAiB,eAAe,EAAiB,MAAM,gBAAgB,CAAC;AAG/E,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,QAAQ,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAKhE"}
|
package/lib/browser.js
CHANGED
|
@@ -5,25 +5,25 @@ export function getBrowserLogger(opts) {
|
|
|
5
5
|
return createWinstonLogger({ level: opts.level, module: opts.module ?? "", format: opts.format, timestampFormat: opts.timestampFormat }, [new BrowserConsole({ level: opts.level })]);
|
|
6
6
|
}
|
|
7
7
|
class BrowserConsole extends Transport {
|
|
8
|
+
name = "BrowserConsole";
|
|
9
|
+
levels = {
|
|
10
|
+
error: 0,
|
|
11
|
+
warn: 1,
|
|
12
|
+
info: 2,
|
|
13
|
+
verbose: 3,
|
|
14
|
+
debug: 4,
|
|
15
|
+
trace: 5,
|
|
16
|
+
};
|
|
17
|
+
methods = {
|
|
18
|
+
error: "error",
|
|
19
|
+
warn: "warn",
|
|
20
|
+
info: "info",
|
|
21
|
+
verbose: "log",
|
|
22
|
+
debug: "log",
|
|
23
|
+
trace: "log",
|
|
24
|
+
};
|
|
8
25
|
constructor(opts) {
|
|
9
26
|
super(opts);
|
|
10
|
-
this.name = "BrowserConsole";
|
|
11
|
-
this.levels = {
|
|
12
|
-
error: 0,
|
|
13
|
-
warn: 1,
|
|
14
|
-
info: 2,
|
|
15
|
-
verbose: 3,
|
|
16
|
-
debug: 4,
|
|
17
|
-
trace: 5,
|
|
18
|
-
};
|
|
19
|
-
this.methods = {
|
|
20
|
-
error: "error",
|
|
21
|
-
warn: "warn",
|
|
22
|
-
info: "info",
|
|
23
|
-
verbose: "log",
|
|
24
|
-
debug: "log",
|
|
25
|
-
trace: "log",
|
|
26
|
-
};
|
|
27
27
|
this.level = opts?.level && Object.prototype.hasOwnProperty.call(this.levels, opts.level) ? opts.level : "info";
|
|
28
28
|
}
|
|
29
29
|
log(info, callback) {
|
package/lib/browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAC,KAAK,EAAE,OAAO,EAAkC,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AA0BjD,MAAM,UAAU,gBAAgB,CAAC,IAAuB;IACtD,OAAO,mBAAmB,CACxB,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,CAAC,eAAe,EAAC,EAC1G,CAAC,IAAI,cAAc,CAAC,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAC,CAAC,CAAC,CAC1C,CAAC;AACJ,CAAC;AAED,MAAM,cAAe,SAAQ,SAAS;IACpC,IAAI,GAAG,gBAAgB,CAAC;IAChB,MAAM,GAA6B;QACzC,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,CAAC;QACP,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,CAAC;KACT,CAAC;IAEM,OAAO,GAA6B;QAC1C,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;KACb,CAAC;IAEF,YAAY,IAA0D;QACpE,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;IAClH,CAAC;IAED,GAAG,CAAC,IAAoB,EAAE,QAAoB;QAC5C,UAAU,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC5B,CAAC,EAAE,CAAC,CAAC,CAAC;QAEN,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACrC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAE9B,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAiB,CAAC,EAAE,CAAC;YAC/C,mBAAmB;YACnB,gFAAgF;YAChF,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;QAED,QAAQ,EAAE,CAAC;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"empty.d.ts","sourceRoot":"","sources":["../src/empty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAEvC,wBAAgB,cAAc,IAAI,MAAM,CAkBvC"}
|
package/lib/env.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Logger } from "@lodestar/utils";
|
|
2
|
-
import { LogLevel } from "@lodestar/utils";
|
|
1
|
+
import { LogLevel, Logger } from "@lodestar/utils";
|
|
3
2
|
import { BrowserLoggerOpts } from "./browser.js";
|
|
4
3
|
export declare function getEnvLogLevel(): LogLevel | null;
|
|
5
4
|
export declare function getEnvLogger(opts?: Partial<BrowserLoggerOpts>): Logger;
|
package/lib/env.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,iBAAiB,EAAmB,MAAM,cAAc,CAAC;AAIjE,wBAAgB,cAAc,IAAI,QAAQ,GAAG,IAAI,CAMhD;AAED,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAYtE"}
|
package/lib/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAS,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAoB,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACjE,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAG1C,MAAM,UAAU,cAAc;IAC5B,IAAI,OAAO,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IACjC,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS;QAAE,OAAO,OAAO,CAAC,GAAG,CAAC,SAAqB,CAAC;IACpE,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK;QAAE,OAAO,QAAQ,CAAC,KAAK,CAAC;IAC7C,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO;QAAE,OAAO,QAAQ,CAAC,OAAO,CAAC;IACjD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAiC;IAC5D,MAAM,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,cAAc,EAAE,CAAC;IAC9C,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAc,CAAC;IACrE,MAAM,eAAe,GACnB,IAAI,EAAE,eAAe;QACpB,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAC,CAAC,CAAC,CAAC,SAAS,CAAqB,CAAC;IAEnH,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,gBAAgB,CAAC,EAAC,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAC,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,cAAc,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/lib/interface.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LogData, LogHandler, LogLevel, Logger } from "@lodestar/utils";
|
|
2
1
|
import { LEVEL, MESSAGE } from "triple-beam";
|
|
2
|
+
import { LogData, LogHandler, LogLevel, Logger } from "@lodestar/utils";
|
|
3
3
|
export { LogLevel, LEVEL, MESSAGE };
|
|
4
4
|
export type { Logger, LogHandler, LogData };
|
|
5
5
|
export declare const logLevelNum: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAC,OAAO,EAAE,UAAU,EA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-
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAsB,QAAQ,EAAS,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAC,CAAC;AAGlC,MAAM,CAAC,MAAM,WAAW,GAA8B;IACpD,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACnB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IACrB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACnB,iFAAiF;IACjF,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAGjD,MAAM,CAAC,MAAM,UAAU,GAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAOzD,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,8CAAuB,CAAA;IACvB,wCAAiB,CAAA;IACjB,0CAAmB,CAAA;AACrB,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B"}
|
package/lib/node.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,IAAI,OAAO,EAAC,MAAM,SAAS,CAAC;AAE/C,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,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,IAAI,EAAE,cAAc,GAAG,iBAAiB;IAIjE,KAAK,CAAC,IAAI,EAAE,mBAAmB,GAAG,UAAU;IAkB5C,MAAM,IAAI,cAAc;CAGzB"}
|
package/lib/node.js
CHANGED
package/lib/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,kFAAkF;AAClF,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAC,mBAAmB,EAAC,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAE3C,MAAM,YAAY,GAAG,YAAY,CAAC;AAqDlC;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,IAAoB;IAChD,OAAO,iBAAiB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAoB;IACnD,MAAM,gBAAgB,GAAG,IAAI,mBAAmB,CAAC;QAC/C,gFAAgF;QAChF,YAAY,EAAE,IAAI,CAAC,KAAK;QACxB,WAAW,EAAE,IAAI;QACjB,gBAAgB,EAAE,IAAI;KACvB,CAAC,CAAC;IAEH,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/D,gBAAgB,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAsB,CAAC,gBAAgB,CAAC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AO,CAAC,QAAQ,CAAC,aAAa,CAA+B;IAC7D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAW;IAGxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IACnD,OAAO,CAAC,MAAM,CAAC,CAAS;gBAEZ,IAAI,EAAE;QAAC,YAAY,EAAE,QAAQ,CAAA;KAAC,GAAG,UAAU,CAAC,uBAAuB;IAS/E,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IAIrD,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI1C,MAAM,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,GAAG,IAAI;CAiB9G"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { transports } from "winston";
|
|
2
2
|
import { LEVEL } from "../interface.js";
|
|
3
3
|
export class ConsoleDynamicLevel extends transports.Console {
|
|
4
|
+
levelByModule = new Map();
|
|
5
|
+
defaultLevel;
|
|
6
|
+
// Define property from TransportStream that's not in the types
|
|
7
|
+
levels;
|
|
8
|
+
parent;
|
|
4
9
|
constructor(opts) {
|
|
5
10
|
super(opts);
|
|
6
|
-
this.levelByModule = new Map();
|
|
7
11
|
this.defaultLevel = opts.defaultLevel;
|
|
8
12
|
// Set level and parent to undefined so that underlying transport logs everything
|
|
9
13
|
this.level = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consoleTransport.js","sourceRoot":"","sources":["../../src/utils/consoleTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAC,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAC,KAAK,EAA2B,MAAM,iBAAiB,CAAC;AAEhE,MAAM,OAAO,mBAAoB,SAAQ,UAAU,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file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CAAC,CAAC;QACpC,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAAA,OAAO,OAAiB,MAAM,SAAS,CAAC;AAExC,OAAO,EAAC,aAAa,EAAsB,MAAM,iBAAiB,CAAC;AAInE,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAaxD,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CASrD"}
|
package/lib/utils/format.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LodestarError, isEmptyObject } from "@lodestar/utils";
|
|
2
1
|
import { format } from "winston";
|
|
2
|
+
import { LodestarError, isEmptyObject } from "@lodestar/utils";
|
|
3
3
|
import { TimestampFormatCode } from "../interface.js";
|
|
4
4
|
import { logCtxToJson, logCtxToString } from "./json.js";
|
|
5
5
|
import { formatEpochSlotTime } from "./timeFormat.js";
|
package/lib/utils/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AACxC,OAAO,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAgB,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAU,YAAY,EAAE,cAAc,EAAC,MAAM,WAAW,CAAC;AAChE,OAAO,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AAepD,MAAM,UAAU,SAAS,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F,CAAC,IAAI,CAAC,KAAK,YAAY,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;gBAC1F,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":"AAIA,KAAK,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAE1E,MAAM,MAAM,OAAO,GACf,YAAY,GACZ,YAAY,EAAE,GACd,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,GAC9B,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;AAErC;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,SAAI,EAAE,SAAS,UAAQ,GAAG,OAAO,CAoDhF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,SAAI,EAAE,SAAS,UAAQ,GAAG,MAAM,CAmDjF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeFormat.d.ts","sourceRoot":"","sources":["../../src/utils/timeFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,SAAa,GAAG,MAAM,CASjF"}
|
package/lib/winston.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import winston from "winston";
|
|
2
1
|
import type { Logger as Winston } from "winston";
|
|
2
|
+
import winston from "winston";
|
|
3
3
|
import { Logger, LoggerOptions } from "./interface.js";
|
|
4
4
|
import { LogData } from "./utils/json.js";
|
|
5
5
|
export declare function createWinstonLogger(options?: Partial<LoggerOptions>, transports?: winston.transport[]): Logger;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"winston.d.ts","sourceRoot":"","sources":["../src/winston.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,IAAI,OAAO,EAAC,MAAM,SAAS,CAAC;AAC/C,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAW,MAAM,EAAE,aAAa,EAAc,MAAM,gBAAgB,CAAC;AAE5E,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AA8BxC,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,GAAG,MAAM,CAElH;AAED,qBAAa,aAAc,YAAW,MAAM;IAC9B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO;gBAAhB,OAAO,EAAE,OAAO;IAE/C,MAAM,CAAC,QAAQ,CAAC,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,GAAG,aAAa;IAItG,MAAM,CAAC,qBAAqB,CAAC,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,GAAG,OAAO;IAc7G,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;IAI9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;IAI7D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;IAI7D,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;IAIhE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;IAI9D,OAAO,CAAC,cAAc;CAQvB"}
|
package/lib/winston.js
CHANGED
package/lib/winston.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston.js","sourceRoot":"","sources":["../src/winston.ts"],"names":[],"mappings":"AAAA,kFAAkF;
|
|
1
|
+
{"version":3,"file":"winston.js","sourceRoot":"","sources":["../src/winston.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAGlF,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,QAAQ,EAAyB,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AA+B5C,MAAM,UAAU,mBAAmB,CAAC,UAAkC,EAAE,EAAE,UAAgC;IACxG,OAAO,aAAa,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,OAAO,aAAa;IACO;IAA/B,YAA+B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAEnD,MAAM,CAAC,QAAQ,CAAC,UAAkC,EAAE,EAAE,UAAgC;QACpF,OAAO,IAAI,aAAa,CAAC,aAAa,CAAC,qBAAqB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;IACrF,CAAC;IAED,MAAM,C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QAE7G,wGAAwG;QACxG,6GAA6G;QAC7G,gHAAgH;QAChH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC,CAAC;IACrD,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -11,22 +11,27 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.35.0-dev.
|
|
14
|
+
"version": "1.35.0-dev.fcf8d024ea",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
+
"bun": "./src/index.ts",
|
|
18
19
|
"import": "./lib/index.js"
|
|
19
20
|
},
|
|
20
21
|
"./browser": {
|
|
22
|
+
"bun": "./src/browser.ts",
|
|
21
23
|
"import": "./lib/browser.js"
|
|
22
24
|
},
|
|
23
25
|
"./env": {
|
|
26
|
+
"bun": "./src/env.ts",
|
|
24
27
|
"import": "./lib/env.js"
|
|
25
28
|
},
|
|
26
29
|
"./node": {
|
|
30
|
+
"bun": "./src/node.ts",
|
|
27
31
|
"import": "./lib/node.js"
|
|
28
32
|
},
|
|
29
33
|
"./empty": {
|
|
34
|
+
"bun": "./src/empty.ts",
|
|
30
35
|
"import": "./lib/empty.js"
|
|
31
36
|
}
|
|
32
37
|
},
|
|
@@ -40,11 +45,9 @@
|
|
|
40
45
|
}
|
|
41
46
|
},
|
|
42
47
|
"files": [
|
|
43
|
-
"
|
|
44
|
-
"lib
|
|
45
|
-
"
|
|
46
|
-
"*.d.ts",
|
|
47
|
-
"*.js"
|
|
48
|
+
"src",
|
|
49
|
+
"lib",
|
|
50
|
+
"!**/*.tsbuildinfo"
|
|
48
51
|
],
|
|
49
52
|
"scripts": {
|
|
50
53
|
"clean": "rm -rf lib && rm -f *.tsbuildinfo",
|
|
@@ -63,14 +66,14 @@
|
|
|
63
66
|
},
|
|
64
67
|
"types": "lib/index.d.ts",
|
|
65
68
|
"dependencies": {
|
|
66
|
-
"@lodestar/utils": "1.35.0-dev.
|
|
69
|
+
"@lodestar/utils": "1.35.0-dev.fcf8d024ea",
|
|
67
70
|
"winston": "^3.8.2",
|
|
68
71
|
"winston-daily-rotate-file": "^4.7.1",
|
|
69
72
|
"winston-transport": "^4.5.0"
|
|
70
73
|
},
|
|
71
74
|
"devDependencies": {
|
|
72
|
-
"@chainsafe/threads": "^1.11.
|
|
73
|
-
"@lodestar/test-utils": "1.35.0-dev.
|
|
75
|
+
"@chainsafe/threads": "^1.11.3",
|
|
76
|
+
"@lodestar/test-utils": "1.35.0-dev.fcf8d024ea",
|
|
74
77
|
"@types/triple-beam": "^1.3.2",
|
|
75
78
|
"triple-beam": "^1.3.0"
|
|
76
79
|
},
|
|
@@ -80,5 +83,5 @@
|
|
|
80
83
|
"beacon",
|
|
81
84
|
"blockchain"
|
|
82
85
|
],
|
|
83
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "d72abda1a1607ce062febfcfc4528b9e9848c288"
|
|
84
87
|
}
|
package/src/browser.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import winston from "winston";
|
|
2
|
+
import Transport from "winston-transport";
|
|
3
|
+
import {LogLevel, Logger} from "@lodestar/utils";
|
|
4
|
+
import {LEVEL, MESSAGE, TimestampFormat, WinstonLogInfo} from "./interface.js";
|
|
5
|
+
import {createWinstonLogger} from "./winston.js";
|
|
6
|
+
|
|
7
|
+
export type BrowserLoggerOpts = {
|
|
8
|
+
/**
|
|
9
|
+
* Module prefix for all logs
|
|
10
|
+
*/
|
|
11
|
+
module?: string;
|
|
12
|
+
level: LogLevel;
|
|
13
|
+
/**
|
|
14
|
+
* Rendering format for logs, defaults to "human"
|
|
15
|
+
*/
|
|
16
|
+
format?: "human" | "json";
|
|
17
|
+
/**
|
|
18
|
+
* Enables relative to genesis timestamp format
|
|
19
|
+
* ```
|
|
20
|
+
* timestampFormat = {
|
|
21
|
+
* format: TimestampFormatCode.EpochSlot,
|
|
22
|
+
* genesisTime: args.logFormatGenesisTime,
|
|
23
|
+
* secondsPerSlot: config.SECONDS_PER_SLOT,
|
|
24
|
+
* slotsPerEpoch: SLOTS_PER_EPOCH,
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
timestampFormat?: TimestampFormat;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function getBrowserLogger(opts: BrowserLoggerOpts): Logger {
|
|
32
|
+
return createWinstonLogger(
|
|
33
|
+
{level: opts.level, module: opts.module ?? "", format: opts.format, timestampFormat: opts.timestampFormat},
|
|
34
|
+
[new BrowserConsole({level: opts.level})]
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class BrowserConsole extends Transport {
|
|
39
|
+
name = "BrowserConsole";
|
|
40
|
+
private levels: Record<LogLevel, number> = {
|
|
41
|
+
error: 0,
|
|
42
|
+
warn: 1,
|
|
43
|
+
info: 2,
|
|
44
|
+
verbose: 3,
|
|
45
|
+
debug: 4,
|
|
46
|
+
trace: 5,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
private methods: Record<LogLevel, string> = {
|
|
50
|
+
error: "error",
|
|
51
|
+
warn: "warn",
|
|
52
|
+
info: "info",
|
|
53
|
+
verbose: "log",
|
|
54
|
+
debug: "log",
|
|
55
|
+
trace: "log",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
constructor(opts: winston.transport.TransportStreamOptions | undefined) {
|
|
59
|
+
super(opts);
|
|
60
|
+
this.level = opts?.level && Object.prototype.hasOwnProperty.call(this.levels, opts.level) ? opts.level : "info";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
log(info: WinstonLogInfo, callback: () => void): void {
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
this.emit("logged", info);
|
|
66
|
+
}, 0);
|
|
67
|
+
|
|
68
|
+
const val = this.levels[info[LEVEL]];
|
|
69
|
+
const mappedMethod = this.methods[info[LEVEL]];
|
|
70
|
+
const message = info[MESSAGE];
|
|
71
|
+
|
|
72
|
+
if (val <= this.levels[this.level as LogLevel]) {
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
// biome-ignore lint/suspicious/noConsole: We want the explicit usage of console
|
|
75
|
+
console[mappedMethod](message);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
callback();
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/empty.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {Logger} from "@lodestar/utils";
|
|
2
|
+
|
|
3
|
+
export function getEmptyLogger(): Logger {
|
|
4
|
+
return {
|
|
5
|
+
error: function error(): void {
|
|
6
|
+
// Do nothing
|
|
7
|
+
},
|
|
8
|
+
warn: function warn(): void {
|
|
9
|
+
// Do nothing
|
|
10
|
+
},
|
|
11
|
+
info: function info(): void {
|
|
12
|
+
// Do nothing
|
|
13
|
+
},
|
|
14
|
+
verbose: function verbose(): void {
|
|
15
|
+
// Do nothing
|
|
16
|
+
},
|
|
17
|
+
debug: function debug(): void {
|
|
18
|
+
// Do nothing
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
package/src/env.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {LogLevel, Logger} from "@lodestar/utils";
|
|
2
|
+
import {BrowserLoggerOpts, getBrowserLogger} from "./browser.js";
|
|
3
|
+
import {getEmptyLogger} from "./empty.js";
|
|
4
|
+
import {LogFormat, TimestampFormat} from "./interface.js";
|
|
5
|
+
|
|
6
|
+
export function getEnvLogLevel(): LogLevel | null {
|
|
7
|
+
if (process == null) return null;
|
|
8
|
+
if (process.env.LOG_LEVEL) return process.env.LOG_LEVEL as LogLevel;
|
|
9
|
+
if (process.env.DEBUG) return LogLevel.debug;
|
|
10
|
+
if (process.env.VERBOSE) return LogLevel.verbose;
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getEnvLogger(opts?: Partial<BrowserLoggerOpts>): Logger {
|
|
15
|
+
const level = opts?.level ?? getEnvLogLevel();
|
|
16
|
+
const format = (opts?.format ?? process.env.LOG_FORMAT) as LogFormat;
|
|
17
|
+
const timestampFormat =
|
|
18
|
+
opts?.timestampFormat ??
|
|
19
|
+
((process.env.LOG_TIMESTAMP_FORMAT ? {format: process.env.LOG_TIMESTAMP_FORMAT} : undefined) as TimestampFormat);
|
|
20
|
+
|
|
21
|
+
if (level != null) {
|
|
22
|
+
return getBrowserLogger({...opts, level, format, timestampFormat});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return getEmptyLogger();
|
|
26
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./interface.js";
|
package/src/interface.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {LEVEL, MESSAGE} from "triple-beam";
|
|
2
|
+
import {LogData, LogHandler, LogLevel, Logger} from "@lodestar/utils";
|
|
3
|
+
|
|
4
|
+
export {LogLevel, LEVEL, MESSAGE};
|
|
5
|
+
export type {Logger, LogHandler, LogData};
|
|
6
|
+
|
|
7
|
+
export const logLevelNum: {[K in LogLevel]: number} = {
|
|
8
|
+
[LogLevel.error]: 0,
|
|
9
|
+
[LogLevel.warn]: 1,
|
|
10
|
+
[LogLevel.info]: 2,
|
|
11
|
+
[LogLevel.verbose]: 3,
|
|
12
|
+
[LogLevel.debug]: 4,
|
|
13
|
+
/** Request in https://github.com/ChainSafe/lodestar/issues/4536 by eth-docker */
|
|
14
|
+
[LogLevel.trace]: 5,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const LogLevels = Object.values(LogLevel);
|
|
18
|
+
|
|
19
|
+
export type LogFormat = "human" | "json";
|
|
20
|
+
export const logFormats: LogFormat[] = ["human", "json"];
|
|
21
|
+
|
|
22
|
+
export type EpochSlotOpts = {
|
|
23
|
+
genesisTime: number;
|
|
24
|
+
secondsPerSlot: number;
|
|
25
|
+
slotsPerEpoch: number;
|
|
26
|
+
};
|
|
27
|
+
export enum TimestampFormatCode {
|
|
28
|
+
DateRegular = "regular",
|
|
29
|
+
Hidden = "hidden",
|
|
30
|
+
EpochSlot = "epoch",
|
|
31
|
+
}
|
|
32
|
+
export type TimestampFormat =
|
|
33
|
+
| {format: TimestampFormatCode.DateRegular}
|
|
34
|
+
| {format: TimestampFormatCode.Hidden}
|
|
35
|
+
| ({format: TimestampFormatCode.EpochSlot} & EpochSlotOpts);
|
|
36
|
+
|
|
37
|
+
export interface LoggerOptions {
|
|
38
|
+
level?: LogLevel;
|
|
39
|
+
module?: string;
|
|
40
|
+
format?: LogFormat;
|
|
41
|
+
timestampFormat?: TimestampFormat;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface WinstonLogInfo {
|
|
45
|
+
module: string;
|
|
46
|
+
[LEVEL]: LogLevel;
|
|
47
|
+
[MESSAGE]: string;
|
|
48
|
+
}
|
package/src/node.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type {Logger as Winston} from "winston";
|
|
3
|
+
// We want to keep `winston` export as it's more readable and easier to understand
|
|
4
|
+
import winston from "winston";
|
|
5
|
+
import DailyRotateFile from "winston-daily-rotate-file";
|
|
6
|
+
import TransportStream from "winston-transport";
|
|
7
|
+
import {LogLevel, Logger, TimestampFormat} from "./interface.js";
|
|
8
|
+
import {ConsoleDynamicLevel} from "./utils/consoleTransport.js";
|
|
9
|
+
import {WinstonLogger} from "./winston.js";
|
|
10
|
+
|
|
11
|
+
const DATE_PATTERN = "YYYY-MM-DD";
|
|
12
|
+
|
|
13
|
+
export type LoggerNodeOpts = {
|
|
14
|
+
level: LogLevel;
|
|
15
|
+
/**
|
|
16
|
+
* Enable file output transport if set
|
|
17
|
+
*/
|
|
18
|
+
file?: {
|
|
19
|
+
filepath: string;
|
|
20
|
+
/**
|
|
21
|
+
* Log level for file output transport
|
|
22
|
+
*/
|
|
23
|
+
level: LogLevel;
|
|
24
|
+
/**
|
|
25
|
+
* Rotation config for file output transport
|
|
26
|
+
*/
|
|
27
|
+
dailyRotate?: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Module prefix for all logs
|
|
31
|
+
*/
|
|
32
|
+
module?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Rendering format for logs, defaults to "human"
|
|
35
|
+
*/
|
|
36
|
+
format?: "human" | "json";
|
|
37
|
+
/**
|
|
38
|
+
* Set specific log levels by module
|
|
39
|
+
*/
|
|
40
|
+
levelModule?: Record<string, LogLevel>;
|
|
41
|
+
/**
|
|
42
|
+
* Enables relative to genesis timestamp format
|
|
43
|
+
* ```
|
|
44
|
+
* timestampFormat = {
|
|
45
|
+
* format: TimestampFormatCode.EpochSlot,
|
|
46
|
+
* genesisTime: args.logFormatGenesisTime,
|
|
47
|
+
* secondsPerSlot: config.SECONDS_PER_SLOT,
|
|
48
|
+
* slotsPerEpoch: SLOTS_PER_EPOCH,
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
timestampFormat?: TimestampFormat;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type LoggerNodeChildOpts = {
|
|
56
|
+
module?: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type LoggerNode = Logger & {
|
|
60
|
+
toOpts(): LoggerNodeOpts;
|
|
61
|
+
child(opts: LoggerNodeChildOpts): LoggerNode;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Setup a CLI logger, common for beacon, validator and dev commands
|
|
66
|
+
*/
|
|
67
|
+
export function getNodeLogger(opts: LoggerNodeOpts): LoggerNode {
|
|
68
|
+
return WinstonLoggerNode.fromNewTransports(opts);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function getNodeLoggerTransports(opts: LoggerNodeOpts): winston.transport[] {
|
|
72
|
+
const consoleTransport = new ConsoleDynamicLevel({
|
|
73
|
+
// Set defaultLevel, not level for dynamic level setting of ConsoleDynamicLvevel
|
|
74
|
+
defaultLevel: opts.level,
|
|
75
|
+
debugStdout: true,
|
|
76
|
+
handleExceptions: true,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (opts.levelModule) {
|
|
80
|
+
for (const [module, level] of Object.entries(opts.levelModule)) {
|
|
81
|
+
consoleTransport.setModuleLevel(module, level);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const transports: TransportStream[] = [consoleTransport];
|
|
86
|
+
|
|
87
|
+
if (opts.file) {
|
|
88
|
+
const filename = opts.file.filepath;
|
|
89
|
+
|
|
90
|
+
// `lodestar --logFileDailyRotate` -> enable daily rotate with default value
|
|
91
|
+
// `lodestar --logFileDailyRotate 10` -> set daily rotate to custom value 10
|
|
92
|
+
// `lodestar --logFileDailyRotate 0` -> disable daily rotate and accumulate in same file
|
|
93
|
+
const enableDailyRotate = opts.file.dailyRotate != null && opts.file.dailyRotate > 0;
|
|
94
|
+
|
|
95
|
+
transports.push(
|
|
96
|
+
enableDailyRotate
|
|
97
|
+
? new DailyRotateFile({
|
|
98
|
+
level: opts.file.level,
|
|
99
|
+
//insert the date pattern in filename before the file extension.
|
|
100
|
+
filename: filename.replace(/\.(?=[^.]*$)|$/, "-%DATE%$&"),
|
|
101
|
+
datePattern: DATE_PATTERN,
|
|
102
|
+
handleExceptions: true,
|
|
103
|
+
maxFiles: opts.file.dailyRotate,
|
|
104
|
+
auditFile: path.join(path.dirname(filename), ".log_rotate_audit.json"),
|
|
105
|
+
})
|
|
106
|
+
: new winston.transports.File({
|
|
107
|
+
level: opts.file.level,
|
|
108
|
+
filename: filename,
|
|
109
|
+
handleExceptions: true,
|
|
110
|
+
})
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return transports;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface DefaultMeta {
|
|
118
|
+
module: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export class WinstonLoggerNode extends WinstonLogger implements LoggerNode {
|
|
122
|
+
constructor(
|
|
123
|
+
protected readonly winston: Winston,
|
|
124
|
+
private readonly opts: LoggerNodeOpts
|
|
125
|
+
) {
|
|
126
|
+
super(winston);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static fromOpts(opts: LoggerNodeOpts, transports: winston.transport[]): WinstonLoggerNode {
|
|
130
|
+
return new WinstonLoggerNode(WinstonLoggerNode.createWinstonInstance(opts, transports), opts);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static fromNewTransports(opts: LoggerNodeOpts): WinstonLoggerNode {
|
|
134
|
+
return WinstonLoggerNode.fromOpts(opts, getNodeLoggerTransports(opts));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
child(opts: LoggerNodeChildOpts): LoggerNode {
|
|
138
|
+
const parentMeta = this.winston.defaultMeta as DefaultMeta | undefined;
|
|
139
|
+
const childModule = [parentMeta?.module, opts.module].filter(Boolean).join("/");
|
|
140
|
+
const childOpts: LoggerNodeOpts = {...this.opts, module: childModule};
|
|
141
|
+
const defaultMeta: DefaultMeta = {module: childModule};
|
|
142
|
+
|
|
143
|
+
// Same strategy as Winston's source .child.
|
|
144
|
+
// However, their implementation of child is to merge info objects where parent takes precedence, so it's
|
|
145
|
+
// impossible for child to overwrite 'module' field. Instead the winston class is cloned as defaultMeta
|
|
146
|
+
// overwritten completely.
|
|
147
|
+
// https://github.com/winstonjs/winston/blob/3f1dcc13cda384eb30fe3b941764e47a5a5efc26/lib/winston/logger.js#L47
|
|
148
|
+
const childWinston = Object.create(this.winston) as typeof this.winston;
|
|
149
|
+
|
|
150
|
+
childWinston.defaultMeta = defaultMeta;
|
|
151
|
+
|
|
152
|
+
return new WinstonLoggerNode(childWinston, childOpts);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
toOpts(): LoggerNodeOpts {
|
|
156
|
+
return this.opts;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {Logger, transports} from "winston";
|
|
2
|
+
import {LEVEL, LogLevel, WinstonLogInfo} from "../interface.js";
|
|
3
|
+
|
|
4
|
+
export class ConsoleDynamicLevel extends transports.Console {
|
|
5
|
+
private readonly levelByModule = new Map<string, LogLevel>();
|
|
6
|
+
private readonly defaultLevel: LogLevel;
|
|
7
|
+
|
|
8
|
+
// Define property from TransportStream that's not in the types
|
|
9
|
+
private readonly levels!: Record<LogLevel, number>;
|
|
10
|
+
private parent?: Logger;
|
|
11
|
+
|
|
12
|
+
constructor(opts: {defaultLevel: LogLevel} & transports.ConsoleTransportOptions) {
|
|
13
|
+
super(opts);
|
|
14
|
+
|
|
15
|
+
this.defaultLevel = opts.defaultLevel;
|
|
16
|
+
|
|
17
|
+
// Set level and parent to undefined so that underlying transport logs everything
|
|
18
|
+
this.level = undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setModuleLevel(module: string, level: LogLevel): void {
|
|
22
|
+
this.levelByModule.set(module, level);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
deleteModuleLevel(module: string): boolean {
|
|
26
|
+
return this.levelByModule.delete(module);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
_write(info: WinstonLogInfo, enc: BufferEncoding, callback: (error?: Error | null | undefined) => void): void {
|
|
30
|
+
const moduleLevel = this.levelByModule.get(info.module) ?? this.defaultLevel;
|
|
31
|
+
|
|
32
|
+
// Min number is highest prio log level
|
|
33
|
+
// levels = {error: 0, warn: 1, info: 2, ...}
|
|
34
|
+
|
|
35
|
+
if (this.levels[moduleLevel] >= this.levels[info[LEVEL]]) {
|
|
36
|
+
// Set level and parent to undefined so that underlying transport logs everything
|
|
37
|
+
if (this.parent) {
|
|
38
|
+
this.parent = undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
super._write(info, enc, callback);
|
|
42
|
+
} else {
|
|
43
|
+
callback(null);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import winston, {format} from "winston";
|
|
2
|
+
import {LodestarError, isEmptyObject} from "@lodestar/utils";
|
|
3
|
+
import {LoggerOptions, TimestampFormatCode} from "../interface.js";
|
|
4
|
+
import {LogData, logCtxToJson, logCtxToString} from "./json.js";
|
|
5
|
+
import {formatEpochSlotTime} from "./timeFormat.js";
|
|
6
|
+
|
|
7
|
+
type Format = ReturnType<typeof winston.format.combine>;
|
|
8
|
+
|
|
9
|
+
// TODO: Find a more typesafe way of enforce this properties
|
|
10
|
+
type WinstonInfoArg = {
|
|
11
|
+
level: string;
|
|
12
|
+
message: string;
|
|
13
|
+
module?: string;
|
|
14
|
+
namespace?: string;
|
|
15
|
+
timestamp: string;
|
|
16
|
+
context: LogData;
|
|
17
|
+
error: Error;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function getFormat(opts: LoggerOptions): Format {
|
|
21
|
+
switch (opts.format) {
|
|
22
|
+
case "json":
|
|
23
|
+
return jsonLogFormat(opts);
|
|
24
|
+
case "human":
|
|
25
|
+
return humanReadableLogFormat(opts);
|
|
26
|
+
default:
|
|
27
|
+
return humanReadableLogFormat(opts);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function humanReadableLogFormat(opts: LoggerOptions): Format {
|
|
32
|
+
return format.combine(
|
|
33
|
+
...(opts.timestampFormat?.format === TimestampFormatCode.Hidden ? [] : [formatTimestamp(opts)]),
|
|
34
|
+
format.colorize(),
|
|
35
|
+
format.printf(humanReadableTemplateFn)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function formatTimestamp(opts: LoggerOptions): Format {
|
|
40
|
+
const {timestampFormat} = opts;
|
|
41
|
+
|
|
42
|
+
switch (timestampFormat?.format) {
|
|
43
|
+
case TimestampFormatCode.EpochSlot:
|
|
44
|
+
return {
|
|
45
|
+
transform: (info) => {
|
|
46
|
+
info.timestamp = formatEpochSlotTime(timestampFormat);
|
|
47
|
+
return info;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
case TimestampFormatCode.DateRegular:
|
|
52
|
+
return format.timestamp({format: "MMM-DD HH:mm:ss.SSS"});
|
|
53
|
+
default:
|
|
54
|
+
return format.timestamp({format: "MMM-DD HH:mm:ss.SSS"});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function jsonLogFormat(opts: LoggerOptions): Format {
|
|
59
|
+
return format.combine(
|
|
60
|
+
...(opts.timestampFormat?.format === TimestampFormatCode.Hidden ? [] : [format.timestamp()]),
|
|
61
|
+
format((_info) => {
|
|
62
|
+
const info = _info as WinstonInfoArg;
|
|
63
|
+
info.context = logCtxToJson(info.context);
|
|
64
|
+
info.error = logCtxToJson(info.error) as unknown as Error;
|
|
65
|
+
return info;
|
|
66
|
+
})(),
|
|
67
|
+
format.json()
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Winston template function print a human readable string given a log object
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
// biome-ignore lint/suspicious/noExplicitAny: We need to use `any` type here
|
|
76
|
+
function humanReadableTemplateFn(_info: {[key: string]: any; level: string; message: string}): string {
|
|
77
|
+
const info = _info as WinstonInfoArg;
|
|
78
|
+
|
|
79
|
+
const paddingBetweenInfo = 30;
|
|
80
|
+
|
|
81
|
+
const infoString = info.module || info.namespace || "";
|
|
82
|
+
const infoPad = paddingBetweenInfo - infoString.length;
|
|
83
|
+
|
|
84
|
+
let str = "";
|
|
85
|
+
|
|
86
|
+
if (info.timestamp) str += info.timestamp;
|
|
87
|
+
|
|
88
|
+
str += `[${infoString}] ${info.level.padStart(infoPad)}: ${info.message}`;
|
|
89
|
+
|
|
90
|
+
if (info.context !== undefined && !isEmptyObject(info.context)) str += " " + logCtxToString(info.context);
|
|
91
|
+
if (info.error !== undefined) {
|
|
92
|
+
str +=
|
|
93
|
+
// LodestarError is formatted in the same way as context, it is either appended to
|
|
94
|
+
// the log message (" ") or extends existing context properties (", "). For any other
|
|
95
|
+
// error, the message is printed out and clearly separated from the log message (" - ").
|
|
96
|
+
(info.error instanceof LodestarError ? (isEmptyObject(info.context) ? " " : ", ") : " - ") +
|
|
97
|
+
logCtxToString(info.error);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return str;
|
|
101
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {LodestarError, mapValues, toHex} from "@lodestar/utils";
|
|
2
|
+
|
|
3
|
+
const MAX_DEPTH = 0;
|
|
4
|
+
|
|
5
|
+
type LogDataBasic = string | number | bigint | boolean | null | undefined;
|
|
6
|
+
|
|
7
|
+
export type LogData =
|
|
8
|
+
| LogDataBasic
|
|
9
|
+
| LogDataBasic[]
|
|
10
|
+
| Record<string, LogDataBasic>
|
|
11
|
+
| Record<string, LogDataBasic>[]
|
|
12
|
+
| Record<string, LogDataBasic[]>
|
|
13
|
+
| Record<string, LogDataBasic[]>[];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Renders any log Context to JSON up to one level of depth.
|
|
17
|
+
*
|
|
18
|
+
* By limiting recursiveness, it renders limited content while ensuring safer logging.
|
|
19
|
+
* Consumers of the logger should ensure to send pre-formated data if they require nesting.
|
|
20
|
+
*/
|
|
21
|
+
export function logCtxToJson(arg: unknown, depth = 0, fromError = false): LogData {
|
|
22
|
+
switch (typeof arg) {
|
|
23
|
+
case "bigint":
|
|
24
|
+
case "symbol":
|
|
25
|
+
case "function":
|
|
26
|
+
return arg.toString();
|
|
27
|
+
|
|
28
|
+
case "object":
|
|
29
|
+
if (arg === null) return "null";
|
|
30
|
+
|
|
31
|
+
if (arg instanceof Uint8Array) {
|
|
32
|
+
return toHex(arg);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// For any type that may include recursiveness break early at the first level
|
|
36
|
+
// - Prevent recursive loops
|
|
37
|
+
// - Ensures Error with deep complex metadata won't leak into the logs and cause bugs
|
|
38
|
+
if (depth > MAX_DEPTH) {
|
|
39
|
+
return "[object]";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (arg instanceof Error) {
|
|
43
|
+
let metadata: Record<string, unknown>;
|
|
44
|
+
if (arg instanceof LodestarError) {
|
|
45
|
+
if (fromError) {
|
|
46
|
+
return "[LodestarErrorCircular]";
|
|
47
|
+
}
|
|
48
|
+
// Allow one extra depth level for LodestarError
|
|
49
|
+
metadata = logCtxToJson(arg.getMetadata(), depth - 1, true) as Record<string, unknown>;
|
|
50
|
+
} else {
|
|
51
|
+
metadata = {message: arg.message};
|
|
52
|
+
}
|
|
53
|
+
if (arg.stack) metadata.stack = arg.stack;
|
|
54
|
+
return metadata as LogData;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (Array.isArray(arg)) {
|
|
58
|
+
return arg.map((item) => logCtxToJson(item, depth + 1)) as LogData;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return mapValues(arg as Record<string, unknown>, (item) => logCtxToJson(item, depth + 1)) as LogData;
|
|
62
|
+
|
|
63
|
+
// Already valid JSON
|
|
64
|
+
case "number":
|
|
65
|
+
case "string":
|
|
66
|
+
case "undefined":
|
|
67
|
+
case "boolean":
|
|
68
|
+
return arg;
|
|
69
|
+
|
|
70
|
+
default:
|
|
71
|
+
return String(arg);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Renders any log Context to a string up to one level of depth.
|
|
77
|
+
*
|
|
78
|
+
* By limiting recursiveness, it renders limited content while ensuring safer logging.
|
|
79
|
+
* Consumers of the logger should ensure to send pre-formated data if they require nesting.
|
|
80
|
+
*/
|
|
81
|
+
export function logCtxToString(arg: unknown, depth = 0, fromError = false): string {
|
|
82
|
+
switch (typeof arg) {
|
|
83
|
+
case "bigint":
|
|
84
|
+
case "symbol":
|
|
85
|
+
case "function":
|
|
86
|
+
return arg.toString();
|
|
87
|
+
|
|
88
|
+
case "object":
|
|
89
|
+
if (arg === null) return "null";
|
|
90
|
+
|
|
91
|
+
if (arg instanceof Uint8Array) {
|
|
92
|
+
return toHex(arg);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// For any type that may include recursiveness break early at the first level
|
|
96
|
+
// - Prevent recursive loops
|
|
97
|
+
// - Ensures Error with deep complex metadata won't leak into the logs and cause bugs
|
|
98
|
+
if (depth > MAX_DEPTH) {
|
|
99
|
+
return "[object]";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (arg instanceof Error) {
|
|
103
|
+
let metadata: string;
|
|
104
|
+
if (arg instanceof LodestarError) {
|
|
105
|
+
if (fromError) {
|
|
106
|
+
return "[LodestarErrorCircular]";
|
|
107
|
+
}
|
|
108
|
+
// Allow one extra depth level for LodestarError
|
|
109
|
+
metadata = logCtxToString(arg.getMetadata(), depth - 1, true);
|
|
110
|
+
} else {
|
|
111
|
+
metadata = arg.message;
|
|
112
|
+
}
|
|
113
|
+
return `${metadata}\n${arg.stack || ""}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (Array.isArray(arg)) {
|
|
117
|
+
return arg.map((item) => logCtxToString(item, depth + 1)).join(", ");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return Object.entries(arg)
|
|
121
|
+
.map(([key, value]) => `${key}=${logCtxToString(value, depth + 1)}`)
|
|
122
|
+
.join(", ");
|
|
123
|
+
|
|
124
|
+
case "number":
|
|
125
|
+
case "string":
|
|
126
|
+
case "undefined":
|
|
127
|
+
case "boolean":
|
|
128
|
+
return String(arg);
|
|
129
|
+
default:
|
|
130
|
+
return String(arg);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {EpochSlotOpts} from "../interface.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Formats time as: `EPOCH/SLOT_INDEX SECONDS.MILLISECONDS
|
|
5
|
+
*/
|
|
6
|
+
export function formatEpochSlotTime(opts: EpochSlotOpts, now = Date.now()): string {
|
|
7
|
+
const nowSec = now / 1000;
|
|
8
|
+
const secSinceGenesis = nowSec - opts.genesisTime;
|
|
9
|
+
const epoch = Math.floor(secSinceGenesis / (opts.slotsPerEpoch * opts.secondsPerSlot));
|
|
10
|
+
const epochStartSec = opts.genesisTime + epoch * opts.slotsPerEpoch * opts.secondsPerSlot;
|
|
11
|
+
const secSinceStartEpoch = nowSec - epochStartSec;
|
|
12
|
+
const slotIndex = Math.floor(secSinceStartEpoch / opts.secondsPerSlot);
|
|
13
|
+
const slotSec = secSinceStartEpoch % opts.secondsPerSlot;
|
|
14
|
+
return `Eph ${epoch}/${slotIndex} ${slotSec.toFixed(3)}`;
|
|
15
|
+
}
|
package/src/winston.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// We want to keep `winston` export as it's more readable and easier to understand
|
|
2
|
+
|
|
3
|
+
import type {Logger as Winston} from "winston";
|
|
4
|
+
import winston from "winston";
|
|
5
|
+
import {LogLevel, Logger, LoggerOptions, logLevelNum} from "./interface.js";
|
|
6
|
+
import {getFormat} from "./utils/format.js";
|
|
7
|
+
import {LogData} from "./utils/json.js";
|
|
8
|
+
|
|
9
|
+
// # How to configure Winston log level?
|
|
10
|
+
//
|
|
11
|
+
// - Log level is meant to be configured BY TRANSPORT only
|
|
12
|
+
// - There's no native logic that allows different logLevels by metadata.module
|
|
13
|
+
// - Transports are shared between child loggers, so a custom transport is required
|
|
14
|
+
//
|
|
15
|
+
// This is the logic that controls if log or not based on each log message level.
|
|
16
|
+
// Winston transport base class TransportStream check its own transport level to decide to format then log
|
|
17
|
+
//
|
|
18
|
+
// ```ts
|
|
19
|
+
// TransportStream.prototype._write = function _write(info, enc, callback) {
|
|
20
|
+
// const level = this.level || (this.parent && this.parent.level);
|
|
21
|
+
// if (!level || this.levels[level] >= this.levels[info[LEVEL]]) {
|
|
22
|
+
// transformed = this.format.transform(Object.assign({}, info), this.format.options);
|
|
23
|
+
// return this.log(transformed, callback);
|
|
24
|
+
// }
|
|
25
|
+
// };
|
|
26
|
+
// ```
|
|
27
|
+
// https://github.com/winstonjs/winston-transport/blob/51baf6138753f0766181355fb50b1b0334344c56/index.js#L80
|
|
28
|
+
//
|
|
29
|
+
// To configure different logLevel per metadata.module the simplest solution is to have a custom Transport
|
|
30
|
+
// that overrides the `transport._write` with a lookup on a Map of module -> log level. This is done in
|
|
31
|
+
// the CLI package on a special ConsoleTransport that could be set dynamically.
|
|
32
|
+
|
|
33
|
+
interface DefaultMeta {
|
|
34
|
+
module: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createWinstonLogger(options: Partial<LoggerOptions> = {}, transports?: winston.transport[]): Logger {
|
|
38
|
+
return WinstonLogger.fromOpts(options, transports);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class WinstonLogger implements Logger {
|
|
42
|
+
constructor(protected readonly winston: Winston) {}
|
|
43
|
+
|
|
44
|
+
static fromOpts(options: Partial<LoggerOptions> = {}, transports?: winston.transport[]): WinstonLogger {
|
|
45
|
+
return new WinstonLogger(WinstonLogger.createWinstonInstance(options, transports));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static createWinstonInstance(options: Partial<LoggerOptions> = {}, transports?: winston.transport[]): Winston {
|
|
49
|
+
const defaultMeta: DefaultMeta = {module: options?.module || ""};
|
|
50
|
+
|
|
51
|
+
return winston.createLogger({
|
|
52
|
+
// Do not set level at the logger level. Always control by Transport, unless for testLogger
|
|
53
|
+
level: options.level,
|
|
54
|
+
defaultMeta,
|
|
55
|
+
format: getFormat(options),
|
|
56
|
+
transports,
|
|
57
|
+
exitOnError: false,
|
|
58
|
+
levels: logLevelNum,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
error(message: string, context?: LogData, error?: Error): void {
|
|
63
|
+
this.createLogEntry(LogLevel.error, message, context, error);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
warn(message: string, context?: LogData, error?: Error): void {
|
|
67
|
+
this.createLogEntry(LogLevel.warn, message, context, error);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
info(message: string, context?: LogData, error?: Error): void {
|
|
71
|
+
this.createLogEntry(LogLevel.info, message, context, error);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
verbose(message: string, context?: LogData, error?: Error): void {
|
|
75
|
+
this.createLogEntry(LogLevel.verbose, message, context, error);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
debug(message: string, context?: LogData, error?: Error): void {
|
|
79
|
+
this.createLogEntry(LogLevel.debug, message, context, error);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private createLogEntry(level: LogLevel, message: string, context?: LogData, error?: Error): void {
|
|
83
|
+
// Note: logger does not run format.transform function unless it will actually write the log to the transport
|
|
84
|
+
|
|
85
|
+
// If winston logger is called with `winston.info(message, context, error)` it triggers the "splat" path
|
|
86
|
+
// while we just need winston to forward an object to the custom formatter. So we call the fn signature below
|
|
87
|
+
// https://github.com/winstonjs/winston/blob/3f1dcc13cda384eb30fe3b941764e47a5a5efc26/lib/winston/logger.js#L221
|
|
88
|
+
this.winston.log(level, {message, context, error});
|
|
89
|
+
}
|
|
90
|
+
}
|