@lodestar/utils 1.8.0 → 1.9.0-dev.1602f67e3b

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/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export * from "./logger/index.js";
2
1
  export * from "./yaml/index.js";
3
2
  export * from "./assert.js";
4
3
  export * from "./bytes.js";
5
4
  export * from "./err.js";
6
5
  export * from "./errors.js";
7
6
  export * from "./format.js";
7
+ export * from "./logger.js";
8
8
  export * from "./map.js";
9
9
  export * from "./math.js";
10
10
  export * from "./objects.js";
package/lib/index.js CHANGED
@@ -1,10 +1,10 @@
1
- export * from "./logger/index.js";
2
1
  export * from "./yaml/index.js";
3
2
  export * from "./assert.js";
4
3
  export * from "./bytes.js";
5
4
  export * from "./err.js";
6
5
  export * from "./errors.js";
7
6
  export * from "./format.js";
7
+ export * from "./logger.js";
8
8
  export * from "./map.js";
9
9
  export * from "./math.js";
10
10
  export * from "./objects.js";
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAC,KAAK,EAAe,MAAM,YAAY,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAmB,OAAO,EAAC,MAAM,YAAY,CAAC;AACrD,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAC,KAAK,EAAe,MAAM,YAAY,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAmB,OAAO,EAAC,MAAM,YAAY,CAAC;AACrD,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Interface of a generic Lodestar logger. For implementations, see `@lodestar/logger`
3
+ */
4
+ export type Logger = Record<LogLevel, LogHandler>;
5
+ export declare enum LogLevel {
6
+ error = "error",
7
+ warn = "warn",
8
+ info = "info",
9
+ verbose = "verbose",
10
+ debug = "debug",
11
+ trace = "trace"
12
+ }
13
+ export declare const LogLevels: LogLevel[];
14
+ export type LogHandler = (message: string, context?: LogData, error?: Error) => void;
15
+ type LogDataBasic = string | number | bigint | boolean | null | undefined;
16
+ export type LogData = LogDataBasic | Record<string, LogDataBasic> | LogDataBasic[] | Record<string, LogDataBasic>[];
17
+ export {};
18
+ //# sourceMappingURL=logger.d.ts.map
package/lib/logger.js ADDED
@@ -0,0 +1,12 @@
1
+ export var LogLevel;
2
+ (function (LogLevel) {
3
+ LogLevel["error"] = "error";
4
+ LogLevel["warn"] = "warn";
5
+ LogLevel["info"] = "info";
6
+ LogLevel["verbose"] = "verbose";
7
+ LogLevel["debug"] = "debug";
8
+ LogLevel["trace"] = "trace";
9
+ })(LogLevel || (LogLevel = {}));
10
+ // eslint-disable-next-line @typescript-eslint/naming-convention
11
+ export const LogLevels = Object.values(LogLevel);
12
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAKA,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,+BAAmB,CAAA;IACnB,2BAAe,CAAA;IACf,2BAAe,CAAA;AACjB,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAED,gEAAgE;AAChE,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC"}
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.8.0",
14
+ "version": "1.9.0-dev.1602f67e3b",
15
15
  "type": "module",
16
16
  "exports": "./lib/index.js",
17
17
  "files": [
@@ -57,5 +57,5 @@
57
57
  "beacon",
58
58
  "blockchain"
59
59
  ],
60
- "gitHead": "a4b29cfe38de109c44992977074869a8c01cfc83"
60
+ "gitHead": "c388781e99a28446b709e33f8ba2bfe0eb2e24d5"
61
61
  }
