@wsurface/debug 2.0.1 → 2.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wsurface/debug",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "A simple and powerful logger for your project.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,7 +16,7 @@ const DEFAULT_THEME = {
16
16
  conn: "blue"
17
17
  };
18
18
 
19
- const ICONS = {
19
+ const DEFAULT_ICONS = {
20
20
  info: "ℹ",
21
21
  warn: "⚠",
22
22
  error: "✖",
@@ -32,6 +32,7 @@ class Logger {
32
32
  icons: true,
33
33
  tag: true,
34
34
  theme: DEFAULT_THEME,
35
+ iconSet: DEFAULT_ICONS,
35
36
  ...options
36
37
  };
37
38
 
@@ -67,13 +68,25 @@ class Logger {
67
68
  if (!start) return;
68
69
 
69
70
  const duration = Date.now() - start;
70
-
71
71
  this.info(`⏱ ${label}: ${duration}ms`);
72
72
  this.timers.delete(label);
73
73
  }
74
74
  };
75
75
  }
76
76
 
77
+ getIcon(level, options) {
78
+ if (!options.icons) return "";
79
+
80
+ const iconSet = {
81
+ ...DEFAULT_ICONS,
82
+ ...options.iconSet
83
+ };
84
+
85
+ const icon = iconSet[level];
86
+
87
+ return icon ? icon + " " : "";
88
+ }
89
+
77
90
  createMode(options) {
78
91
  const mode = {};
79
92
 
@@ -90,7 +103,8 @@ class Logger {
90
103
 
91
104
  this.levels.forEach(level => {
92
105
  box[level] = msg => {
93
- const text = ` ${ICONS[level]} ${msg} `;
106
+ const icon = this.getIcon(level, this.options);
107
+ const text = ` ${icon}${msg} `;
94
108
  const line = "─".repeat(text.length);
95
109
 
96
110
  console.log(`┌${line}┐`);
@@ -126,7 +140,16 @@ class Logger {
126
140
  }
127
141
 
128
142
  setOptions(options) {
129
- this.options = { ...this.options, ...options };
143
+ this.options = {
144
+ ...this.options,
145
+ ...options,
146
+ iconSet: options.iconSet
147
+ ? {
148
+ ...this.options.iconSet,
149
+ ...options.iconSet
150
+ }
151
+ : this.options.iconSet
152
+ };
130
153
  }
131
154
 
132
155
  formatTimestamp(enabled) {
@@ -151,7 +174,7 @@ class Logger {
151
174
 
152
175
  const color = c[theme[level]] || c.white;
153
176
 
154
- const icon = merged.icons ? `${ICONS[level]} ` : "";
177
+ const icon = this.getIcon(level, merged);
155
178
 
156
179
  const timestamp = this.formatTimestamp(merged.timestamp);
157
180
 
@@ -11,7 +11,7 @@ const DEFAULT_THEME = {
11
11
  conn: "blue"
12
12
  };
13
13
 
14
- const ICONS = {
14
+ const DEFAULT_ICONS = {
15
15
  info: "ℹ",
16
16
  warn: "⚠",
17
17
  error: "✖",
@@ -27,6 +27,7 @@ class Logger {
27
27
  icons: true,
28
28
  tag: true,
29
29
  theme: DEFAULT_THEME,
30
+ iconSet: DEFAULT_ICONS,
30
31
  ...options
31
32
  };
32
33
 
@@ -41,7 +42,6 @@ class Logger {
41
42
  });
42
43
 
43
44
  this.box = this.createBox();
44
-
45
45
  this.json = this.createJSON();
46
46
 
47
47
  this.group = {
@@ -70,6 +70,19 @@ class Logger {
70
70
  };
71
71
  }
72
72
 
73
+ getIcon(level, options) {
74
+ if (!options.icons) return "";
75
+
76
+ const iconSet = {
77
+ ...DEFAULT_ICONS,
78
+ ...options.iconSet
79
+ };
80
+
81
+ const icon = iconSet[level];
82
+
83
+ return icon ? icon + " " : "";
84
+ }
85
+
73
86
  createMode(options) {
74
87
  const mode = {};
75
88
  this.levels.forEach(level => {
@@ -84,7 +97,8 @@ class Logger {
84
97
 
85
98
  this.levels.forEach(level => {
86
99
  box[level] = msg => {
87
- const text = ` ${ICONS[level]} ${msg} `;
100
+ const icon = this.getIcon(level, this.options);
101
+ const text = ` ${icon}${msg} `;
88
102
  const line = "─".repeat(text.length);
89
103
 
90
104
  console.log(`┌${line}┐`);
@@ -120,7 +134,16 @@ class Logger {
120
134
  }
121
135
 
122
136
  setOptions(options) {
123
- this.options = { ...this.options, ...options };
137
+ this.options = {
138
+ ...this.options,
139
+ ...options,
140
+ iconSet: options.iconSet
141
+ ? {
142
+ ...this.options.iconSet,
143
+ ...options.iconSet
144
+ }
145
+ : this.options.iconSet
146
+ };
124
147
  }
125
148
 
126
149
  formatTimestamp(enabled) {
@@ -143,7 +166,7 @@ class Logger {
143
166
 
144
167
  const color = chalk[theme[level]] || chalk.white;
145
168
 
146
- const icon = merged.icons ? `${ICONS[level]} ` : "";
169
+ const icon = this.getIcon(level, merged);
147
170
 
148
171
  const timestamp = this.formatTimestamp(merged.timestamp);
149
172