@xylabs/logger 3.0.9 → 3.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/IdLogger.d.cts +6 -6
- package/dist/browser/IdLogger.d.cts.map +1 -1
- package/dist/browser/IdLogger.d.mts +6 -6
- package/dist/browser/IdLogger.d.mts.map +1 -1
- package/dist/browser/IdLogger.d.ts +6 -6
- package/dist/browser/IdLogger.d.ts.map +1 -1
- package/dist/browser/Logger.d.cts +1 -2
- package/dist/browser/Logger.d.cts.map +1 -1
- package/dist/browser/Logger.d.mts +1 -2
- package/dist/browser/Logger.d.mts.map +1 -1
- package/dist/browser/Logger.d.ts +1 -2
- package/dist/browser/Logger.d.ts.map +1 -1
- package/dist/browser/getFunctionName.d.cts +2 -0
- package/dist/browser/getFunctionName.d.cts.map +1 -0
- package/dist/browser/getFunctionName.d.mts +2 -0
- package/dist/browser/getFunctionName.d.mts.map +1 -0
- package/dist/browser/getFunctionName.d.ts +2 -0
- package/dist/browser/getFunctionName.d.ts.map +1 -0
- package/dist/browser/index.cjs +44 -42
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +1 -0
- package/dist/browser/index.d.cts.map +1 -1
- package/dist/browser/index.d.mts +1 -0
- package/dist/browser/index.d.mts.map +1 -1
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +44 -42
- package/dist/browser/index.js.map +1 -1
- package/dist/node/IdLogger.d.cts +6 -6
- package/dist/node/IdLogger.d.cts.map +1 -1
- package/dist/node/IdLogger.d.mts +6 -6
- package/dist/node/IdLogger.d.mts.map +1 -1
- package/dist/node/IdLogger.d.ts +6 -6
- package/dist/node/IdLogger.d.ts.map +1 -1
- package/dist/node/Logger.d.cts +1 -2
- package/dist/node/Logger.d.cts.map +1 -1
- package/dist/node/Logger.d.mts +1 -2
- package/dist/node/Logger.d.mts.map +1 -1
- package/dist/node/Logger.d.ts +1 -2
- package/dist/node/Logger.d.ts.map +1 -1
- package/dist/node/getFunctionName.d.cts +2 -0
- package/dist/node/getFunctionName.d.cts.map +1 -0
- package/dist/node/getFunctionName.d.mts +2 -0
- package/dist/node/getFunctionName.d.mts.map +1 -0
- package/dist/node/getFunctionName.d.ts +2 -0
- package/dist/node/getFunctionName.d.ts.map +1 -0
- package/dist/node/index.cjs +45 -42
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +1 -0
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.mts +1 -0
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +45 -42
- package/dist/node/index.js.map +1 -1
- package/package.json +2 -2
- package/src/IdLogger.ts +14 -17
- package/src/Logger.ts +1 -24
- package/src/getFunctionName.ts +23 -0
- package/src/index.ts +1 -0
|
@@ -4,11 +4,11 @@ export declare class IdLogger implements Logger {
|
|
|
4
4
|
private _logger;
|
|
5
5
|
constructor(logger: Logger, id?: () => string);
|
|
6
6
|
set id(id: string);
|
|
7
|
-
debug(
|
|
8
|
-
error(
|
|
9
|
-
info(
|
|
10
|
-
log(
|
|
11
|
-
warn(
|
|
12
|
-
private
|
|
7
|
+
debug(...data: unknown[]): void;
|
|
8
|
+
error(...data: unknown[]): void;
|
|
9
|
+
info(...data: unknown[]): void;
|
|
10
|
+
log(...data: unknown[]): void;
|
|
11
|
+
warn(...data: unknown[]): void;
|
|
12
|
+
private prefix;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=IdLogger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGvB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGtB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIvB,OAAO,CAAC,MAAM;CAGf"}
|
|
@@ -4,11 +4,11 @@ export declare class IdLogger implements Logger {
|
|
|
4
4
|
private _logger;
|
|
5
5
|
constructor(logger: Logger, id?: () => string);
|
|
6
6
|
set id(id: string);
|
|
7
|
-
debug(
|
|
8
|
-
error(
|
|
9
|
-
info(
|
|
10
|
-
log(
|
|
11
|
-
warn(
|
|
12
|
-
private
|
|
7
|
+
debug(...data: unknown[]): void;
|
|
8
|
+
error(...data: unknown[]): void;
|
|
9
|
+
info(...data: unknown[]): void;
|
|
10
|
+
log(...data: unknown[]): void;
|
|
11
|
+
warn(...data: unknown[]): void;
|
|
12
|
+
private prefix;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=IdLogger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGvB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGtB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIvB,OAAO,CAAC,MAAM;CAGf"}
|
|
@@ -4,11 +4,11 @@ export declare class IdLogger implements Logger {
|
|
|
4
4
|
private _logger;
|
|
5
5
|
constructor(logger: Logger, id?: () => string);
|
|
6
6
|
set id(id: string);
|
|
7
|
-
debug(
|
|
8
|
-
error(
|
|
9
|
-
info(
|
|
10
|
-
log(
|
|
11
|
-
warn(
|
|
12
|
-
private
|
|
7
|
+
debug(...data: unknown[]): void;
|
|
8
|
+
error(...data: unknown[]): void;
|
|
9
|
+
info(...data: unknown[]): void;
|
|
10
|
+
log(...data: unknown[]): void;
|
|
11
|
+
warn(...data: unknown[]): void;
|
|
12
|
+
private prefix;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=IdLogger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGvB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGtB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIvB,OAAO,CAAC,MAAM;CAGf"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type LogFunction = (
|
|
1
|
+
export type LogFunction = (...data: unknown[]) => void;
|
|
2
2
|
/**
|
|
3
3
|
* Interface to handle overlap between Winston &
|
|
4
4
|
* `console` with as much congruency as possible.
|
|
@@ -42,5 +42,4 @@ export declare class ConsoleLogger implements Logger {
|
|
|
42
42
|
(message?: any, ...optionalParams: any[]): void;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
export declare const getFunctionName: (depth?: number) => string;
|
|
46
45
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -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":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEtD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,GAAG,IAAI;CACR;AAED,eAAO,MAAM,eAAe,cAAe,OAAO,cAAY,CAAA;AAE9D,qBAAa,aAAc,YAAW,MAAM;IAC9B,QAAQ,CAAC,KAAK,EAAE,QAAQ;gBAAf,KAAK,GAAE,QAAwB;IAEpD,IAAI,KAAK;;;MAER;IAED,IAAI,KAAK;;;MAER;IAED,IAAI,IAAI;;;MAEP;IAED,IAAI,GAAG;;;MAEN;IAED,IAAI,IAAI;;;MAEP;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type LogFunction = (
|
|
1
|
+
export type LogFunction = (...data: unknown[]) => void;
|
|
2
2
|
/**
|
|
3
3
|
* Interface to handle overlap between Winston &
|
|
4
4
|
* `console` with as much congruency as possible.
|
|
@@ -42,5 +42,4 @@ export declare class ConsoleLogger implements Logger {
|
|
|
42
42
|
(message?: any, ...optionalParams: any[]): void;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
export declare const getFunctionName: (depth?: number) => string;
|
|
46
45
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -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":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEtD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,GAAG,IAAI;CACR;AAED,eAAO,MAAM,eAAe,cAAe,OAAO,cAAY,CAAA;AAE9D,qBAAa,aAAc,YAAW,MAAM;IAC9B,QAAQ,CAAC,KAAK,EAAE,QAAQ;gBAAf,KAAK,GAAE,QAAwB;IAEpD,IAAI,KAAK;;;MAER;IAED,IAAI,KAAK;;;MAER;IAED,IAAI,IAAI;;;MAEP;IAED,IAAI,GAAG;;;MAEN;IAED,IAAI,IAAI;;;MAEP;CACF"}
|
package/dist/browser/Logger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type LogFunction = (
|
|
1
|
+
export type LogFunction = (...data: unknown[]) => void;
|
|
2
2
|
/**
|
|
3
3
|
* Interface to handle overlap between Winston &
|
|
4
4
|
* `console` with as much congruency as possible.
|
|
@@ -42,5 +42,4 @@ export declare class ConsoleLogger implements Logger {
|
|
|
42
42
|
(message?: any, ...optionalParams: any[]): void;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
export declare const getFunctionName: (depth?: number) => string;
|
|
46
45
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -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":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEtD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,GAAG,IAAI;CACR;AAED,eAAO,MAAM,eAAe,cAAe,OAAO,cAAY,CAAA;AAE9D,qBAAa,aAAc,YAAW,MAAM;IAC9B,QAAQ,CAAC,KAAK,EAAE,QAAQ;gBAAf,KAAK,GAAE,QAAwB;IAEpD,IAAI,KAAK;;;MAER;IAED,IAAI,KAAK;;;MAER;IAED,IAAI,IAAI;;;MAEP;IAED,IAAI,GAAG;;;MAEN;IAED,IAAI,IAAI;;;MAEP;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFunctionName.d.ts","sourceRoot":"","sources":["../../src/getFunctionName.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFunctionName.d.ts","sourceRoot":"","sources":["../../src/getFunctionName.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFunctionName.d.ts","sourceRoot":"","sources":["../../src/getFunctionName.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -28,37 +28,8 @@ __export(src_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(src_exports);
|
|
30
30
|
|
|
31
|
-
// src/
|
|
31
|
+
// src/getFunctionName.ts
|
|
32
32
|
var import_error = require("@xylabs/error");
|
|
33
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
34
|
-
LogLevel2[LogLevel2["error"] = 1] = "error";
|
|
35
|
-
LogLevel2[LogLevel2["warn"] = 2] = "warn";
|
|
36
|
-
LogLevel2[LogLevel2["info"] = 3] = "info";
|
|
37
|
-
LogLevel2[LogLevel2["debug"] = 4] = "debug";
|
|
38
|
-
LogLevel2[LogLevel2["log"] = 5] = "log";
|
|
39
|
-
return LogLevel2;
|
|
40
|
-
})(LogLevel || {});
|
|
41
|
-
var NoOpLogFunction = (_message) => void 0;
|
|
42
|
-
var ConsoleLogger = class {
|
|
43
|
-
constructor(level = 2 /* warn */) {
|
|
44
|
-
this.level = level;
|
|
45
|
-
}
|
|
46
|
-
get debug() {
|
|
47
|
-
return this.level >= 4 /* debug */ ? console.debug : NoOpLogFunction;
|
|
48
|
-
}
|
|
49
|
-
get error() {
|
|
50
|
-
return this.level >= 1 /* error */ ? console.error : NoOpLogFunction;
|
|
51
|
-
}
|
|
52
|
-
get info() {
|
|
53
|
-
return this.level >= 3 /* info */ ? console.info : NoOpLogFunction;
|
|
54
|
-
}
|
|
55
|
-
get log() {
|
|
56
|
-
return this.level >= 5 /* log */ ? console.log : NoOpLogFunction;
|
|
57
|
-
}
|
|
58
|
-
get warn() {
|
|
59
|
-
return this.level >= 2 /* warn */ ? console.warn : NoOpLogFunction;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
33
|
var getFunctionName = (depth = 2) => {
|
|
63
34
|
try {
|
|
64
35
|
throw new Error("Getting function name");
|
|
@@ -90,23 +61,54 @@ var IdLogger = class {
|
|
|
90
61
|
set id(id) {
|
|
91
62
|
this._id = () => id;
|
|
92
63
|
}
|
|
93
|
-
debug(
|
|
94
|
-
this._logger?.debug(this.
|
|
64
|
+
debug(...data) {
|
|
65
|
+
this._logger?.debug(this.prefix(), ...data);
|
|
66
|
+
}
|
|
67
|
+
error(...data) {
|
|
68
|
+
this._logger?.error(this.prefix(), ...data);
|
|
95
69
|
}
|
|
96
|
-
|
|
97
|
-
this._logger?.
|
|
70
|
+
info(...data) {
|
|
71
|
+
this._logger?.info(this.prefix(), ...data);
|
|
98
72
|
}
|
|
99
|
-
|
|
100
|
-
this._logger?.
|
|
73
|
+
log(...data) {
|
|
74
|
+
this._logger?.log(this.prefix(), ...data);
|
|
101
75
|
}
|
|
102
|
-
|
|
103
|
-
this._logger?.
|
|
76
|
+
warn(...data) {
|
|
77
|
+
this._logger?.warn(this.prefix(), ...data);
|
|
104
78
|
}
|
|
105
|
-
|
|
106
|
-
this.
|
|
79
|
+
prefix() {
|
|
80
|
+
return `[${this._id?.()}|${getFunctionName(4)}]`;
|
|
107
81
|
}
|
|
108
|
-
|
|
109
|
-
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/Logger.ts
|
|
85
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
86
|
+
LogLevel2[LogLevel2["error"] = 1] = "error";
|
|
87
|
+
LogLevel2[LogLevel2["warn"] = 2] = "warn";
|
|
88
|
+
LogLevel2[LogLevel2["info"] = 3] = "info";
|
|
89
|
+
LogLevel2[LogLevel2["debug"] = 4] = "debug";
|
|
90
|
+
LogLevel2[LogLevel2["log"] = 5] = "log";
|
|
91
|
+
return LogLevel2;
|
|
92
|
+
})(LogLevel || {});
|
|
93
|
+
var NoOpLogFunction = (_message) => void 0;
|
|
94
|
+
var ConsoleLogger = class {
|
|
95
|
+
constructor(level = 2 /* warn */) {
|
|
96
|
+
this.level = level;
|
|
97
|
+
}
|
|
98
|
+
get debug() {
|
|
99
|
+
return this.level >= 4 /* debug */ ? console.debug : NoOpLogFunction;
|
|
100
|
+
}
|
|
101
|
+
get error() {
|
|
102
|
+
return this.level >= 1 /* error */ ? console.error : NoOpLogFunction;
|
|
103
|
+
}
|
|
104
|
+
get info() {
|
|
105
|
+
return this.level >= 3 /* info */ ? console.info : NoOpLogFunction;
|
|
106
|
+
}
|
|
107
|
+
get log() {
|
|
108
|
+
return this.level >= 5 /* log */ ? console.log : NoOpLogFunction;
|
|
109
|
+
}
|
|
110
|
+
get warn() {
|
|
111
|
+
return this.level >= 2 /* warn */ ? console.warn : NoOpLogFunction;
|
|
110
112
|
}
|
|
111
113
|
};
|
|
112
114
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/getFunctionName.ts","../../src/IdLogger.ts","../../src/Logger.ts"],"sourcesContent":["export * from './getFunctionName'\nexport * from './IdLogger'\nexport * from './Logger'\n","import { handleError } from '@xylabs/error'\n\nexport const getFunctionName = (depth = 2) => {\n try {\n throw new Error('Getting function name')\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | undefined\n const stackParts = error.stack?.split('\\n')[depth].split(' ')\n const funcName =\n stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n //check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return item\n }\n }) ?? '<unknown>'\n return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n","import { getFunctionName } from './getFunctionName'\nimport { Logger } from './Logger'\n\nexport class IdLogger implements Logger {\n private _id?: () => string\n private _logger: Logger\n\n constructor(logger: Logger, id?: () => string) {\n this._logger = logger\n this._id = id\n }\n\n set id(id: string) {\n this._id = () => id\n }\n\n debug(...data: unknown[]) {\n this._logger?.debug(this.prefix(), ...data)\n }\n error(...data: unknown[]) {\n this._logger?.error(this.prefix(), ...data)\n }\n info(...data: unknown[]) {\n this._logger?.info(this.prefix(), ...data)\n }\n log(...data: unknown[]) {\n this._logger?.log(this.prefix(), ...data)\n }\n warn(...data: unknown[]) {\n this._logger?.warn(this.prefix(), ...data)\n }\n\n private prefix() {\n return `[${this._id?.()}|${getFunctionName(4)}]`\n }\n}\n","export type LogFunction = (...data: unknown[]) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\nexport enum LogLevel {\n error = 1,\n warn = 2,\n info = 3,\n debug = 4,\n log = 5,\n}\n\nexport const NoOpLogFunction = (_message?: unknown) => void {}\n\nexport class ConsoleLogger implements Logger {\n constructor(readonly level: LogLevel = LogLevel.warn) {}\n\n get debug() {\n return this.level >= LogLevel.debug ? console.debug : NoOpLogFunction\n }\n\n get error() {\n return this.level >= LogLevel.error ? console.error : NoOpLogFunction\n }\n\n get info() {\n return this.level >= LogLevel.info ? console.info : NoOpLogFunction\n }\n\n get log() {\n return this.level >= LogLevel.log ? console.log : NoOpLogFunction\n }\n\n get warn() {\n return this.level >= LogLevel.warn ? console.warn : NoOpLogFunction\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4B;AAErB,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC,SAAS,IAAI;AACX,eAAO,0BAAY,IAAI,CAAC,UAAU;AAChC,UAAI;AACJ,YAAM,aAAa,MAAM,OAAO,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG;AAC5D,YAAM,WACJ,YAAY,KAAK,CAAC,MAAM,UAAU;AAChC,YAAI,KAAK,SAAS,KAAK,SAAS,MAAM;AAEpC,cAAI,SAAS,OAAO;AAClB,uBAAW;AAAA,UACb;AACA,iBAAO;AAAA,QACT;AAAA,MACF,CAAC,KAAK;AACR,aAAO,WAAW,GAAG,QAAQ,IAAI,aAAa,WAAW,CAAC,CAAC,KAAK;AAAA,IAClE,CAAC;AAAA,EACH;AACF;;;ACnBO,IAAM,WAAN,MAAiC;AAAA,EAC9B;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,IAAmB;AAC7C,SAAK,UAAU;AACf,SAAK,MAAM;AAAA,EACb;AAAA,EAEA,IAAI,GAAG,IAAY;AACjB,SAAK,MAAM,MAAM;AAAA,EACnB;AAAA,EAEA,SAAS,MAAiB;AACxB,SAAK,SAAS,MAAM,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC5C;AAAA,EACA,SAAS,MAAiB;AACxB,SAAK,SAAS,MAAM,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC5C;AAAA,EACA,QAAQ,MAAiB;AACvB,SAAK,SAAS,KAAK,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC3C;AAAA,EACA,OAAO,MAAiB;AACtB,SAAK,SAAS,IAAI,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC1C;AAAA,EACA,QAAQ,MAAiB;AACvB,SAAK,SAAS,KAAK,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC3C;AAAA,EAEQ,SAAS;AACf,WAAO,IAAI,KAAK,MAAM,CAAC,IAAI,gBAAgB,CAAC,CAAC;AAAA,EAC/C;AACF;;;ACrBO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,SAAM,KAAN;AALU,SAAAA;AAAA,GAAA;AAQL,IAAM,kBAAkB,CAAC,aAAuB;AAEhD,IAAM,gBAAN,MAAsC;AAAA,EAC3C,YAAqB,QAAkB,cAAe;AAAjC;AAAA,EAAkC;AAAA,EAEvD,IAAI,QAAQ;AACV,WAAO,KAAK,SAAS,gBAAiB,QAAQ,QAAQ;AAAA,EACxD;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,KAAK,SAAS,gBAAiB,QAAQ,QAAQ;AAAA,EACxD;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS,eAAgB,QAAQ,OAAO;AAAA,EACtD;AAAA,EAEA,IAAI,MAAM;AACR,WAAO,KAAK,SAAS,cAAe,QAAQ,MAAM;AAAA,EACpD;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS,eAAgB,QAAQ,OAAO;AAAA,EACtD;AACF;","names":["LogLevel"]}
|
package/dist/browser/index.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
package/dist/browser/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,34 +1,5 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/getFunctionName.ts
|
|
2
2
|
import { handleError } from "@xylabs/error";
|
|
3
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
4
|
-
LogLevel2[LogLevel2["error"] = 1] = "error";
|
|
5
|
-
LogLevel2[LogLevel2["warn"] = 2] = "warn";
|
|
6
|
-
LogLevel2[LogLevel2["info"] = 3] = "info";
|
|
7
|
-
LogLevel2[LogLevel2["debug"] = 4] = "debug";
|
|
8
|
-
LogLevel2[LogLevel2["log"] = 5] = "log";
|
|
9
|
-
return LogLevel2;
|
|
10
|
-
})(LogLevel || {});
|
|
11
|
-
var NoOpLogFunction = (_message) => void 0;
|
|
12
|
-
var ConsoleLogger = class {
|
|
13
|
-
constructor(level = 2 /* warn */) {
|
|
14
|
-
this.level = level;
|
|
15
|
-
}
|
|
16
|
-
get debug() {
|
|
17
|
-
return this.level >= 4 /* debug */ ? console.debug : NoOpLogFunction;
|
|
18
|
-
}
|
|
19
|
-
get error() {
|
|
20
|
-
return this.level >= 1 /* error */ ? console.error : NoOpLogFunction;
|
|
21
|
-
}
|
|
22
|
-
get info() {
|
|
23
|
-
return this.level >= 3 /* info */ ? console.info : NoOpLogFunction;
|
|
24
|
-
}
|
|
25
|
-
get log() {
|
|
26
|
-
return this.level >= 5 /* log */ ? console.log : NoOpLogFunction;
|
|
27
|
-
}
|
|
28
|
-
get warn() {
|
|
29
|
-
return this.level >= 2 /* warn */ ? console.warn : NoOpLogFunction;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
3
|
var getFunctionName = (depth = 2) => {
|
|
33
4
|
try {
|
|
34
5
|
throw new Error("Getting function name");
|
|
@@ -60,23 +31,54 @@ var IdLogger = class {
|
|
|
60
31
|
set id(id) {
|
|
61
32
|
this._id = () => id;
|
|
62
33
|
}
|
|
63
|
-
debug(
|
|
64
|
-
this._logger?.debug(this.
|
|
34
|
+
debug(...data) {
|
|
35
|
+
this._logger?.debug(this.prefix(), ...data);
|
|
36
|
+
}
|
|
37
|
+
error(...data) {
|
|
38
|
+
this._logger?.error(this.prefix(), ...data);
|
|
65
39
|
}
|
|
66
|
-
|
|
67
|
-
this._logger?.
|
|
40
|
+
info(...data) {
|
|
41
|
+
this._logger?.info(this.prefix(), ...data);
|
|
68
42
|
}
|
|
69
|
-
|
|
70
|
-
this._logger?.
|
|
43
|
+
log(...data) {
|
|
44
|
+
this._logger?.log(this.prefix(), ...data);
|
|
71
45
|
}
|
|
72
|
-
|
|
73
|
-
this._logger?.
|
|
46
|
+
warn(...data) {
|
|
47
|
+
this._logger?.warn(this.prefix(), ...data);
|
|
74
48
|
}
|
|
75
|
-
|
|
76
|
-
this.
|
|
49
|
+
prefix() {
|
|
50
|
+
return `[${this._id?.()}|${getFunctionName(4)}]`;
|
|
77
51
|
}
|
|
78
|
-
|
|
79
|
-
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/Logger.ts
|
|
55
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
56
|
+
LogLevel2[LogLevel2["error"] = 1] = "error";
|
|
57
|
+
LogLevel2[LogLevel2["warn"] = 2] = "warn";
|
|
58
|
+
LogLevel2[LogLevel2["info"] = 3] = "info";
|
|
59
|
+
LogLevel2[LogLevel2["debug"] = 4] = "debug";
|
|
60
|
+
LogLevel2[LogLevel2["log"] = 5] = "log";
|
|
61
|
+
return LogLevel2;
|
|
62
|
+
})(LogLevel || {});
|
|
63
|
+
var NoOpLogFunction = (_message) => void 0;
|
|
64
|
+
var ConsoleLogger = class {
|
|
65
|
+
constructor(level = 2 /* warn */) {
|
|
66
|
+
this.level = level;
|
|
67
|
+
}
|
|
68
|
+
get debug() {
|
|
69
|
+
return this.level >= 4 /* debug */ ? console.debug : NoOpLogFunction;
|
|
70
|
+
}
|
|
71
|
+
get error() {
|
|
72
|
+
return this.level >= 1 /* error */ ? console.error : NoOpLogFunction;
|
|
73
|
+
}
|
|
74
|
+
get info() {
|
|
75
|
+
return this.level >= 3 /* info */ ? console.info : NoOpLogFunction;
|
|
76
|
+
}
|
|
77
|
+
get log() {
|
|
78
|
+
return this.level >= 5 /* log */ ? console.log : NoOpLogFunction;
|
|
79
|
+
}
|
|
80
|
+
get warn() {
|
|
81
|
+
return this.level >= 2 /* warn */ ? console.warn : NoOpLogFunction;
|
|
80
82
|
}
|
|
81
83
|
};
|
|
82
84
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/getFunctionName.ts","../../src/IdLogger.ts","../../src/Logger.ts"],"sourcesContent":["import { handleError } from '@xylabs/error'\n\nexport const getFunctionName = (depth = 2) => {\n try {\n throw new Error('Getting function name')\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | undefined\n const stackParts = error.stack?.split('\\n')[depth].split(' ')\n const funcName =\n stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n //check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return item\n }\n }) ?? '<unknown>'\n return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n","import { getFunctionName } from './getFunctionName'\nimport { Logger } from './Logger'\n\nexport class IdLogger implements Logger {\n private _id?: () => string\n private _logger: Logger\n\n constructor(logger: Logger, id?: () => string) {\n this._logger = logger\n this._id = id\n }\n\n set id(id: string) {\n this._id = () => id\n }\n\n debug(...data: unknown[]) {\n this._logger?.debug(this.prefix(), ...data)\n }\n error(...data: unknown[]) {\n this._logger?.error(this.prefix(), ...data)\n }\n info(...data: unknown[]) {\n this._logger?.info(this.prefix(), ...data)\n }\n log(...data: unknown[]) {\n this._logger?.log(this.prefix(), ...data)\n }\n warn(...data: unknown[]) {\n this._logger?.warn(this.prefix(), ...data)\n }\n\n private prefix() {\n return `[${this._id?.()}|${getFunctionName(4)}]`\n }\n}\n","export type LogFunction = (...data: unknown[]) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\nexport enum LogLevel {\n error = 1,\n warn = 2,\n info = 3,\n debug = 4,\n log = 5,\n}\n\nexport const NoOpLogFunction = (_message?: unknown) => void {}\n\nexport class ConsoleLogger implements Logger {\n constructor(readonly level: LogLevel = LogLevel.warn) {}\n\n get debug() {\n return this.level >= LogLevel.debug ? console.debug : NoOpLogFunction\n }\n\n get error() {\n return this.level >= LogLevel.error ? console.error : NoOpLogFunction\n }\n\n get info() {\n return this.level >= LogLevel.info ? console.info : NoOpLogFunction\n }\n\n get log() {\n return this.level >= LogLevel.log ? console.log : NoOpLogFunction\n }\n\n get warn() {\n return this.level >= LogLevel.warn ? console.warn : NoOpLogFunction\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAErB,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC,SAAS,IAAI;AACX,WAAO,YAAY,IAAI,CAAC,UAAU;AAChC,UAAI;AACJ,YAAM,aAAa,MAAM,OAAO,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG;AAC5D,YAAM,WACJ,YAAY,KAAK,CAAC,MAAM,UAAU;AAChC,YAAI,KAAK,SAAS,KAAK,SAAS,MAAM;AAEpC,cAAI,SAAS,OAAO;AAClB,uBAAW;AAAA,UACb;AACA,iBAAO;AAAA,QACT;AAAA,MACF,CAAC,KAAK;AACR,aAAO,WAAW,GAAG,QAAQ,IAAI,aAAa,WAAW,CAAC,CAAC,KAAK;AAAA,IAClE,CAAC;AAAA,EACH;AACF;;;ACnBO,IAAM,WAAN,MAAiC;AAAA,EAC9B;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,IAAmB;AAC7C,SAAK,UAAU;AACf,SAAK,MAAM;AAAA,EACb;AAAA,EAEA,IAAI,GAAG,IAAY;AACjB,SAAK,MAAM,MAAM;AAAA,EACnB;AAAA,EAEA,SAAS,MAAiB;AACxB,SAAK,SAAS,MAAM,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC5C;AAAA,EACA,SAAS,MAAiB;AACxB,SAAK,SAAS,MAAM,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC5C;AAAA,EACA,QAAQ,MAAiB;AACvB,SAAK,SAAS,KAAK,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC3C;AAAA,EACA,OAAO,MAAiB;AACtB,SAAK,SAAS,IAAI,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC1C;AAAA,EACA,QAAQ,MAAiB;AACvB,SAAK,SAAS,KAAK,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC3C;AAAA,EAEQ,SAAS;AACf,WAAO,IAAI,KAAK,MAAM,CAAC,IAAI,gBAAgB,CAAC,CAAC;AAAA,EAC/C;AACF;;;ACrBO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,SAAM,KAAN;AALU,SAAAA;AAAA,GAAA;AAQL,IAAM,kBAAkB,CAAC,aAAuB;AAEhD,IAAM,gBAAN,MAAsC;AAAA,EAC3C,YAAqB,QAAkB,cAAe;AAAjC;AAAA,EAAkC;AAAA,EAEvD,IAAI,QAAQ;AACV,WAAO,KAAK,SAAS,gBAAiB,QAAQ,QAAQ;AAAA,EACxD;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,KAAK,SAAS,gBAAiB,QAAQ,QAAQ;AAAA,EACxD;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS,eAAgB,QAAQ,OAAO;AAAA,EACtD;AAAA,EAEA,IAAI,MAAM;AACR,WAAO,KAAK,SAAS,cAAe,QAAQ,MAAM;AAAA,EACpD;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS,eAAgB,QAAQ,OAAO;AAAA,EACtD;AACF;","names":["LogLevel"]}
|
package/dist/node/IdLogger.d.cts
CHANGED
|
@@ -4,11 +4,11 @@ export declare class IdLogger implements Logger {
|
|
|
4
4
|
private _logger;
|
|
5
5
|
constructor(logger: Logger, id?: () => string);
|
|
6
6
|
set id(id: string);
|
|
7
|
-
debug(
|
|
8
|
-
error(
|
|
9
|
-
info(
|
|
10
|
-
log(
|
|
11
|
-
warn(
|
|
12
|
-
private
|
|
7
|
+
debug(...data: unknown[]): void;
|
|
8
|
+
error(...data: unknown[]): void;
|
|
9
|
+
info(...data: unknown[]): void;
|
|
10
|
+
log(...data: unknown[]): void;
|
|
11
|
+
warn(...data: unknown[]): void;
|
|
12
|
+
private prefix;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=IdLogger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGvB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGtB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIvB,OAAO,CAAC,MAAM;CAGf"}
|
package/dist/node/IdLogger.d.mts
CHANGED
|
@@ -4,11 +4,11 @@ export declare class IdLogger implements Logger {
|
|
|
4
4
|
private _logger;
|
|
5
5
|
constructor(logger: Logger, id?: () => string);
|
|
6
6
|
set id(id: string);
|
|
7
|
-
debug(
|
|
8
|
-
error(
|
|
9
|
-
info(
|
|
10
|
-
log(
|
|
11
|
-
warn(
|
|
12
|
-
private
|
|
7
|
+
debug(...data: unknown[]): void;
|
|
8
|
+
error(...data: unknown[]): void;
|
|
9
|
+
info(...data: unknown[]): void;
|
|
10
|
+
log(...data: unknown[]): void;
|
|
11
|
+
warn(...data: unknown[]): void;
|
|
12
|
+
private prefix;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=IdLogger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGvB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGtB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIvB,OAAO,CAAC,MAAM;CAGf"}
|
package/dist/node/IdLogger.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ export declare class IdLogger implements Logger {
|
|
|
4
4
|
private _logger;
|
|
5
5
|
constructor(logger: Logger, id?: () => string);
|
|
6
6
|
set id(id: string);
|
|
7
|
-
debug(
|
|
8
|
-
error(
|
|
9
|
-
info(
|
|
10
|
-
log(
|
|
11
|
-
warn(
|
|
12
|
-
private
|
|
7
|
+
debug(...data: unknown[]): void;
|
|
8
|
+
error(...data: unknown[]): void;
|
|
9
|
+
info(...data: unknown[]): void;
|
|
10
|
+
log(...data: unknown[]): void;
|
|
11
|
+
warn(...data: unknown[]): void;
|
|
12
|
+
private prefix;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=IdLogger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGxB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGvB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAGtB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAIvB,OAAO,CAAC,MAAM;CAGf"}
|
package/dist/node/Logger.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type LogFunction = (
|
|
1
|
+
export type LogFunction = (...data: unknown[]) => void;
|
|
2
2
|
/**
|
|
3
3
|
* Interface to handle overlap between Winston &
|
|
4
4
|
* `console` with as much congruency as possible.
|
|
@@ -42,5 +42,4 @@ export declare class ConsoleLogger implements Logger {
|
|
|
42
42
|
(message?: any, ...optionalParams: any[]): void;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
export declare const getFunctionName: (depth?: number) => string;
|
|
46
45
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -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":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEtD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,GAAG,IAAI;CACR;AAED,eAAO,MAAM,eAAe,cAAe,OAAO,cAAY,CAAA;AAE9D,qBAAa,aAAc,YAAW,MAAM;IAC9B,QAAQ,CAAC,KAAK,EAAE,QAAQ;gBAAf,KAAK,GAAE,QAAwB;IAEpD,IAAI,KAAK;;;MAER;IAED,IAAI,KAAK;;;MAER;IAED,IAAI,IAAI;;;MAEP;IAED,IAAI,GAAG;;;MAEN;IAED,IAAI,IAAI;;;MAEP;CACF"}
|
package/dist/node/Logger.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type LogFunction = (
|
|
1
|
+
export type LogFunction = (...data: unknown[]) => void;
|
|
2
2
|
/**
|
|
3
3
|
* Interface to handle overlap between Winston &
|
|
4
4
|
* `console` with as much congruency as possible.
|
|
@@ -42,5 +42,4 @@ export declare class ConsoleLogger implements Logger {
|
|
|
42
42
|
(message?: any, ...optionalParams: any[]): void;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
export declare const getFunctionName: (depth?: number) => string;
|
|
46
45
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -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":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEtD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,GAAG,IAAI;CACR;AAED,eAAO,MAAM,eAAe,cAAe,OAAO,cAAY,CAAA;AAE9D,qBAAa,aAAc,YAAW,MAAM;IAC9B,QAAQ,CAAC,KAAK,EAAE,QAAQ;gBAAf,KAAK,GAAE,QAAwB;IAEpD,IAAI,KAAK;;;MAER;IAED,IAAI,KAAK;;;MAER;IAED,IAAI,IAAI;;;MAEP;IAED,IAAI,GAAG;;;MAEN;IAED,IAAI,IAAI;;;MAEP;CACF"}
|
package/dist/node/Logger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type LogFunction = (
|
|
1
|
+
export type LogFunction = (...data: unknown[]) => void;
|
|
2
2
|
/**
|
|
3
3
|
* Interface to handle overlap between Winston &
|
|
4
4
|
* `console` with as much congruency as possible.
|
|
@@ -42,5 +42,4 @@ export declare class ConsoleLogger implements Logger {
|
|
|
42
42
|
(message?: any, ...optionalParams: any[]): void;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
export declare const getFunctionName: (depth?: number) => string;
|
|
46
45
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -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":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEtD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,GAAG,EAAE,WAAW,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,GAAG,IAAI;CACR;AAED,eAAO,MAAM,eAAe,cAAe,OAAO,cAAY,CAAA;AAE9D,qBAAa,aAAc,YAAW,MAAM;IAC9B,QAAQ,CAAC,KAAK,EAAE,QAAQ;gBAAf,KAAK,GAAE,QAAwB;IAEpD,IAAI,KAAK;;;MAER;IAED,IAAI,KAAK;;;MAER;IAED,IAAI,IAAI;;;MAEP;IAED,IAAI,GAAG;;;MAEN;IAED,IAAI,IAAI;;;MAEP;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFunctionName.d.ts","sourceRoot":"","sources":["../../src/getFunctionName.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFunctionName.d.ts","sourceRoot":"","sources":["../../src/getFunctionName.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFunctionName.d.ts","sourceRoot":"","sources":["../../src/getFunctionName.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -28,37 +28,8 @@ __export(src_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(src_exports);
|
|
30
30
|
|
|
31
|
-
// src/
|
|
31
|
+
// src/getFunctionName.ts
|
|
32
32
|
var import_error = require("@xylabs/error");
|
|
33
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
34
|
-
LogLevel2[LogLevel2["error"] = 1] = "error";
|
|
35
|
-
LogLevel2[LogLevel2["warn"] = 2] = "warn";
|
|
36
|
-
LogLevel2[LogLevel2["info"] = 3] = "info";
|
|
37
|
-
LogLevel2[LogLevel2["debug"] = 4] = "debug";
|
|
38
|
-
LogLevel2[LogLevel2["log"] = 5] = "log";
|
|
39
|
-
return LogLevel2;
|
|
40
|
-
})(LogLevel || {});
|
|
41
|
-
var NoOpLogFunction = (_message) => void 0;
|
|
42
|
-
var ConsoleLogger = class {
|
|
43
|
-
constructor(level = 2 /* warn */) {
|
|
44
|
-
this.level = level;
|
|
45
|
-
}
|
|
46
|
-
get debug() {
|
|
47
|
-
return this.level >= 4 /* debug */ ? console.debug : NoOpLogFunction;
|
|
48
|
-
}
|
|
49
|
-
get error() {
|
|
50
|
-
return this.level >= 1 /* error */ ? console.error : NoOpLogFunction;
|
|
51
|
-
}
|
|
52
|
-
get info() {
|
|
53
|
-
return this.level >= 3 /* info */ ? console.info : NoOpLogFunction;
|
|
54
|
-
}
|
|
55
|
-
get log() {
|
|
56
|
-
return this.level >= 5 /* log */ ? console.log : NoOpLogFunction;
|
|
57
|
-
}
|
|
58
|
-
get warn() {
|
|
59
|
-
return this.level >= 2 /* warn */ ? console.warn : NoOpLogFunction;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
33
|
var getFunctionName = (depth = 2) => {
|
|
63
34
|
try {
|
|
64
35
|
throw new Error("Getting function name");
|
|
@@ -91,28 +62,60 @@ var IdLogger = class {
|
|
|
91
62
|
set id(id) {
|
|
92
63
|
this._id = () => id;
|
|
93
64
|
}
|
|
94
|
-
debug(
|
|
65
|
+
debug(...data) {
|
|
66
|
+
var _a;
|
|
67
|
+
(_a = this._logger) == null ? void 0 : _a.debug(this.prefix(), ...data);
|
|
68
|
+
}
|
|
69
|
+
error(...data) {
|
|
95
70
|
var _a;
|
|
96
|
-
(_a = this._logger) == null ? void 0 : _a.
|
|
71
|
+
(_a = this._logger) == null ? void 0 : _a.error(this.prefix(), ...data);
|
|
97
72
|
}
|
|
98
|
-
|
|
73
|
+
info(...data) {
|
|
99
74
|
var _a;
|
|
100
|
-
(_a = this._logger) == null ? void 0 : _a.
|
|
75
|
+
(_a = this._logger) == null ? void 0 : _a.info(this.prefix(), ...data);
|
|
101
76
|
}
|
|
102
|
-
|
|
77
|
+
log(...data) {
|
|
103
78
|
var _a;
|
|
104
|
-
(_a = this._logger) == null ? void 0 : _a.
|
|
79
|
+
(_a = this._logger) == null ? void 0 : _a.log(this.prefix(), ...data);
|
|
105
80
|
}
|
|
106
|
-
|
|
81
|
+
warn(...data) {
|
|
107
82
|
var _a;
|
|
108
|
-
(_a = this._logger) == null ? void 0 : _a.
|
|
83
|
+
(_a = this._logger) == null ? void 0 : _a.warn(this.prefix(), ...data);
|
|
109
84
|
}
|
|
110
|
-
|
|
85
|
+
prefix() {
|
|
111
86
|
var _a;
|
|
112
|
-
(_a = this.
|
|
87
|
+
return `[${(_a = this._id) == null ? void 0 : _a.call(this)}|${getFunctionName(4)}]`;
|
|
113
88
|
}
|
|
114
|
-
|
|
115
|
-
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/Logger.ts
|
|
92
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
93
|
+
LogLevel2[LogLevel2["error"] = 1] = "error";
|
|
94
|
+
LogLevel2[LogLevel2["warn"] = 2] = "warn";
|
|
95
|
+
LogLevel2[LogLevel2["info"] = 3] = "info";
|
|
96
|
+
LogLevel2[LogLevel2["debug"] = 4] = "debug";
|
|
97
|
+
LogLevel2[LogLevel2["log"] = 5] = "log";
|
|
98
|
+
return LogLevel2;
|
|
99
|
+
})(LogLevel || {});
|
|
100
|
+
var NoOpLogFunction = (_message) => void 0;
|
|
101
|
+
var ConsoleLogger = class {
|
|
102
|
+
constructor(level = 2 /* warn */) {
|
|
103
|
+
this.level = level;
|
|
104
|
+
}
|
|
105
|
+
get debug() {
|
|
106
|
+
return this.level >= 4 /* debug */ ? console.debug : NoOpLogFunction;
|
|
107
|
+
}
|
|
108
|
+
get error() {
|
|
109
|
+
return this.level >= 1 /* error */ ? console.error : NoOpLogFunction;
|
|
110
|
+
}
|
|
111
|
+
get info() {
|
|
112
|
+
return this.level >= 3 /* info */ ? console.info : NoOpLogFunction;
|
|
113
|
+
}
|
|
114
|
+
get log() {
|
|
115
|
+
return this.level >= 5 /* log */ ? console.log : NoOpLogFunction;
|
|
116
|
+
}
|
|
117
|
+
get warn() {
|
|
118
|
+
return this.level >= 2 /* warn */ ? console.warn : NoOpLogFunction;
|
|
116
119
|
}
|
|
117
120
|
};
|
|
118
121
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/getFunctionName.ts","../../src/IdLogger.ts","../../src/Logger.ts"],"sourcesContent":["export * from './getFunctionName'\nexport * from './IdLogger'\nexport * from './Logger'\n","import { handleError } from '@xylabs/error'\n\nexport const getFunctionName = (depth = 2) => {\n try {\n throw new Error('Getting function name')\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | undefined\n const stackParts = error.stack?.split('\\n')[depth].split(' ')\n const funcName =\n stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n //check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return item\n }\n }) ?? '<unknown>'\n return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n","import { getFunctionName } from './getFunctionName'\nimport { Logger } from './Logger'\n\nexport class IdLogger implements Logger {\n private _id?: () => string\n private _logger: Logger\n\n constructor(logger: Logger, id?: () => string) {\n this._logger = logger\n this._id = id\n }\n\n set id(id: string) {\n this._id = () => id\n }\n\n debug(...data: unknown[]) {\n this._logger?.debug(this.prefix(), ...data)\n }\n error(...data: unknown[]) {\n this._logger?.error(this.prefix(), ...data)\n }\n info(...data: unknown[]) {\n this._logger?.info(this.prefix(), ...data)\n }\n log(...data: unknown[]) {\n this._logger?.log(this.prefix(), ...data)\n }\n warn(...data: unknown[]) {\n this._logger?.warn(this.prefix(), ...data)\n }\n\n private prefix() {\n return `[${this._id?.()}|${getFunctionName(4)}]`\n }\n}\n","export type LogFunction = (...data: unknown[]) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\nexport enum LogLevel {\n error = 1,\n warn = 2,\n info = 3,\n debug = 4,\n log = 5,\n}\n\nexport const NoOpLogFunction = (_message?: unknown) => void {}\n\nexport class ConsoleLogger implements Logger {\n constructor(readonly level: LogLevel = LogLevel.warn) {}\n\n get debug() {\n return this.level >= LogLevel.debug ? console.debug : NoOpLogFunction\n }\n\n get error() {\n return this.level >= LogLevel.error ? console.error : NoOpLogFunction\n }\n\n get info() {\n return this.level >= LogLevel.info ? console.info : NoOpLogFunction\n }\n\n get log() {\n return this.level >= LogLevel.log ? console.log : NoOpLogFunction\n }\n\n get warn() {\n return this.level >= LogLevel.warn ? console.warn : NoOpLogFunction\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4B;AAErB,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC,SAAS,IAAI;AACX,eAAO,0BAAY,IAAI,CAAC,UAAU;AANtC;AAOM,UAAI;AACJ,YAAM,cAAa,WAAM,UAAN,mBAAa,MAAM,MAAM,OAAO,MAAM;AACzD,YAAM,YACJ,yCAAY,KAAK,CAAC,MAAM,UAAU;AAChC,YAAI,KAAK,SAAS,KAAK,SAAS,MAAM;AAEpC,cAAI,SAAS,OAAO;AAClB,uBAAW;AAAA,UACb;AACA,iBAAO;AAAA,QACT;AAAA,MACF,OAAM;AACR,aAAO,WAAW,GAAG,QAAQ,IAAI,yCAAa,WAAW,EAAE,KAAK;AAAA,IAClE,CAAC;AAAA,EACH;AACF;;;ACnBO,IAAM,WAAN,MAAiC;AAAA,EAC9B;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,IAAmB;AAC7C,SAAK,UAAU;AACf,SAAK,MAAM;AAAA,EACb;AAAA,EAEA,IAAI,GAAG,IAAY;AACjB,SAAK,MAAM,MAAM;AAAA,EACnB;AAAA,EAEA,SAAS,MAAiB;AAhB5B;AAiBI,eAAK,YAAL,mBAAc,MAAM,KAAK,OAAO,GAAG,GAAG;AAAA,EACxC;AAAA,EACA,SAAS,MAAiB;AAnB5B;AAoBI,eAAK,YAAL,mBAAc,MAAM,KAAK,OAAO,GAAG,GAAG;AAAA,EACxC;AAAA,EACA,QAAQ,MAAiB;AAtB3B;AAuBI,eAAK,YAAL,mBAAc,KAAK,KAAK,OAAO,GAAG,GAAG;AAAA,EACvC;AAAA,EACA,OAAO,MAAiB;AAzB1B;AA0BI,eAAK,YAAL,mBAAc,IAAI,KAAK,OAAO,GAAG,GAAG;AAAA,EACtC;AAAA,EACA,QAAQ,MAAiB;AA5B3B;AA6BI,eAAK,YAAL,mBAAc,KAAK,KAAK,OAAO,GAAG,GAAG;AAAA,EACvC;AAAA,EAEQ,SAAS;AAhCnB;AAiCI,WAAO,KAAI,UAAK,QAAL,6BAAY,IAAI,gBAAgB,CAAC,CAAC;AAAA,EAC/C;AACF;;;ACrBO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,SAAM,KAAN;AALU,SAAAA;AAAA,GAAA;AAQL,IAAM,kBAAkB,CAAC,aAAuB;AAEhD,IAAM,gBAAN,MAAsC;AAAA,EAC3C,YAAqB,QAAkB,cAAe;AAAjC;AAAA,EAAkC;AAAA,EAEvD,IAAI,QAAQ;AACV,WAAO,KAAK,SAAS,gBAAiB,QAAQ,QAAQ;AAAA,EACxD;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,KAAK,SAAS,gBAAiB,QAAQ,QAAQ;AAAA,EACxD;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS,eAAgB,QAAQ,OAAO;AAAA,EACtD;AAAA,EAEA,IAAI,MAAM;AACR,WAAO,KAAK,SAAS,cAAe,QAAQ,MAAM;AAAA,EACpD;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS,eAAgB,QAAQ,OAAO;AAAA,EACtD;AACF;","names":["LogLevel"]}
|
package/dist/node/index.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
package/dist/node/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
package/dist/node/index.js
CHANGED
|
@@ -1,34 +1,5 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/getFunctionName.ts
|
|
2
2
|
import { handleError } from "@xylabs/error";
|
|
3
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
4
|
-
LogLevel2[LogLevel2["error"] = 1] = "error";
|
|
5
|
-
LogLevel2[LogLevel2["warn"] = 2] = "warn";
|
|
6
|
-
LogLevel2[LogLevel2["info"] = 3] = "info";
|
|
7
|
-
LogLevel2[LogLevel2["debug"] = 4] = "debug";
|
|
8
|
-
LogLevel2[LogLevel2["log"] = 5] = "log";
|
|
9
|
-
return LogLevel2;
|
|
10
|
-
})(LogLevel || {});
|
|
11
|
-
var NoOpLogFunction = (_message) => void 0;
|
|
12
|
-
var ConsoleLogger = class {
|
|
13
|
-
constructor(level = 2 /* warn */) {
|
|
14
|
-
this.level = level;
|
|
15
|
-
}
|
|
16
|
-
get debug() {
|
|
17
|
-
return this.level >= 4 /* debug */ ? console.debug : NoOpLogFunction;
|
|
18
|
-
}
|
|
19
|
-
get error() {
|
|
20
|
-
return this.level >= 1 /* error */ ? console.error : NoOpLogFunction;
|
|
21
|
-
}
|
|
22
|
-
get info() {
|
|
23
|
-
return this.level >= 3 /* info */ ? console.info : NoOpLogFunction;
|
|
24
|
-
}
|
|
25
|
-
get log() {
|
|
26
|
-
return this.level >= 5 /* log */ ? console.log : NoOpLogFunction;
|
|
27
|
-
}
|
|
28
|
-
get warn() {
|
|
29
|
-
return this.level >= 2 /* warn */ ? console.warn : NoOpLogFunction;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
3
|
var getFunctionName = (depth = 2) => {
|
|
33
4
|
try {
|
|
34
5
|
throw new Error("Getting function name");
|
|
@@ -61,28 +32,60 @@ var IdLogger = class {
|
|
|
61
32
|
set id(id) {
|
|
62
33
|
this._id = () => id;
|
|
63
34
|
}
|
|
64
|
-
debug(
|
|
35
|
+
debug(...data) {
|
|
36
|
+
var _a;
|
|
37
|
+
(_a = this._logger) == null ? void 0 : _a.debug(this.prefix(), ...data);
|
|
38
|
+
}
|
|
39
|
+
error(...data) {
|
|
65
40
|
var _a;
|
|
66
|
-
(_a = this._logger) == null ? void 0 : _a.
|
|
41
|
+
(_a = this._logger) == null ? void 0 : _a.error(this.prefix(), ...data);
|
|
67
42
|
}
|
|
68
|
-
|
|
43
|
+
info(...data) {
|
|
69
44
|
var _a;
|
|
70
|
-
(_a = this._logger) == null ? void 0 : _a.
|
|
45
|
+
(_a = this._logger) == null ? void 0 : _a.info(this.prefix(), ...data);
|
|
71
46
|
}
|
|
72
|
-
|
|
47
|
+
log(...data) {
|
|
73
48
|
var _a;
|
|
74
|
-
(_a = this._logger) == null ? void 0 : _a.
|
|
49
|
+
(_a = this._logger) == null ? void 0 : _a.log(this.prefix(), ...data);
|
|
75
50
|
}
|
|
76
|
-
|
|
51
|
+
warn(...data) {
|
|
77
52
|
var _a;
|
|
78
|
-
(_a = this._logger) == null ? void 0 : _a.
|
|
53
|
+
(_a = this._logger) == null ? void 0 : _a.warn(this.prefix(), ...data);
|
|
79
54
|
}
|
|
80
|
-
|
|
55
|
+
prefix() {
|
|
81
56
|
var _a;
|
|
82
|
-
(_a = this.
|
|
57
|
+
return `[${(_a = this._id) == null ? void 0 : _a.call(this)}|${getFunctionName(4)}]`;
|
|
83
58
|
}
|
|
84
|
-
|
|
85
|
-
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/Logger.ts
|
|
62
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
63
|
+
LogLevel2[LogLevel2["error"] = 1] = "error";
|
|
64
|
+
LogLevel2[LogLevel2["warn"] = 2] = "warn";
|
|
65
|
+
LogLevel2[LogLevel2["info"] = 3] = "info";
|
|
66
|
+
LogLevel2[LogLevel2["debug"] = 4] = "debug";
|
|
67
|
+
LogLevel2[LogLevel2["log"] = 5] = "log";
|
|
68
|
+
return LogLevel2;
|
|
69
|
+
})(LogLevel || {});
|
|
70
|
+
var NoOpLogFunction = (_message) => void 0;
|
|
71
|
+
var ConsoleLogger = class {
|
|
72
|
+
constructor(level = 2 /* warn */) {
|
|
73
|
+
this.level = level;
|
|
74
|
+
}
|
|
75
|
+
get debug() {
|
|
76
|
+
return this.level >= 4 /* debug */ ? console.debug : NoOpLogFunction;
|
|
77
|
+
}
|
|
78
|
+
get error() {
|
|
79
|
+
return this.level >= 1 /* error */ ? console.error : NoOpLogFunction;
|
|
80
|
+
}
|
|
81
|
+
get info() {
|
|
82
|
+
return this.level >= 3 /* info */ ? console.info : NoOpLogFunction;
|
|
83
|
+
}
|
|
84
|
+
get log() {
|
|
85
|
+
return this.level >= 5 /* log */ ? console.log : NoOpLogFunction;
|
|
86
|
+
}
|
|
87
|
+
get warn() {
|
|
88
|
+
return this.level >= 2 /* warn */ ? console.warn : NoOpLogFunction;
|
|
86
89
|
}
|
|
87
90
|
};
|
|
88
91
|
export {
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/getFunctionName.ts","../../src/IdLogger.ts","../../src/Logger.ts"],"sourcesContent":["import { handleError } from '@xylabs/error'\n\nexport const getFunctionName = (depth = 2) => {\n try {\n throw new Error('Getting function name')\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | undefined\n const stackParts = error.stack?.split('\\n')[depth].split(' ')\n const funcName =\n stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n //check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return item\n }\n }) ?? '<unknown>'\n return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n","import { getFunctionName } from './getFunctionName'\nimport { Logger } from './Logger'\n\nexport class IdLogger implements Logger {\n private _id?: () => string\n private _logger: Logger\n\n constructor(logger: Logger, id?: () => string) {\n this._logger = logger\n this._id = id\n }\n\n set id(id: string) {\n this._id = () => id\n }\n\n debug(...data: unknown[]) {\n this._logger?.debug(this.prefix(), ...data)\n }\n error(...data: unknown[]) {\n this._logger?.error(this.prefix(), ...data)\n }\n info(...data: unknown[]) {\n this._logger?.info(this.prefix(), ...data)\n }\n log(...data: unknown[]) {\n this._logger?.log(this.prefix(), ...data)\n }\n warn(...data: unknown[]) {\n this._logger?.warn(this.prefix(), ...data)\n }\n\n private prefix() {\n return `[${this._id?.()}|${getFunctionName(4)}]`\n }\n}\n","export type LogFunction = (...data: unknown[]) => void\n\n/**\n * Interface to handle overlap between Winston &\n * `console` with as much congruency as possible.\n */\nexport interface Logger {\n debug: LogFunction\n error: LogFunction\n info: LogFunction\n log: LogFunction\n warn: LogFunction\n}\n\nexport enum LogLevel {\n error = 1,\n warn = 2,\n info = 3,\n debug = 4,\n log = 5,\n}\n\nexport const NoOpLogFunction = (_message?: unknown) => void {}\n\nexport class ConsoleLogger implements Logger {\n constructor(readonly level: LogLevel = LogLevel.warn) {}\n\n get debug() {\n return this.level >= LogLevel.debug ? console.debug : NoOpLogFunction\n }\n\n get error() {\n return this.level >= LogLevel.error ? console.error : NoOpLogFunction\n }\n\n get info() {\n return this.level >= LogLevel.info ? console.info : NoOpLogFunction\n }\n\n get log() {\n return this.level >= LogLevel.log ? console.log : NoOpLogFunction\n }\n\n get warn() {\n return this.level >= LogLevel.warn ? console.warn : NoOpLogFunction\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAErB,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC,SAAS,IAAI;AACX,WAAO,YAAY,IAAI,CAAC,UAAU;AANtC;AAOM,UAAI;AACJ,YAAM,cAAa,WAAM,UAAN,mBAAa,MAAM,MAAM,OAAO,MAAM;AACzD,YAAM,YACJ,yCAAY,KAAK,CAAC,MAAM,UAAU;AAChC,YAAI,KAAK,SAAS,KAAK,SAAS,MAAM;AAEpC,cAAI,SAAS,OAAO;AAClB,uBAAW;AAAA,UACb;AACA,iBAAO;AAAA,QACT;AAAA,MACF,OAAM;AACR,aAAO,WAAW,GAAG,QAAQ,IAAI,yCAAa,WAAW,EAAE,KAAK;AAAA,IAClE,CAAC;AAAA,EACH;AACF;;;ACnBO,IAAM,WAAN,MAAiC;AAAA,EAC9B;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,IAAmB;AAC7C,SAAK,UAAU;AACf,SAAK,MAAM;AAAA,EACb;AAAA,EAEA,IAAI,GAAG,IAAY;AACjB,SAAK,MAAM,MAAM;AAAA,EACnB;AAAA,EAEA,SAAS,MAAiB;AAhB5B;AAiBI,eAAK,YAAL,mBAAc,MAAM,KAAK,OAAO,GAAG,GAAG;AAAA,EACxC;AAAA,EACA,SAAS,MAAiB;AAnB5B;AAoBI,eAAK,YAAL,mBAAc,MAAM,KAAK,OAAO,GAAG,GAAG;AAAA,EACxC;AAAA,EACA,QAAQ,MAAiB;AAtB3B;AAuBI,eAAK,YAAL,mBAAc,KAAK,KAAK,OAAO,GAAG,GAAG;AAAA,EACvC;AAAA,EACA,OAAO,MAAiB;AAzB1B;AA0BI,eAAK,YAAL,mBAAc,IAAI,KAAK,OAAO,GAAG,GAAG;AAAA,EACtC;AAAA,EACA,QAAQ,MAAiB;AA5B3B;AA6BI,eAAK,YAAL,mBAAc,KAAK,KAAK,OAAO,GAAG,GAAG;AAAA,EACvC;AAAA,EAEQ,SAAS;AAhCnB;AAiCI,WAAO,KAAI,UAAK,QAAL,6BAAY,IAAI,gBAAgB,CAAC,CAAC;AAAA,EAC/C;AACF;;;ACrBO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,SAAM,KAAN;AALU,SAAAA;AAAA,GAAA;AAQL,IAAM,kBAAkB,CAAC,aAAuB;AAEhD,IAAM,gBAAN,MAAsC;AAAA,EAC3C,YAAqB,QAAkB,cAAe;AAAjC;AAAA,EAAkC;AAAA,EAEvD,IAAI,QAAQ;AACV,WAAO,KAAK,SAAS,gBAAiB,QAAQ,QAAQ;AAAA,EACxD;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,KAAK,SAAS,gBAAiB,QAAQ,QAAQ;AAAA,EACxD;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS,eAAgB,QAAQ,OAAO;AAAA,EACtD;AAAA,EAEA,IAAI,MAAM;AACR,WAAO,KAAK,SAAS,cAAe,QAAQ,MAAM;AAAA,EACpD;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS,eAAgB,QAAQ,OAAO;AAAA,EACtD;AACF;","names":["LogLevel"]}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@xylabs/error": "~3.0.
|
|
14
|
+
"@xylabs/error": "~3.0.10"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@xylabs/ts-scripts-yarn3": "^3.5.0",
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
"esm"
|
|
69
69
|
],
|
|
70
70
|
"sideEffects": false,
|
|
71
|
-
"version": "3.0.
|
|
71
|
+
"version": "3.0.10",
|
|
72
72
|
"type": "module"
|
|
73
73
|
}
|
package/src/IdLogger.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getFunctionName
|
|
1
|
+
import { getFunctionName } from './getFunctionName'
|
|
2
|
+
import { Logger } from './Logger'
|
|
2
3
|
|
|
3
4
|
export class IdLogger implements Logger {
|
|
4
5
|
private _id?: () => string
|
|
@@ -13,27 +14,23 @@ export class IdLogger implements Logger {
|
|
|
13
14
|
this._id = () => id
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
debug(
|
|
17
|
-
this._logger?.debug(this.
|
|
17
|
+
debug(...data: unknown[]) {
|
|
18
|
+
this._logger?.debug(this.prefix(), ...data)
|
|
18
19
|
}
|
|
19
|
-
error(
|
|
20
|
-
this._logger?.error(this.
|
|
20
|
+
error(...data: unknown[]) {
|
|
21
|
+
this._logger?.error(this.prefix(), ...data)
|
|
21
22
|
}
|
|
22
|
-
info(
|
|
23
|
-
this._logger?.info(this.
|
|
23
|
+
info(...data: unknown[]) {
|
|
24
|
+
this._logger?.info(this.prefix(), ...data)
|
|
24
25
|
}
|
|
25
|
-
log(
|
|
26
|
-
this._logger?.log(this.
|
|
26
|
+
log(...data: unknown[]) {
|
|
27
|
+
this._logger?.log(this.prefix(), ...data)
|
|
27
28
|
}
|
|
28
|
-
warn(
|
|
29
|
-
this._logger?.warn(this.
|
|
29
|
+
warn(...data: unknown[]) {
|
|
30
|
+
this._logger?.warn(this.prefix(), ...data)
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
private
|
|
33
|
-
return
|
|
34
|
-
typeof message === 'string' ? message
|
|
35
|
-
: typeof message === 'object' ? JSON.stringify(message, null, 2)
|
|
36
|
-
: `${message}`
|
|
37
|
-
}`
|
|
33
|
+
private prefix() {
|
|
34
|
+
return `[${this._id?.()}|${getFunctionName(4)}]`
|
|
38
35
|
}
|
|
39
36
|
}
|
package/src/Logger.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type LogFunction = (message?: unknown) => void
|
|
1
|
+
export type LogFunction = (...data: unknown[]) => void
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Interface to handle overlap between Winston &
|
|
@@ -47,24 +45,3 @@ export class ConsoleLogger implements Logger {
|
|
|
47
45
|
return this.level >= LogLevel.warn ? console.warn : NoOpLogFunction
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
|
-
export const getFunctionName = (depth = 2) => {
|
|
51
|
-
try {
|
|
52
|
-
throw new Error('Getting function name')
|
|
53
|
-
} catch (ex) {
|
|
54
|
-
return handleError(ex, (error) => {
|
|
55
|
-
let newIndex: number | undefined
|
|
56
|
-
const stackParts = error.stack?.split('\n')[depth].split(' ')
|
|
57
|
-
const funcName =
|
|
58
|
-
stackParts?.find((item, index) => {
|
|
59
|
-
if (item.length > 0 && item !== 'at') {
|
|
60
|
-
//check if constructor
|
|
61
|
-
if (item === 'new') {
|
|
62
|
-
newIndex = index
|
|
63
|
-
}
|
|
64
|
-
return item
|
|
65
|
-
}
|
|
66
|
-
}) ?? '<unknown>'
|
|
67
|
-
return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { handleError } from '@xylabs/error'
|
|
2
|
+
|
|
3
|
+
export const getFunctionName = (depth = 2) => {
|
|
4
|
+
try {
|
|
5
|
+
throw new Error('Getting function name')
|
|
6
|
+
} catch (ex) {
|
|
7
|
+
return handleError(ex, (error) => {
|
|
8
|
+
let newIndex: number | undefined
|
|
9
|
+
const stackParts = error.stack?.split('\n')[depth].split(' ')
|
|
10
|
+
const funcName =
|
|
11
|
+
stackParts?.find((item, index) => {
|
|
12
|
+
if (item.length > 0 && item !== 'at') {
|
|
13
|
+
//check if constructor
|
|
14
|
+
if (item === 'new') {
|
|
15
|
+
newIndex = index
|
|
16
|
+
}
|
|
17
|
+
return item
|
|
18
|
+
}
|
|
19
|
+
}) ?? '<unknown>'
|
|
20
|
+
return newIndex ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.ts
CHANGED