@@ -1,6 +0,0 @@
1
- import winston from "winston";
2
- import { LoggerOptions } from "./interface.js";
3
- type Format = ReturnType<typeof winston.format.combine>;
4
- export declare function getFormat(opts: LoggerOptions): Format;
5
- export {};
6
- //# sourceMappingURL=format.d.ts.map
@@ -1,60 +0,0 @@
1
- import winston from "winston";
2
- import { logCtxToJson, logCtxToString } from "./json.js";
3
- import { TimestampFormatCode } from "./interface.js";
4
- import { formatEpochSlotTime } from "./util.js";
5
- const { format } = winston;
6
- export function getFormat(opts) {
7
- switch (opts.format) {
8
- case "json":
9
- return jsonLogFormat(opts);
10
- case "human":
11
- default:
12
- return humanReadableLogFormat(opts);
13
- }
14
- }
15
- function humanReadableLogFormat(opts) {
16
- return format.combine(...(opts.hideTimestamp ? [] : [formatTimestamp(opts)]), format.colorize(), format.printf(humanReadableTemplateFn));
17
- }
18
- function formatTimestamp(opts) {
19
- const { timestampFormat } = opts;
20
- switch (timestampFormat === null || timestampFormat === void 0 ? void 0 : timestampFormat.format) {
21
- case TimestampFormatCode.EpochSlot:
22
- return {
23
- transform: (info) => {
24
- info.timestamp = formatEpochSlotTime(timestampFormat);
25
- return info;
26
- },
27
- };
28
- case TimestampFormatCode.DateRegular:
29
- default:
30
- return format.timestamp({ format: "MMM-DD HH:mm:ss.SSS" });
31
- }
32
- }
33
- function jsonLogFormat(opts) {
34
- return format.combine(...(opts.hideTimestamp ? [] : [format.timestamp()]), format((_info) => {
35
- const info = _info;
36
- info.context = logCtxToJson(info.context);
37
- info.error = logCtxToJson(info.error);
38
- return info;
39
- })(), format.json());
40
- }
41
- /**
42
- * Winston template function print a human readable string given a log object
43
- */
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
- function humanReadableTemplateFn(_info) {
46
- const info = _info;
47
- const paddingBetweenInfo = 30;
48
- const infoString = info.module || info.namespace || "";
49
- const infoPad = paddingBetweenInfo - infoString.length;
50
- let str = "";
51
- if (info.timestamp)
52
- str += info.timestamp;
53
- str += `[${infoString}] ${info.level.padStart(infoPad)}: ${info.message}`;
54
- if (info.context !== undefined)
55
- str += " " + logCtxToString(info.context);
56
- if (info.error !== undefined)
57
- str += " " + logCtxToString(info.error);
58
- return str;
59
- }
60
- //# sourceMappingURL=format.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/logger/format.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,YAAY,EAAE,cAAc,EAAU,MAAM,WAAW,CAAC;AAChE,OAAO,EAAgB,mBAAmB,EAAC,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAC,mBAAmB,EAAC,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AC,CAAC,EACnD,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,IAAI,GAAG,KAAuB,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,KAAK,CAAqB,CAAC;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,EAAE,EACJ,MAAM,CAAC,IAAI,EAAE,CACd,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,8DAA8D;AAC9D,SAAS,uBAAuB,CAAC,KAA2D;IAC1F,MAAM,IAAI,GAAG,KAAuB,CAAC;IAErC,MAAM,kBAAkB,GAAG,EAAE,CAAC;IAE9B,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC;IACvD,MAAM,OAAO,GAAG,kBAAkB,GAAG,UAAU,CAAC,MAAM,CAAC;IAEvD,IAAI,GAAG,GAAG,EAAE,CAAC;IAEb,IAAI,IAAI,CAAC,SAAS;QAAE,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC;IAE1C,GAAG,IAAI,IAAI,UAAU,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;IAE1E,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;QAAE,GAAG,IAAI,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1E,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;QAAE,GAAG,IAAI,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEtE,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,5 +0,0 @@
1
- export * from "./interface.js";
2
- export * from "./format.js";
3
- export * from "./winston.js";
4
- export { LogData } from "./json.js";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1,4 +0,0 @@
1
- export * from "./interface.js";
2
- export * from "./format.js";
3
- export * from "./winston.js";
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -1,50 +0,0 @@
1
- import { LogData } from "./json.js";
2
- export declare enum LogLevel {
3
- error = "error",
4
- warn = "warn",
5
- info = "info",
6
- verbose = "verbose",
7
- debug = "debug",
8
- trace = "trace"
9
- }
10
- export declare const logLevelNum: {
11
- [K in LogLevel]: number;
12
- };
13
- export declare const LogLevels: LogLevel[];
14
- export declare const defaultLogLevel = LogLevel.info;
15
- export type LogFormat = "human" | "json";
16
- export declare const logFormats: LogFormat[];
17
- export type EpochSlotOpts = {
18
- genesisTime: number;
19
- secondsPerSlot: number;
20
- slotsPerEpoch: number;
21
- };
22
- export declare enum TimestampFormatCode {
23
- DateRegular = 0,
24
- EpochSlot = 1
25
- }
26
- export type TimestampFormat = {
27
- format: TimestampFormatCode.DateRegular;
28
- } | ({
29
- format: TimestampFormatCode.EpochSlot;
30
- } & EpochSlotOpts);
31
- export interface LoggerOptions {
32
- level?: LogLevel;
33
- module?: string;
34
- format?: LogFormat;
35
- hideTimestamp?: boolean;
36
- timestampFormat?: TimestampFormat;
37
- }
38
- export type LoggerChildOpts = {
39
- module: string;
40
- };
41
- export type LogHandler = (message: string, context?: LogData, error?: Error) => void;
42
- export type Logger = {
43
- error: LogHandler;
44
- warn: LogHandler;
45
- info: LogHandler;
46
- verbose: LogHandler;
47
- debug: LogHandler;
48
- child(options: LoggerChildOpts): Logger;
49
- };
50
- //# sourceMappingURL=interface.d.ts.map
@@ -1,28 +0,0 @@
1
- export var LogLevel;
2
- (function (LogLevel) {
3
- LogLevel["error"] = "error";
4
- LogLevel["warn"] = "warn";
5
- LogLevel["info"] = "info";
6
- LogLevel["verbose"] = "verbose";
7
- LogLevel["debug"] = "debug";
8
- LogLevel["trace"] = "trace";
9
- })(LogLevel || (LogLevel = {}));
10
- export const logLevelNum = {
11
- [LogLevel.error]: 0,
12
- [LogLevel.warn]: 1,
13
- [LogLevel.info]: 2,
14
- [LogLevel.verbose]: 3,
15
- [LogLevel.debug]: 4,
16
- /** Request in https://github.com/ChainSafe/lodestar/issues/4536 by eth-docker */
17
- [LogLevel.trace]: 5,
18
- };
19
- // eslint-disable-next-line @typescript-eslint/naming-convention
20
- export const LogLevels = Object.values(LogLevel);
21
- export const defaultLogLevel = LogLevel.info;
22
- export const logFormats = ["human", "json"];
23
- export var TimestampFormatCode;
24
- (function (TimestampFormatCode) {
25
- TimestampFormatCode[TimestampFormatCode["DateRegular"] = 0] = "DateRegular";
26
- TimestampFormatCode[TimestampFormatCode["EpochSlot"] = 1] = "EpochSlot";
27
- })(TimestampFormatCode || (TimestampFormatCode = {}));
28
- //# sourceMappingURL=interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/logger/interface.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,+BAAmB,CAAA;IACnB,2BAAe,CAAA;IACf,2BAAe,CAAA;AACjB,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAED,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,gEAAgE;AAChE,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAEjD,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC;AAG7C,MAAM,CAAC,MAAM,UAAU,GAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAOzD,MAAM,CAAN,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,2EAAW,CAAA;IACX,uEAAS,CAAA;AACX,CAAC,EAHW,mBAAmB,KAAnB,mBAAmB,QAG9B"}
@@ -1,18 +0,0 @@
1
- type LogDataBasic = string | number | bigint | boolean | null | undefined;
2
- export type LogData = LogDataBasic | Record<string, LogDataBasic> | LogDataBasic[] | Record<string, LogDataBasic>[];
3
- /**
4
- * Renders any log Context to JSON up to one level of depth.
5
- *
6
- * By limiting recursiveness, it renders limited content while ensuring safer logging.
7
- * Consumers of the logger should ensure to send pre-formated data if they require nesting.
8
- */
9
- export declare function logCtxToJson(arg: unknown, depth?: number, fromError?: boolean): LogData;
10
- /**
11
- * Renders any log Context to a string up to one level of depth.
12
- *
13
- * By limiting recursiveness, it renders limited content while ensuring safer logging.
14
- * Consumers of the logger should ensure to send pre-formated data if they require nesting.
15
- */
16
- export declare function logCtxToString(arg: unknown, depth?: number, fromError?: boolean): string;
17
- export {};
18
- //# sourceMappingURL=json.d.ts.map
@@ -1,115 +0,0 @@
1
- import { toHexString } from "../bytes.js";
2
- import { LodestarError } from "../errors.js";
3
- import { mapValues } from "../objects.js";
4
- const MAX_DEPTH = 0;
5
- /**
6
- * Renders any log Context to JSON up to one level of depth.
7
- *
8
- * By limiting recursiveness, it renders limited content while ensuring safer logging.
9
- * Consumers of the logger should ensure to send pre-formated data if they require nesting.
10
- */
11
- export function logCtxToJson(arg, depth = 0, fromError = false) {
12
- switch (typeof arg) {
13
- case "bigint":
14
- case "symbol":
15
- case "function":
16
- return arg.toString();
17
- case "object":
18
- if (arg === null)
19
- return "null";
20
- if (arg instanceof Uint8Array) {
21
- return toHexString(arg);
22
- }
23
- // For any type that may include recursiveness break early at the first level
24
- // - Prevent recursive loops
25
- // - Ensures Error with deep complex metadata won't leak into the logs and cause bugs
26
- if (depth > MAX_DEPTH) {
27
- return "[object]";
28
- }
29
- if (arg instanceof Error) {
30
- let metadata;
31
- if (arg instanceof LodestarError) {
32
- if (fromError) {
33
- return "[LodestarErrorCircular]";
34
- }
35
- else {
36
- // Allow one extra depth level for LodestarError
37
- metadata = logCtxToJson(arg.getMetadata(), depth - 1, true);
38
- }
39
- }
40
- else {
41
- metadata = { message: arg.message };
42
- }
43
- if (arg.stack)
44
- metadata.stack = arg.stack;
45
- return metadata;
46
- }
47
- if (Array.isArray(arg)) {
48
- return arg.map((item) => logCtxToJson(item, depth + 1));
49
- }
50
- return mapValues(arg, (item) => logCtxToJson(item, depth + 1));
51
- // Already valid JSON
52
- case "number":
53
- case "string":
54
- case "undefined":
55
- case "boolean":
56
- return arg;
57
- default:
58
- return String(arg);
59
- }
60
- }
61
- /**
62
- * Renders any log Context to a string up to one level of depth.
63
- *
64
- * By limiting recursiveness, it renders limited content while ensuring safer logging.
65
- * Consumers of the logger should ensure to send pre-formated data if they require nesting.
66
- */
67
- export function logCtxToString(arg, depth = 0, fromError = false) {
68
- switch (typeof arg) {
69
- case "bigint":
70
- case "symbol":
71
- case "function":
72
- return arg.toString();
73
- case "object":
74
- if (arg === null)
75
- return "null";
76
- if (arg instanceof Uint8Array) {
77
- return toHexString(arg);
78
- }
79
- // For any type that may include recursiveness break early at the first level
80
- // - Prevent recursive loops
81
- // - Ensures Error with deep complex metadata won't leak into the logs and cause bugs
82
- if (depth > MAX_DEPTH) {
83
- return "[object]";
84
- }
85
- if (arg instanceof Error) {
86
- let metadata;
87
- if (arg instanceof LodestarError) {
88
- if (fromError) {
89
- return "[LodestarErrorCircular]";
90
- }
91
- else {
92
- // Allow one extra depth level for LodestarError
93
- metadata = logCtxToString(arg.getMetadata(), depth - 1, true);
94
- }
95
- }
96
- else {
97
- metadata = arg.message;
98
- }
99
- return `${metadata}\n${arg.stack || ""}`;
100
- }
101
- if (Array.isArray(arg)) {
102
- return arg.map((item) => logCtxToString(item, depth + 1)).join(", ");
103
- }
104
- return Object.entries(arg)
105
- .map(([key, value]) => `${key}=${logCtxToString(value, depth + 1)}`)
106
- .join(", ");
107
- case "number":
108
- case "string":
109
- case "undefined":
110
- case "boolean":
111
- default:
112
- return String(arg);
113
- }
114
- }
115
- //# sourceMappingURL=json.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/logger/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AAExC,MAAM,SAAS,GAAG,CAAC,CAAC;AAMpB;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAAY,EAAE,KAAK,GAAG,CAAC,EAAE,SAAS,GAAG,KAAK;IACrE,QAAQ,OAAO,GAAG,EAAE;QAClB,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,UAAU;YACb,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;QAExB,KAAK,QAAQ;YACX,IAAI,GAAG,KAAK,IAAI;gBAAE,OAAO,MAAM,CAAC;YAEhC,IAAI,GAAG,YAAY,UAAU,EAAE;gBAC7B,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;aACzB;YAED,6EAA6E;YAC7E,4BAA4B;YAC5B,qFAAqF;YACrF,IAAI,KAAK,GAAG,SAAS,EAAE;gBACrB,OAAO,UAAU,CAAC;aACnB;YAED,IAAI,GAAG,YAAY,KAAK,EAAE;gBACxB,IAAI,QAAiC,CAAC;gBACtC,IAAI,GAA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AC,CAAC;KACtB;AACH,CAAC"}
@@ -1,6 +0,0 @@
1
- import { EpochSlotOpts } from "./interface.js";
2
- /**
3
- * Formats time as: `EPOCH/SLOT_INDEX SECONDS.MILLISECONDS
4
- */
5
- export declare function formatEpochSlotTime(opts: EpochSlotOpts, now?: number): string;
6
- //# sourceMappingURL=util.d.ts.map
@@ -1,14 +0,0 @@
1
- /**
2
- * Formats time as: `EPOCH/SLOT_INDEX SECONDS.MILLISECONDS
3
- */
4
- export function formatEpochSlotTime(opts, now = Date.now()) {
5
- const nowSec = now / 1000;
6
- const secSinceGenesis = nowSec - opts.genesisTime;
7
- const epoch = Math.floor(secSinceGenesis / (opts.slotsPerEpoch * opts.secondsPerSlot));
8
- const epochStartSec = opts.genesisTime + epoch * opts.slotsPerEpoch * opts.secondsPerSlot;
9
- const secSinceStartEpoch = nowSec - epochStartSec;
10
- const slotIndex = Math.floor(secSinceStartEpoch / opts.secondsPerSlot);
11
- const slotSec = secSinceStartEpoch % opts.secondsPerSlot;
12
- return `Eph ${epoch}/${slotIndex} ${slotSec.toFixed(3)}`;
13
- }
14
- //# sourceMappingURL=util.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/logger/util.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAmB,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IACvE,MAAM,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC;IAC1B,MAAM,eAAe,GAAG,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC;IAClD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;IACvF,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,GAAG,KAAK,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC;IAC1F,MAAM,kBAAkB,GAAG,MAAM,GAAG,aAAa,CAAC;IAClD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;IACvE,MAAM,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAAC,cAAc,CAAC;IACzD,OAAO,OAAO,KAAK,IAAI,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3D,CAAC"}
@@ -1,19 +0,0 @@
1
- import winston from "winston";
2
- import type { Logger as Winston } from "winston";
3
- import { Logger, LoggerOptions, LoggerChildOpts } from "./interface.js";
4
- import { LogData } from "./json.js";
5
- export declare function createWinstonLogger(options?: Partial<LoggerOptions>, transports?: winston.transport[]): Logger;
6
- export declare class WinstonLogger implements Logger {
7
- private readonly winston;
8
- constructor(winston: Winston);
9
- static fromOpts(options?: Partial<LoggerOptions>, transports?: winston.transport[]): WinstonLogger;
10
- error(message: string, context?: LogData, error?: Error): void;
11
- warn(message: string, context?: LogData, error?: Error): void;
12
- info(message: string, context?: LogData, error?: Error): void;
13
- verbose(message: string, context?: LogData, error?: Error): void;
14
- debug(message: string, context?: LogData, error?: Error): void;
15
- trace(message: string, context?: LogData, error?: Error): void;
16
- child(options: LoggerChildOpts): WinstonLogger;
17
- private createLogEntry;
18
- }
19
- //# sourceMappingURL=winston.d.ts.map
@@ -1,62 +0,0 @@
1
- import winston from "winston";
2
- import { LogLevel, logLevelNum } from "./interface.js";
3
- import { getFormat } from "./format.js";
4
- export function createWinstonLogger(options = {}, transports) {
5
- return WinstonLogger.fromOpts(options, transports);
6
- }
7
- export class WinstonLogger {
8
- constructor(winston) {
9
- this.winston = winston;
10
- }
11
- static fromOpts(options = {}, transports) {
12
- const defaultMeta = { module: (options === null || options === void 0 ? void 0 : options.module) || "" };
13
- return new WinstonLogger(winston.createLogger({
14
- // Do not set level at the logger level. Always control by Transport, unless for testLogger
15
- level: options.level,
16
- defaultMeta,
17
- format: getFormat(options),
18
- transports,
19
- exitOnError: false,
20
- levels: logLevelNum,
21
- }));
22
- }
23
- error(message, context, error) {
24
- this.createLogEntry(LogLevel.error, message, context, error);
25
- }
26
- warn(message, context, error) {
27
- this.createLogEntry(LogLevel.warn, message, context, error);
28
- }
29
- info(message, context, error) {
30
- this.createLogEntry(LogLevel.info, message, context, error);
31
- }
32
- verbose(message, context, error) {
33
- this.createLogEntry(LogLevel.verbose, message, context, error);
34
- }
35
- debug(message, context, error) {
36
- this.createLogEntry(LogLevel.debug, message, context, error);
37
- }
38
- trace(message, context, error) {
39
- this.createLogEntry(LogLevel.trace, message, context, error);
40
- }
41
- child(options) {
42
- const parentMeta = this.winston.defaultMeta;
43
- const childModule = [parentMeta === null || parentMeta === void 0 ? void 0 : parentMeta.module, options.module].filter(Boolean).join("/");
44
- const defaultMeta = { module: childModule };
45
- // Same strategy as Winston's source .child.
46
- // However, their implementation of child is to merge info objects where parent takes precedence, so it's
47
- // impossible for child to overwrite 'module' field. Instead the winston class is cloned as defaultMeta
48
- // overwritten completely.
49
- // https://github.com/winstonjs/winston/blob/3f1dcc13cda384eb30fe3b941764e47a5a5efc26/lib/winston/logger.js#L47
50
- const childWinston = Object.create(this.winston);
51
- childWinston.defaultMeta = defaultMeta;
52
- return new WinstonLogger(childWinston);
53
- }
54
- createLogEntry(level, message, context, error) {
55
- // Note: logger does not run format.transform function unless it will actually write the log to the transport
56
- // If winston logger is called with `winston.info(message, context, error)` it triggers the "splat" path
57
- // while we just need winston to forward an object to the custom formatter. So we call the fn signature below
58
- // https://github.com/winstonjs/winston/blob/3f1dcc13cda384eb30fe3b941764e47a5a5efc26/lib/winston/logger.js#L221
59
- this.winston.log(level, { message, context, error });
60
- }
61
- }
62
- //# sourceMappingURL=winston.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"winston.js","sourceRoot":"","sources":["../../src/logger/winston.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OA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