@dynamic-labs/logger 0.18.100-viem.0 → 0.19.0-alpha.1

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/CHANGELOG.md CHANGED
@@ -1,59 +1,36 @@
1
1
 
2
- ## [0.18.100-viem.0](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-beta.29...v0.18.100-viem.0) (2023-08-04)
2
+ ## [0.19.0-alpha.1](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.0...v0.19.0-alpha.1) (2023-08-10)
3
3
 
4
- ### Bug Fixes
5
-
6
- * add improves to wallet events handling
7
-
8
- ## [0.18.0-beta.29](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-beta.28...v0.18.0-beta.29) (2023-08-03)
9
-
10
-
11
- ### ⚠ BREAKING CHANGES
12
-
13
- * remove deprecated multiwallet prop (#2821)
14
-
15
- ### Bug Fixes
16
-
17
- * array of dynamicWagmiSettings not being sent, must be turned into object ([#2837](https://github.com/dynamic-labs/DynamicAuth/issues/2837)) ([fc5051d](https://github.com/dynamic-labs/DynamicAuth/commit/fc5051d3ce4c5e28d54a74cc9d74424748b52df9)), closes [#2835](https://github.com/dynamic-labs/DynamicAuth/issues/2835)
18
- * change network modal doesn't pop on secondary wallet, when primaryWallet was disconnected ([#2831](https://github.com/dynamic-labs/DynamicAuth/issues/2831)) ([4a78cc8](https://github.com/dynamic-labs/DynamicAuth/commit/4a78cc8c9004e6716fa9e35d8572c57bfd8bdc22))
19
- * connectSuccess callback is not being called when connecting new wallet after unlink ([#2829](https://github.com/dynamic-labs/DynamicAuth/issues/2829)) ([37795e5](https://github.com/dynamic-labs/DynamicAuth/commit/37795e5304d65766968ae6168d329b899c0afdfa))
20
- * **wcv2:** simulate chain change event in switchNetwork ([#2827](https://github.com/dynamic-labs/DynamicAuth/issues/2827)) ([98cff76](https://github.com/dynamic-labs/DynamicAuth/commit/98cff7687112ddbf2971fa4e42cc959f5be62014)), closes [#2809](https://github.com/dynamic-labs/DynamicAuth/issues/2809)
21
- * wrong wallet list is showing after disconnecting and network change ([#2832](https://github.com/dynamic-labs/DynamicAuth/issues/2832)) ([b7af548](https://github.com/dynamic-labs/DynamicAuth/commit/b7af5480a0f05b851cf9accb3ab0870fd2836a92))
22
-
23
-
24
- * remove deprecated multiwallet prop ([#2821](https://github.com/dynamic-labs/DynamicAuth/issues/2821)) ([d95173d](https://github.com/dynamic-labs/DynamicAuth/commit/d95173de890104b1b94b612976682c9d86ec4b17))
25
-
26
- ## [0.18.0-beta.28](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.27...v0.18.0-beta.28) (2023-08-03)
27
-
28
-
29
- ### Bug Fixes
30
-
31
- * gracefully handle walletbook fallbacks ([#2812](https://github.com/dynamic-labs/DynamicAuth/issues/2812)) ([#2822](https://github.com/dynamic-labs/DynamicAuth/issues/2822)) ([8e737d6](https://github.com/dynamic-labs/DynamicAuth/commit/8e737d602d64fa2414ba136799b8878e975a40a2))
32
-
33
- ## [0.18.0-RC.27](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.26...v0.18.0-RC.27) (2023-08-03)
34
-
35
- ### Bug Fixes
36
-
37
- * fixes circular dependency issues on usePromise
38
-
39
- ## [0.18.0-RC.26](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.24...v0.18.0-RC.26) (2023-08-02)
40
-
41
-
42
- ### ⚠ BREAKING CHANGES
43
-
44
- * displayTermsOfService prop set to false breaks message verfication (#2751)
45
4
 
46
5
  ### Features
47
6
 
48
- * send wagmi settings from wagmi connector ([#2791](https://github.com/dynamic-labs/DynamicAuth/issues/2791)) ([#2800](https://github.com/dynamic-labs/DynamicAuth/issues/2800)) ([5b65605](https://github.com/dynamic-labs/DynamicAuth/commit/5b656059361a48de57e01ad2dd81de0bc9b2c7e8))
7
+ * cleaning up email input field - delete continue button ([#2833](https://github.com/dynamic-labs/DynamicAuth/issues/2833)) ([baa399e](https://github.com/dynamic-labs/DynamicAuth/commit/baa399e387bce9570a7e7774d68dc3c92f86be1b))
8
+ * disable social buttons after provider is selected ([#2875](https://github.com/dynamic-labs/DynamicAuth/issues/2875)) ([6296ce1](https://github.com/dynamic-labs/DynamicAuth/commit/6296ce13062a8589cf6fb4741957dc9bf84552a2))
9
+ * **GVTY-65:** Allow Merging accounts when duplicated email in KYC step ([#2772](https://github.com/dynamic-labs/DynamicAuth/issues/2772)) ([8efb6ae](https://github.com/dynamic-labs/DynamicAuth/commit/8efb6aecc9445ef1798a5c6358eac27b16f661b6))
10
+ * hide network from nav if hideNetworkInDynamicWidget setting is true ([#2842](https://github.com/dynamic-labs/DynamicAuth/issues/2842)) ([f3dc9ba](https://github.com/dynamic-labs/DynamicAuth/commit/f3dc9ba987781d5d0540336f351bb9f148400eac))
11
+ * show email submit button on focus ([#2860](https://github.com/dynamic-labs/DynamicAuth/issues/2860)) ([87d8ae0](https://github.com/dynamic-labs/DynamicAuth/commit/87d8ae0806425a25835efda5f9b9abc58e5de18e))
49
12
 
50
13
 
51
14
  ### Bug Fixes
52
15
 
53
- * always call onBeforeConnectSuccess callback when wallet state changes ([#2786](https://github.com/dynamic-labs/DynamicAuth/issues/2786)) ([e2eaef3](https://github.com/dynamic-labs/DynamicAuth/commit/e2eaef3da1f80cdc7dc21e902e9c033e581242d2))
54
- * displayTermsOfService prop set to false breaks message verfication ([#2751](https://github.com/dynamic-labs/DynamicAuth/issues/2751)) ([6433732](https://github.com/dynamic-labs/DynamicAuth/commit/6433732fac87d641f2475d19ef743ac31130274f))
55
- * ensure auto-redirect back to dapp after message signing ([#2783](https://github.com/dynamic-labs/DynamicAuth/issues/2783)) ([dba4664](https://github.com/dynamic-labs/DynamicAuth/commit/dba466473ecc2afd808cdae0fd9023d38676b01f))
56
- * use css.supports only when available ([#2802](https://github.com/dynamic-labs/DynamicAuth/issues/2802)) ([7651898](https://github.com/dynamic-labs/DynamicAuth/commit/76518982a97e728ab65549f37f55b537eed4e890))
16
+ * account already exist message not displaying automatically ([#2896](https://github.com/dynamic-labs/DynamicAuth/issues/2896)) ([ba56c93](https://github.com/dynamic-labs/DynamicAuth/commit/ba56c936546428b0a1111ab5ef6e8d0d9a463bb5))
17
+ * array of dynamicWagmiSettings not being sent, must be turned into object ([#2835](https://github.com/dynamic-labs/DynamicAuth/issues/2835)) ([092c45a](https://github.com/dynamic-labs/DynamicAuth/commit/092c45afd3676fbd7c3d28f51818470de7f95768))
18
+ * change network modal doesn't pop on secondary wallet, when primaryWallet was disconnected ([#2817](https://github.com/dynamic-labs/DynamicAuth/issues/2817)) ([b68c156](https://github.com/dynamic-labs/DynamicAuth/commit/b68c1565f936d2f4275b104a0881ba5720101abd))
19
+ * connectSuccess callback is not being called when connecting new wallet after unlink ([#2814](https://github.com/dynamic-labs/DynamicAuth/issues/2814)) ([d5b34d8](https://github.com/dynamic-labs/DynamicAuth/commit/d5b34d8a073436ce39280766608578fd97567fac))
20
+ * css variables are being ignored for ConnectButton component ([#2869](https://github.com/dynamic-labs/DynamicAuth/issues/2869)) ([a54fb46](https://github.com/dynamic-labs/DynamicAuth/commit/a54fb46648758001450a33e6d86cf04765507701))
21
+ * css variables for the ConnectButton are being ignored ([#2856](https://github.com/dynamic-labs/DynamicAuth/issues/2856)) ([65a342f](https://github.com/dynamic-labs/DynamicAuth/commit/65a342f828b6a16f714fc6b6e2066e1b742b2c0a))
22
+ * don't let user update email if it's linked to an embedded wallet ([#2883](https://github.com/dynamic-labs/DynamicAuth/issues/2883)) ([99aa303](https://github.com/dynamic-labs/DynamicAuth/commit/99aa3033e62c0dee14657cb811db8d5b3597f7de))
23
+ * **GVTY-150:** blocto pop up to sign after disconnect ([#2854](https://github.com/dynamic-labs/DynamicAuth/issues/2854)) ([df5481b](https://github.com/dynamic-labs/DynamicAuth/commit/df5481b2d5438848ad96cdee402f40b520bead08))
24
+ * **GVTY-155:** update to the new design ([#2889](https://github.com/dynamic-labs/DynamicAuth/issues/2889)) ([31f7f54](https://github.com/dynamic-labs/DynamicAuth/commit/31f7f54444c623fe7d5bcf8a42f94ee22eedc3e1))
25
+ * **GVTY-159:** email update view not showing email used error ([#2887](https://github.com/dynamic-labs/DynamicAuth/issues/2887)) ([bd40e4c](https://github.com/dynamic-labs/DynamicAuth/commit/bd40e4c77cda42752d44e42b98bfcea4cfd77a80))
26
+ * **OTPOverviewView:** enable close only on close button click ([#2877](https://github.com/dynamic-labs/DynamicAuth/issues/2877)) ([2be23e7](https://github.com/dynamic-labs/DynamicAuth/commit/2be23e7ddefe67c971d863ad9069ac5b8a74f4e5))
27
+ * **transaction:** improve gas estimate in transaction confirmation ([#2767](https://github.com/dynamic-labs/DynamicAuth/issues/2767)) ([7180ae5](https://github.com/dynamic-labs/DynamicAuth/commit/7180ae50559f924ae9769b2b8d87eadc6604c754))
28
+ * use findSocialIcon instead getSocialIcon to avoid render errors ([#2834](https://github.com/dynamic-labs/DynamicAuth/issues/2834)) ([2c57f98](https://github.com/dynamic-labs/DynamicAuth/commit/2c57f98fd5c461ae4acbe2836f719ebe18bc21fc))
29
+ * **useWalletConnectorEvent:** ensure connector is initialized ([#2849](https://github.com/dynamic-labs/DynamicAuth/issues/2849)) ([9137131](https://github.com/dynamic-labs/DynamicAuth/commit/913713166af8a6e6cc15a8e362e57b328fc0a76f))
30
+ * **wcv2:** simulate chain change event in switchNetwork ([#2809](https://github.com/dynamic-labs/DynamicAuth/issues/2809)) ([2329b80](https://github.com/dynamic-labs/DynamicAuth/commit/2329b808f57644cebb664be536bc41e256d108d8))
31
+ * wrong wallet list is showing after disconnecting and network change ([#2815](https://github.com/dynamic-labs/DynamicAuth/issues/2815)) ([6cae101](https://github.com/dynamic-labs/DynamicAuth/commit/6cae1019f40be4ffe7ab0426aa159c652a770a82))
32
+
33
+ ## [0.19.0-alpha.0](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.25...v0.19.0-alpha.0) (2023-08-01)
57
34
 
58
35
  ## [0.18.0-RC.25](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.24...v0.18.0-RC.25) (2023-08-01)
59
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/logger",
3
- "version": "0.18.100-viem.0",
3
+ "version": "0.19.0-alpha.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
package/src/index.cjs CHANGED
@@ -2,85 +2,85 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /* eslint-disable @typescript-eslint/no-explicit-any, no-console */
6
- exports.LogLevel = void 0;
7
- (function (LogLevel) {
8
- LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
9
- LogLevel[LogLevel["INFO"] = 1] = "INFO";
10
- LogLevel[LogLevel["WARN"] = 2] = "WARN";
11
- LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
12
- LogLevel[LogLevel["MUTE"] = 99] = "MUTE";
13
- })(exports.LogLevel || (exports.LogLevel = {}));
14
- class Logger {
15
- constructor(name, level) {
16
- this.name = name;
17
- if (level === undefined && process.env['NODE_ENV'] !== 'production') {
18
- this.level = exports.LogLevel.DEBUG;
19
- }
20
- else if (level === undefined) {
21
- this.level = exports.LogLevel.WARN;
22
- }
23
- else {
24
- this.level = level;
25
- }
26
- }
27
- get logLevel() {
28
- return exports.LogLevel[this.level];
29
- }
30
- setLogLevel(level) {
31
- if (level in exports.LogLevel && typeof level === 'string') {
32
- this.level = exports.LogLevel[level];
33
- }
34
- else if (level in exports.LogLevel && typeof level === 'number') {
35
- this.level = level;
36
- }
37
- else {
38
- throw new Error(`Invalid log level: ${level}`);
39
- }
40
- }
41
- formatMessage(level, message) {
42
- if (message instanceof Error) {
43
- message = message.stack;
44
- }
45
- else if (
46
- // Handle Error-Like Objects
47
- message instanceof Object &&
48
- Object.prototype.hasOwnProperty.call(message, 'stack')) {
49
- message = message.stack;
50
- }
51
- else if (message instanceof Object) {
52
- message = JSON.stringify(message);
53
- }
54
- return `[${this.name}] [${exports.LogLevel[level]}]: ${message}`;
55
- }
56
- log(level, message, ...args) {
57
- if (level < this.level || level === exports.LogLevel.MUTE) {
58
- return;
59
- }
60
- const fmtMsg = this.formatMessage(level, message);
61
- switch (level) {
62
- case exports.LogLevel.WARN:
63
- console.warn(fmtMsg, ...args);
64
- break;
65
- case exports.LogLevel.ERROR:
66
- console.error(fmtMsg, ...args);
67
- break;
68
- default:
69
- console.log(fmtMsg, ...args);
70
- }
71
- }
72
- debug(message, ...args) {
73
- this.log(exports.LogLevel.DEBUG, message, ...args);
74
- }
75
- info(message, ...args) {
76
- this.log(exports.LogLevel.INFO, message, ...args);
77
- }
78
- warn(message, ...args) {
79
- this.log(exports.LogLevel.WARN, message, ...args);
80
- }
81
- error(message, ...args) {
82
- this.log(exports.LogLevel.ERROR, message, ...args);
83
- }
5
+ /* eslint-disable @typescript-eslint/no-explicit-any, no-console */
6
+ exports.LogLevel = void 0;
7
+ (function (LogLevel) {
8
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
9
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
10
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
11
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
12
+ LogLevel[LogLevel["MUTE"] = 99] = "MUTE";
13
+ })(exports.LogLevel || (exports.LogLevel = {}));
14
+ class Logger {
15
+ constructor(name, level) {
16
+ this.name = name;
17
+ if (level === undefined && process.env['NODE_ENV'] !== 'production') {
18
+ this.level = exports.LogLevel.DEBUG;
19
+ }
20
+ else if (level === undefined) {
21
+ this.level = exports.LogLevel.WARN;
22
+ }
23
+ else {
24
+ this.level = level;
25
+ }
26
+ }
27
+ get logLevel() {
28
+ return exports.LogLevel[this.level];
29
+ }
30
+ setLogLevel(level) {
31
+ if (level in exports.LogLevel && typeof level === 'string') {
32
+ this.level = exports.LogLevel[level];
33
+ }
34
+ else if (level in exports.LogLevel && typeof level === 'number') {
35
+ this.level = level;
36
+ }
37
+ else {
38
+ throw new Error(`Invalid log level: ${level}`);
39
+ }
40
+ }
41
+ formatMessage(level, message) {
42
+ if (message instanceof Error) {
43
+ message = message.stack;
44
+ }
45
+ else if (
46
+ // Handle Error-Like Objects
47
+ message instanceof Object &&
48
+ Object.prototype.hasOwnProperty.call(message, 'stack')) {
49
+ message = message.stack;
50
+ }
51
+ else if (message instanceof Object) {
52
+ message = JSON.stringify(message);
53
+ }
54
+ return `[${this.name}] [${exports.LogLevel[level]}]: ${message}`;
55
+ }
56
+ log(level, message, ...args) {
57
+ if (level < this.level || level === exports.LogLevel.MUTE) {
58
+ return;
59
+ }
60
+ const fmtMsg = this.formatMessage(level, message);
61
+ switch (level) {
62
+ case exports.LogLevel.WARN:
63
+ console.warn(fmtMsg, ...args);
64
+ break;
65
+ case exports.LogLevel.ERROR:
66
+ console.error(fmtMsg, ...args);
67
+ break;
68
+ default:
69
+ console.log(fmtMsg, ...args);
70
+ }
71
+ }
72
+ debug(message, ...args) {
73
+ this.log(exports.LogLevel.DEBUG, message, ...args);
74
+ }
75
+ info(message, ...args) {
76
+ this.log(exports.LogLevel.INFO, message, ...args);
77
+ }
78
+ warn(message, ...args) {
79
+ this.log(exports.LogLevel.WARN, message, ...args);
80
+ }
81
+ error(message, ...args) {
82
+ this.log(exports.LogLevel.ERROR, message, ...args);
83
+ }
84
84
  }
85
85
 
86
86
  exports.Logger = Logger;
package/src/index.d.ts CHANGED
@@ -1,22 +1,22 @@
1
- export declare enum LogLevel {
2
- DEBUG = 0,
3
- INFO = 1,
4
- WARN = 2,
5
- ERROR = 3,
6
- MUTE = 99
7
- }
8
- type Message = string | Error | unknown;
9
- export declare class Logger {
10
- private name;
11
- private level;
12
- constructor(name: string, level?: LogLevel);
13
- get logLevel(): string;
14
- setLogLevel(level: LogLevel | keyof typeof LogLevel): void;
15
- private formatMessage;
16
- log(level: LogLevel, message: Message, ...args: any[]): void;
17
- debug(message: Message, ...args: any[]): void;
18
- info(message: Message, ...args: any[]): void;
19
- warn(message: Message, ...args: any[]): void;
20
- error(message: Message, ...args: any[]): void;
21
- }
22
- export {};
1
+ export declare enum LogLevel {
2
+ DEBUG = 0,
3
+ INFO = 1,
4
+ WARN = 2,
5
+ ERROR = 3,
6
+ MUTE = 99
7
+ }
8
+ type Message = string | Error | unknown;
9
+ export declare class Logger {
10
+ private name;
11
+ private level;
12
+ constructor(name: string, level?: LogLevel);
13
+ get logLevel(): string;
14
+ setLogLevel(level: LogLevel | keyof typeof LogLevel): void;
15
+ private formatMessage;
16
+ log(level: LogLevel, message: Message, ...args: any[]): void;
17
+ debug(message: Message, ...args: any[]): void;
18
+ info(message: Message, ...args: any[]): void;
19
+ warn(message: Message, ...args: any[]): void;
20
+ error(message: Message, ...args: any[]): void;
21
+ }
22
+ export {};
package/src/index.js CHANGED
@@ -1,82 +1,82 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, no-console */
2
- var LogLevel;
3
- (function (LogLevel) {
4
- LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
5
- LogLevel[LogLevel["INFO"] = 1] = "INFO";
6
- LogLevel[LogLevel["WARN"] = 2] = "WARN";
7
- LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
8
- LogLevel[LogLevel["MUTE"] = 99] = "MUTE";
9
- })(LogLevel || (LogLevel = {}));
10
- class Logger {
11
- constructor(name, level) {
12
- this.name = name;
13
- if (level === undefined && process.env['NODE_ENV'] !== 'production') {
14
- this.level = LogLevel.DEBUG;
15
- }
16
- else if (level === undefined) {
17
- this.level = LogLevel.WARN;
18
- }
19
- else {
20
- this.level = level;
21
- }
22
- }
23
- get logLevel() {
24
- return LogLevel[this.level];
25
- }
26
- setLogLevel(level) {
27
- if (level in LogLevel && typeof level === 'string') {
28
- this.level = LogLevel[level];
29
- }
30
- else if (level in LogLevel && typeof level === 'number') {
31
- this.level = level;
32
- }
33
- else {
34
- throw new Error(`Invalid log level: ${level}`);
35
- }
36
- }
37
- formatMessage(level, message) {
38
- if (message instanceof Error) {
39
- message = message.stack;
40
- }
41
- else if (
42
- // Handle Error-Like Objects
43
- message instanceof Object &&
44
- Object.prototype.hasOwnProperty.call(message, 'stack')) {
45
- message = message.stack;
46
- }
47
- else if (message instanceof Object) {
48
- message = JSON.stringify(message);
49
- }
50
- return `[${this.name}] [${LogLevel[level]}]: ${message}`;
51
- }
52
- log(level, message, ...args) {
53
- if (level < this.level || level === LogLevel.MUTE) {
54
- return;
55
- }
56
- const fmtMsg = this.formatMessage(level, message);
57
- switch (level) {
58
- case LogLevel.WARN:
59
- console.warn(fmtMsg, ...args);
60
- break;
61
- case LogLevel.ERROR:
62
- console.error(fmtMsg, ...args);
63
- break;
64
- default:
65
- console.log(fmtMsg, ...args);
66
- }
67
- }
68
- debug(message, ...args) {
69
- this.log(LogLevel.DEBUG, message, ...args);
70
- }
71
- info(message, ...args) {
72
- this.log(LogLevel.INFO, message, ...args);
73
- }
74
- warn(message, ...args) {
75
- this.log(LogLevel.WARN, message, ...args);
76
- }
77
- error(message, ...args) {
78
- this.log(LogLevel.ERROR, message, ...args);
79
- }
1
+ /* eslint-disable @typescript-eslint/no-explicit-any, no-console */
2
+ var LogLevel;
3
+ (function (LogLevel) {
4
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
5
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
6
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
7
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
8
+ LogLevel[LogLevel["MUTE"] = 99] = "MUTE";
9
+ })(LogLevel || (LogLevel = {}));
10
+ class Logger {
11
+ constructor(name, level) {
12
+ this.name = name;
13
+ if (level === undefined && process.env['NODE_ENV'] !== 'production') {
14
+ this.level = LogLevel.DEBUG;
15
+ }
16
+ else if (level === undefined) {
17
+ this.level = LogLevel.WARN;
18
+ }
19
+ else {
20
+ this.level = level;
21
+ }
22
+ }
23
+ get logLevel() {
24
+ return LogLevel[this.level];
25
+ }
26
+ setLogLevel(level) {
27
+ if (level in LogLevel && typeof level === 'string') {
28
+ this.level = LogLevel[level];
29
+ }
30
+ else if (level in LogLevel && typeof level === 'number') {
31
+ this.level = level;
32
+ }
33
+ else {
34
+ throw new Error(`Invalid log level: ${level}`);
35
+ }
36
+ }
37
+ formatMessage(level, message) {
38
+ if (message instanceof Error) {
39
+ message = message.stack;
40
+ }
41
+ else if (
42
+ // Handle Error-Like Objects
43
+ message instanceof Object &&
44
+ Object.prototype.hasOwnProperty.call(message, 'stack')) {
45
+ message = message.stack;
46
+ }
47
+ else if (message instanceof Object) {
48
+ message = JSON.stringify(message);
49
+ }
50
+ return `[${this.name}] [${LogLevel[level]}]: ${message}`;
51
+ }
52
+ log(level, message, ...args) {
53
+ if (level < this.level || level === LogLevel.MUTE) {
54
+ return;
55
+ }
56
+ const fmtMsg = this.formatMessage(level, message);
57
+ switch (level) {
58
+ case LogLevel.WARN:
59
+ console.warn(fmtMsg, ...args);
60
+ break;
61
+ case LogLevel.ERROR:
62
+ console.error(fmtMsg, ...args);
63
+ break;
64
+ default:
65
+ console.log(fmtMsg, ...args);
66
+ }
67
+ }
68
+ debug(message, ...args) {
69
+ this.log(LogLevel.DEBUG, message, ...args);
70
+ }
71
+ info(message, ...args) {
72
+ this.log(LogLevel.INFO, message, ...args);
73
+ }
74
+ warn(message, ...args) {
75
+ this.log(LogLevel.WARN, message, ...args);
76
+ }
77
+ error(message, ...args) {
78
+ this.log(LogLevel.ERROR, message, ...args);
79
+ }
80
80
  }
81
81
 
82
82
  export { LogLevel, Logger };