@xylabs/logger 2.13.22 → 2.13.24
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/Logger.d.cts +32 -0
- package/dist/browser/Logger.d.cts.map +1 -1
- package/dist/browser/Logger.d.mts +32 -0
- package/dist/browser/Logger.d.mts.map +1 -1
- package/dist/browser/Logger.d.ts +32 -0
- package/dist/browser/Logger.d.ts.map +1 -1
- package/dist/browser/index.cjs +32 -0
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +32 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Logger.d.cts +32 -0
- package/dist/node/Logger.d.cts.map +1 -1
- package/dist/node/Logger.d.mts +32 -0
- package/dist/node/Logger.d.mts.map +1 -1
- package/dist/node/Logger.d.ts +32 -0
- package/dist/node/Logger.d.ts.map +1 -1
- package/dist/node/index.cjs +35 -0
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +32 -0
- package/dist/node/index.js.map +1 -1
- package/package.json +4 -4
- package/src/Logger.ts +33 -0
|
@@ -10,5 +10,37 @@ export interface Logger {
|
|
|
10
10
|
log: LogFunction;
|
|
11
11
|
warn: LogFunction;
|
|
12
12
|
}
|
|
13
|
+
export declare enum LogLevel {
|
|
14
|
+
error = 1,
|
|
15
|
+
warn = 2,
|
|
16
|
+
info = 3,
|
|
17
|
+
debug = 4,
|
|
18
|
+
log = 5
|
|
19
|
+
}
|
|
20
|
+
export declare const NoOpLogFunction: (_message?: unknown) => undefined;
|
|
21
|
+
export declare class ConsoleLogger implements Logger {
|
|
22
|
+
readonly level: LogLevel;
|
|
23
|
+
constructor(level?: LogLevel);
|
|
24
|
+
get debug(): {
|
|
25
|
+
(...data: any[]): void;
|
|
26
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
27
|
+
};
|
|
28
|
+
get error(): {
|
|
29
|
+
(...data: any[]): void;
|
|
30
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
31
|
+
};
|
|
32
|
+
get info(): {
|
|
33
|
+
(...data: any[]): void;
|
|
34
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
35
|
+
};
|
|
36
|
+
get log(): {
|
|
37
|
+
(...data: any[]): void;
|
|
38
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
39
|
+
};
|
|
40
|
+
get warn(): {
|
|
41
|
+
(...data: any[]): void;
|
|
42
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
13
45
|
export declare const getFunctionName: (depth?: number) => string;
|
|
14
46
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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;AACD,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
@@ -10,5 +10,37 @@ export interface Logger {
|
|
|
10
10
|
log: LogFunction;
|
|
11
11
|
warn: LogFunction;
|
|
12
12
|
}
|
|
13
|
+
export declare enum LogLevel {
|
|
14
|
+
error = 1,
|
|
15
|
+
warn = 2,
|
|
16
|
+
info = 3,
|
|
17
|
+
debug = 4,
|
|
18
|
+
log = 5
|
|
19
|
+
}
|
|
20
|
+
export declare const NoOpLogFunction: (_message?: unknown) => undefined;
|
|
21
|
+
export declare class ConsoleLogger implements Logger {
|
|
22
|
+
readonly level: LogLevel;
|
|
23
|
+
constructor(level?: LogLevel);
|
|
24
|
+
get debug(): {
|
|
25
|
+
(...data: any[]): void;
|
|
26
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
27
|
+
};
|
|
28
|
+
get error(): {
|
|
29
|
+
(...data: any[]): void;
|
|
30
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
31
|
+
};
|
|
32
|
+
get info(): {
|
|
33
|
+
(...data: any[]): void;
|
|
34
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
35
|
+
};
|
|
36
|
+
get log(): {
|
|
37
|
+
(...data: any[]): void;
|
|
38
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
39
|
+
};
|
|
40
|
+
get warn(): {
|
|
41
|
+
(...data: any[]): void;
|
|
42
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
13
45
|
export declare const getFunctionName: (depth?: number) => string;
|
|
14
46
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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;AACD,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
package/dist/browser/Logger.d.ts
CHANGED
|
@@ -10,5 +10,37 @@ export interface Logger {
|
|
|
10
10
|
log: LogFunction;
|
|
11
11
|
warn: LogFunction;
|
|
12
12
|
}
|
|
13
|
+
export declare enum LogLevel {
|
|
14
|
+
error = 1,
|
|
15
|
+
warn = 2,
|
|
16
|
+
info = 3,
|
|
17
|
+
debug = 4,
|
|
18
|
+
log = 5
|
|
19
|
+
}
|
|
20
|
+
export declare const NoOpLogFunction: (_message?: unknown) => undefined;
|
|
21
|
+
export declare class ConsoleLogger implements Logger {
|
|
22
|
+
readonly level: LogLevel;
|
|
23
|
+
constructor(level?: LogLevel);
|
|
24
|
+
get debug(): {
|
|
25
|
+
(...data: any[]): void;
|
|
26
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
27
|
+
};
|
|
28
|
+
get error(): {
|
|
29
|
+
(...data: any[]): void;
|
|
30
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
31
|
+
};
|
|
32
|
+
get info(): {
|
|
33
|
+
(...data: any[]): void;
|
|
34
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
35
|
+
};
|
|
36
|
+
get log(): {
|
|
37
|
+
(...data: any[]): void;
|
|
38
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
39
|
+
};
|
|
40
|
+
get warn(): {
|
|
41
|
+
(...data: any[]): void;
|
|
42
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
13
45
|
export declare const getFunctionName: (depth?: number) => string;
|
|
14
46
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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;AACD,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -20,13 +20,45 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
ConsoleLogger: () => ConsoleLogger,
|
|
23
24
|
IdLogger: () => IdLogger,
|
|
25
|
+
LogLevel: () => LogLevel,
|
|
26
|
+
NoOpLogFunction: () => NoOpLogFunction,
|
|
24
27
|
getFunctionName: () => getFunctionName
|
|
25
28
|
});
|
|
26
29
|
module.exports = __toCommonJS(src_exports);
|
|
27
30
|
|
|
28
31
|
// src/Logger.ts
|
|
29
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
|
+
};
|
|
30
62
|
var getFunctionName = (depth = 2) => {
|
|
31
63
|
try {
|
|
32
64
|
throw new Error("Getting function name");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Logger.ts","../../src/IdLogger.ts"],"sourcesContent":["export * from './IdLogger'\nexport * from './Logger'\n","import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: 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 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, 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(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message : typeof message === 'object' ? JSON.stringify(message, null, 2) : `${message}`\n }`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4B;AAgBrB,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;;;
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Logger.ts","../../src/IdLogger.ts"],"sourcesContent":["export * from './IdLogger'\nexport * from './Logger'\n","import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: 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}\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, 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(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message : typeof message === 'object' ? JSON.stringify(message, null, 2) : `${message}`\n }`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4B;AAgBrB,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,E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,CAAC;AAAA,EAChE;AAAA,EACA,KAAK,SAAmB;AACtB,SAAK,SAAS,KAAK,KAAK,SAAS,SAAS,gBAAgB,CAAC,CAAC,CAAC;AAAA,EAC/D;AAAA,EACA,IAAI,SAAmB;AACrB,SAAK,SAAS,IAAI,KAAK,SAAS,SAAS,gBAAgB,CAAC,CAAC,CAAC;AAAA,EAC9D;AAAA,EACA,KAAK,SAAmB;AACtB,SAAK,SAAS,KAAK,KAAK,SAAS,SAAS,gBAAgB,CAAC,CAAC,CAAC;AAAA,EAC/D;AAAA,EAEQ,SAAS,SAAmB,KAAc;AAChD,WAAO,GAAG,GAAG,IAAI,KAAK,MAAM,IAAI,KAAK,GAAG,OAAO,EAAE,GAC/C,OAAO,YAAY,WAAW,UAAU,OAAO,YAAY,WAAW,KAAK,UAAU,SAAS,MAAM,CAAC,IAAI,GAAG,OAAO,EACrH;AAAA,EACF;AACF;","names":["LogLevel"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
// src/Logger.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
|
+
};
|
|
3
32
|
var getFunctionName = (depth = 2) => {
|
|
4
33
|
try {
|
|
5
34
|
throw new Error("Getting function name");
|
|
@@ -51,7 +80,10 @@ var IdLogger = class {
|
|
|
51
80
|
}
|
|
52
81
|
};
|
|
53
82
|
export {
|
|
83
|
+
ConsoleLogger,
|
|
54
84
|
IdLogger,
|
|
85
|
+
LogLevel,
|
|
86
|
+
NoOpLogFunction,
|
|
55
87
|
getFunctionName
|
|
56
88
|
};
|
|
57
89
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Logger.ts","../../src/IdLogger.ts"],"sourcesContent":["import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: 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 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, 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(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message : typeof message === 'object' ? JSON.stringify(message, null, 2) : `${message}`\n }`\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAgBrB,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;;;
|
|
1
|
+
{"version":3,"sources":["../../src/Logger.ts","../../src/IdLogger.ts"],"sourcesContent":["import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: 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}\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, 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(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message : typeof message === 'object' ? JSON.stringify(message, null, 2) : `${message}`\n }`\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAgBrB,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;AACO,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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
12
|
}
|
|
13
|
+
export declare enum LogLevel {
|
|
14
|
+
error = 1,
|
|
15
|
+
warn = 2,
|
|
16
|
+
info = 3,
|
|
17
|
+
debug = 4,
|
|
18
|
+
log = 5
|
|
19
|
+
}
|
|
20
|
+
export declare const NoOpLogFunction: (_message?: unknown) => undefined;
|
|
21
|
+
export declare class ConsoleLogger implements Logger {
|
|
22
|
+
readonly level: LogLevel;
|
|
23
|
+
constructor(level?: LogLevel);
|
|
24
|
+
get debug(): {
|
|
25
|
+
(...data: any[]): void;
|
|
26
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
27
|
+
};
|
|
28
|
+
get error(): {
|
|
29
|
+
(...data: any[]): void;
|
|
30
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
31
|
+
};
|
|
32
|
+
get info(): {
|
|
33
|
+
(...data: any[]): void;
|
|
34
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
35
|
+
};
|
|
36
|
+
get log(): {
|
|
37
|
+
(...data: any[]): void;
|
|
38
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
39
|
+
};
|
|
40
|
+
get warn(): {
|
|
41
|
+
(...data: any[]): void;
|
|
42
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
13
45
|
export declare const getFunctionName: (depth?: number) => string;
|
|
14
46
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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;AACD,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
package/dist/node/Logger.d.mts
CHANGED
|
@@ -10,5 +10,37 @@ export interface Logger {
|
|
|
10
10
|
log: LogFunction;
|
|
11
11
|
warn: LogFunction;
|
|
12
12
|
}
|
|
13
|
+
export declare enum LogLevel {
|
|
14
|
+
error = 1,
|
|
15
|
+
warn = 2,
|
|
16
|
+
info = 3,
|
|
17
|
+
debug = 4,
|
|
18
|
+
log = 5
|
|
19
|
+
}
|
|
20
|
+
export declare const NoOpLogFunction: (_message?: unknown) => undefined;
|
|
21
|
+
export declare class ConsoleLogger implements Logger {
|
|
22
|
+
readonly level: LogLevel;
|
|
23
|
+
constructor(level?: LogLevel);
|
|
24
|
+
get debug(): {
|
|
25
|
+
(...data: any[]): void;
|
|
26
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
27
|
+
};
|
|
28
|
+
get error(): {
|
|
29
|
+
(...data: any[]): void;
|
|
30
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
31
|
+
};
|
|
32
|
+
get info(): {
|
|
33
|
+
(...data: any[]): void;
|
|
34
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
35
|
+
};
|
|
36
|
+
get log(): {
|
|
37
|
+
(...data: any[]): void;
|
|
38
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
39
|
+
};
|
|
40
|
+
get warn(): {
|
|
41
|
+
(...data: any[]): void;
|
|
42
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
13
45
|
export declare const getFunctionName: (depth?: number) => string;
|
|
14
46
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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;AACD,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
package/dist/node/Logger.d.ts
CHANGED
|
@@ -10,5 +10,37 @@ export interface Logger {
|
|
|
10
10
|
log: LogFunction;
|
|
11
11
|
warn: LogFunction;
|
|
12
12
|
}
|
|
13
|
+
export declare enum LogLevel {
|
|
14
|
+
error = 1,
|
|
15
|
+
warn = 2,
|
|
16
|
+
info = 3,
|
|
17
|
+
debug = 4,
|
|
18
|
+
log = 5
|
|
19
|
+
}
|
|
20
|
+
export declare const NoOpLogFunction: (_message?: unknown) => undefined;
|
|
21
|
+
export declare class ConsoleLogger implements Logger {
|
|
22
|
+
readonly level: LogLevel;
|
|
23
|
+
constructor(level?: LogLevel);
|
|
24
|
+
get debug(): {
|
|
25
|
+
(...data: any[]): void;
|
|
26
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
27
|
+
};
|
|
28
|
+
get error(): {
|
|
29
|
+
(...data: any[]): void;
|
|
30
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
31
|
+
};
|
|
32
|
+
get info(): {
|
|
33
|
+
(...data: any[]): void;
|
|
34
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
35
|
+
};
|
|
36
|
+
get log(): {
|
|
37
|
+
(...data: any[]): void;
|
|
38
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
39
|
+
};
|
|
40
|
+
get warn(): {
|
|
41
|
+
(...data: any[]): void;
|
|
42
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
13
45
|
export declare const getFunctionName: (depth?: number) => string;
|
|
14
46
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAErD;;;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;AACD,eAAO,MAAM,eAAe,4BAoB3B,CAAA"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -20,13 +20,45 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
ConsoleLogger: () => ConsoleLogger,
|
|
23
24
|
IdLogger: () => IdLogger,
|
|
25
|
+
LogLevel: () => LogLevel,
|
|
26
|
+
NoOpLogFunction: () => NoOpLogFunction,
|
|
24
27
|
getFunctionName: () => getFunctionName
|
|
25
28
|
});
|
|
26
29
|
module.exports = __toCommonJS(src_exports);
|
|
27
30
|
|
|
28
31
|
// src/Logger.ts
|
|
29
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
|
+
};
|
|
30
62
|
var getFunctionName = (depth = 2) => {
|
|
31
63
|
try {
|
|
32
64
|
throw new Error("Getting function name");
|
|
@@ -85,7 +117,10 @@ var IdLogger = class {
|
|
|
85
117
|
};
|
|
86
118
|
// Annotate the CommonJS export names for ESM import in node:
|
|
87
119
|
0 && (module.exports = {
|
|
120
|
+
ConsoleLogger,
|
|
88
121
|
IdLogger,
|
|
122
|
+
LogLevel,
|
|
123
|
+
NoOpLogFunction,
|
|
89
124
|
getFunctionName
|
|
90
125
|
});
|
|
91
126
|
//# sourceMappingURL=index.cjs.map
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Logger.ts","../../src/IdLogger.ts"],"sourcesContent":["export * from './IdLogger'\nexport * from './Logger'\n","import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: 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 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, 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(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message : typeof message === 'object' ? JSON.stringify(message, null, 2) : `${message}`\n }`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4B;AAgBrB,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC,SAAS,IAAI;AACX,eAAO,0BAAY,IAAI,CAAC,UAAU;
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Logger.ts","../../src/IdLogger.ts"],"sourcesContent":["export * from './IdLogger'\nexport * from './Logger'\n","import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: 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}\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, 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(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message : typeof message === 'object' ? JSON.stringify(message, null, 2) : `${message}`\n }`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;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E,CAAC;AAAA,EACH;AACF;;;ACnEO,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,MAAM,SAAmB;AAf3B;AAgBI,eAAK,YAAL,mBAAc,MAAM,KAAK,SAAS,SAAS,gBAAgB,CAAC,CAAC;AAAA,EAC/D;AAAA,EACA,MAAM,SAAmB;AAlB3B;AAmBI,eAAK,YAAL,mBAAc,MAAM,KAAK,SAAS,SAAS,gBAAgB,CAAC,CAAC;AAAA,EAC/D;AAAA,EACA,KAAK,SAAmB;AArB1B;AAsBI,eAAK,YAAL,mBAAc,KAAK,KAAK,SAAS,SAAS,gBAAgB,CAAC,CAAC;AAAA,EAC9D;AAAA,EACA,IAAI,SAAmB;AAxBzB;AAyBI,eAAK,YAAL,mBAAc,IAAI,KAAK,SAAS,SAAS,gBAAgB,CAAC,CAAC;AAAA,EAC7D;AAAA,EACA,KAAK,SAAmB;AA3B1B;AA4BI,eAAK,YAAL,mBAAc,KAAK,KAAK,SAAS,SAAS,gBAAgB,CAAC,CAAC;AAAA,EAC9D;AAAA,EAEQ,SAAS,SAAmB,KAAc;AAChD,WAAO,GAAG,GAAG,IAAI,KAAK,MAAM,IAAI,KAAK,GAAG,OAAO,EAAE,GAC/C,OAAO,YAAY,WAAW,UAAU,OAAO,YAAY,WAAW,KAAK,UAAU,SAAS,MAAM,CAAC,IAAI,GAAG,OAAO,EACrH;AAAA,EACF;AACF;","names":["LogLevel"]}
|
package/dist/node/index.js
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
// src/Logger.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
|
+
};
|
|
3
32
|
var getFunctionName = (depth = 2) => {
|
|
4
33
|
try {
|
|
5
34
|
throw new Error("Getting function name");
|
|
@@ -57,7 +86,10 @@ var IdLogger = class {
|
|
|
57
86
|
}
|
|
58
87
|
};
|
|
59
88
|
export {
|
|
89
|
+
ConsoleLogger,
|
|
60
90
|
IdLogger,
|
|
91
|
+
LogLevel,
|
|
92
|
+
NoOpLogFunction,
|
|
61
93
|
getFunctionName
|
|
62
94
|
};
|
|
63
95
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Logger.ts","../../src/IdLogger.ts"],"sourcesContent":["import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: 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 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, 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(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message : typeof message === 'object' ? JSON.stringify(message, null, 2) : `${message}`\n }`\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAgBrB,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC,SAAS,IAAI;AACX,WAAO,YAAY,IAAI,CAAC,UAAU;
|
|
1
|
+
{"version":3,"sources":["../../src/Logger.ts","../../src/IdLogger.ts"],"sourcesContent":["import { handleError } from '@xylabs/error'\n\nexport type LogFunction = (message?: 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}\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, 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(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message : typeof message === 'object' ? JSON.stringify(message, null, 2) : `${message}`\n }`\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAgBrB,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;AACO,IAAM,kBAAkB,CAAC,QAAQ,MAAM;AAC5C,MAAI;AACF,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC,SAAS,IAAI;AACX,WAAO,YAAY,IAAI,CAAC,UAAU;AArDtC;AAsDM,UAAI;AACJ,YAAM,cAAa,WAAM,UAAN,mBAAa,MAAM,MAAM,OAAO,MAAM;AACzD,YAAM,YACJ,yCA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AO,EACrH;AAAA,EACF;AACF;","names":["LogLevel"]}
|
package/package.json
CHANGED
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
},
|
|
12
12
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@xylabs/error": "~2.13.
|
|
14
|
+
"@xylabs/error": "~2.13.24"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@xylabs/ts-scripts-yarn3": "^3.2.
|
|
18
|
-
"@xylabs/tsconfig": "^3.2.
|
|
17
|
+
"@xylabs/ts-scripts-yarn3": "^3.2.41",
|
|
18
|
+
"@xylabs/tsconfig": "^3.2.41",
|
|
19
19
|
"typescript": "^5.3.3"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
"esm"
|
|
69
69
|
],
|
|
70
70
|
"sideEffects": false,
|
|
71
|
-
"version": "2.13.
|
|
71
|
+
"version": "2.13.24",
|
|
72
72
|
"type": "module"
|
|
73
73
|
}
|
package/src/Logger.ts
CHANGED
|
@@ -14,6 +14,39 @@ export interface Logger {
|
|
|
14
14
|
warn: LogFunction
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export enum LogLevel {
|
|
18
|
+
error = 1,
|
|
19
|
+
warn = 2,
|
|
20
|
+
info = 3,
|
|
21
|
+
debug = 4,
|
|
22
|
+
log = 5,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const NoOpLogFunction = (_message?: unknown) => void {}
|
|
26
|
+
|
|
27
|
+
export class ConsoleLogger implements Logger {
|
|
28
|
+
constructor(readonly level: LogLevel = LogLevel.warn) {}
|
|
29
|
+
|
|
30
|
+
get debug() {
|
|
31
|
+
return this.level <= LogLevel.debug ? console.debug : NoOpLogFunction
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get error() {
|
|
35
|
+
return this.level <= LogLevel.error ? console.error : NoOpLogFunction
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get info() {
|
|
39
|
+
return this.level <= LogLevel.info ? console.info : NoOpLogFunction
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get log() {
|
|
43
|
+
return this.level <= LogLevel.log ? console.log : NoOpLogFunction
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get warn() {
|
|
47
|
+
return this.level <= LogLevel.warn ? console.warn : NoOpLogFunction
|
|
48
|
+
}
|
|
49
|
+
}
|
|
17
50
|
export const getFunctionName = (depth = 2) => {
|
|
18
51
|
try {
|
|
19
52
|
throw new Error('Getting function name')
|