@alwatr/logger 0.11.0 → 0.12.0
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 +27 -40
- package/README.md +26 -18
- package/logger.d.ts +3 -3
- package/logger.d.ts.map +1 -1
- package/logger.js +56 -39
- package/logger.js.map +1 -1
- package/package.json +4 -4
- package/type.d.ts +8 -8
- package/type.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,85 +3,72 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
# [0.
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @alwatr/logger
|
|
6
|
+
# [0.12.0](https://github.com/AliMD/alwatr/compare/v0.11.0...v0.12.0) (2022-07-22)
|
|
9
7
|
|
|
10
8
|
|
|
9
|
+
### Bug Fixes
|
|
11
10
|
|
|
11
|
+
* **logger:** refactor behavior of force ([7d9307b](https://github.com/AliMD/alwatr/commit/7d9307bb78523f3dae17b3bd80fa2fb47c90975f))
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
### Features
|
|
15
15
|
|
|
16
|
-
**
|
|
16
|
+
* **logger:** compatible with node.js ([7ee8b6d](https://github.com/AliMD/alwatr/commit/7ee8b6de3143e39c300345dec6864c9c56a4aae7))
|
|
17
|
+
* **logger:** node coloring support ([2b4aab6](https://github.com/AliMD/alwatr/commit/2b4aab655bc0707761587a7439de98bbd4ad0e08))
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
|
|
22
|
-
# [0.
|
|
23
|
+
# [0.11.0](https://github.com/AliMD/alwatr/compare/v0.10.1...v0.11.0) (2022-04-16)
|
|
23
24
|
|
|
24
25
|
**Note:** Version bump only for package @alwatr/logger
|
|
25
26
|
|
|
27
|
+
# [0.10.0](https://github.com/AliMD/alwatr/compare/v0.9.0...v0.10.0) (2022-04-02)
|
|
26
28
|
|
|
29
|
+
**Note:** Version bump only for package @alwatr/logger
|
|
27
30
|
|
|
31
|
+
# [0.9.0](https://github.com/AliMD/alwatr/compare/v0.8.0...v0.9.0) (2022-03-22)
|
|
28
32
|
|
|
33
|
+
**Note:** Version bump only for package @alwatr/logger
|
|
29
34
|
|
|
30
35
|
# [0.8.0](https://github.com/AliMD/alwatr/compare/v0.7.2...v0.8.0) (2022-03-14)
|
|
31
36
|
|
|
32
37
|
**Note:** Version bump only for package @alwatr/logger
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
39
|
## [0.7.2](https://github.com/AliMD/alwatr/compare/v0.7.1...v0.7.2) (2022-03-12)
|
|
39
40
|
|
|
40
|
-
|
|
41
41
|
### Features
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
- **logger:** add debug and improve documents ([8f83d29](https://github.com/AliMD/alwatr/commit/8f83d2956e521f016fe530322f657c343f1a0b80))
|
|
48
44
|
|
|
49
45
|
# [0.7.0](https://github.com/AliMD/alwatr/compare/v0.6.1...v0.7.0) (2022-03-12)
|
|
50
46
|
|
|
51
47
|
**Note:** Version bump only for package @alwatr/logger
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
49
|
# [0.6.0](https://github.com/AliMD/alwatr/compare/v0.5.0...v0.6.0) (2022-03-11)
|
|
58
50
|
|
|
59
|
-
|
|
60
51
|
### Bug Fixes
|
|
61
52
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
- alalwatr ([898aa6e](https://github.com/AliMD/alwatr/commit/898aa6ed0888eab9265c83b96a50f1b8c216d143))
|
|
54
|
+
- **packages:** duplicate alwatr keyword ([77d4aa2](https://github.com/AliMD/alwatr/commit/77d4aa2105ad47515c3eee251fd6b8c281d0d1fc))
|
|
68
55
|
|
|
69
56
|
# [0.5.0](https://github.com/AliMD/alwatr/compare/v0.4.0...v0.5.0) (2022-03-11)
|
|
70
57
|
|
|
71
58
|
### Performance Improvements
|
|
72
59
|
|
|
73
|
-
|
|
60
|
+
- **logger:** refactor making logger object ([bc38018](https://github.com/AliMD/alwatr/commit/bc38018758540130df2f46c44521aea0a867bbe8))
|
|
74
61
|
|
|
75
62
|
# [0.4.0](https://github.com/AliMD/alwatr/compare/v0.3.0...v0.4.0) (2022-03-11)
|
|
76
63
|
|
|
77
64
|
### Bug Fixes
|
|
78
65
|
|
|
79
|
-
|
|
66
|
+
- **logger:** types missing ([712363d](https://github.com/AliMD/alwatr/commit/712363d3cf77a712f8c801c4dc9d06d256dfc0e6))
|
|
80
67
|
|
|
81
68
|
### Features
|
|
82
69
|
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
- **logger:** add logProperty, logMethodFull ([8b0317d](https://github.com/AliMD/alwatr/commit/8b0317db88ed73604a27935a3a30cd5c31cb0804))
|
|
71
|
+
- **logger:** complete refactor the logger with new API and fix show correct line number ([7efe8cf](https://github.com/AliMD/alwatr/commit/7efe8cf0f566e148406f38fdd60fa3d747c9bc51))
|
|
85
72
|
|
|
86
73
|
# [0.3.0](https://github.com/AliMD/alwatr/compare/v0.2.1...v0.3.0) (2022-03-06)
|
|
87
74
|
|
|
@@ -91,7 +78,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
91
78
|
|
|
92
79
|
### Bug Fixes
|
|
93
80
|
|
|
94
|
-
|
|
81
|
+
- **logger:** alwatrRegisteredList name ([ff59133](https://github.com/AliMD/alwatr/commit/ff5913321c4eafa1ce53fdacebf8fb4f23bfe430))
|
|
95
82
|
|
|
96
83
|
# [0.2.0](https://github.com/AliMD/alwatr/compare/v0.1.2...v0.2.0) (2022-03-05)
|
|
97
84
|
|
|
@@ -105,19 +92,19 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
105
92
|
|
|
106
93
|
### Bug Fixes
|
|
107
94
|
|
|
108
|
-
|
|
95
|
+
- **packages:** add publish config to public ([9cb3710](https://github.com/AliMD/alwatr/commit/9cb37106b5a35d24d5195ff54232e5769ccc034e))
|
|
109
96
|
|
|
110
97
|
# 0.1.0 (2022-03-02)
|
|
111
98
|
|
|
112
99
|
### Bug Fixes
|
|
113
100
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
- **logger:** fix debug scope ([be62f14](https://github.com/AliMD/alwatr/commit/be62f142cbe3fe4d328e3fd9941ea7c2d640a23f))
|
|
102
|
+
- **logger:** fix logger debug scope ([e734d21](https://github.com/AliMD/alwatr/commit/e734d218db888ecec33a03dc805b98dd75543efd))
|
|
103
|
+
- tsconfig issues ([159adeb](https://github.com/AliMD/alwatr/commit/159adeb72de4626dc16f6657765605b0a2ddccb1))
|
|
117
104
|
|
|
118
105
|
### Features
|
|
119
106
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
107
|
+
- **logger:** debug scope ([6e4190d](https://github.com/AliMD/alwatr/commit/6e4190dc9dafc28e3a7a481aa43622a23527993c))
|
|
108
|
+
- **logger:** debug scope logger package ([1a4baeb](https://github.com/AliMD/alwatr/commit/1a4baeb7a253ba66563dbcf06079242dabb9f246))
|
|
109
|
+
- **logger:** alwatr logger package ([711268e](https://github.com/AliMD/alwatr/commit/711268e17dea8ada9c901ef1e9d605b3212abd97))
|
|
110
|
+
- **logger:** alwatr meta structure ([feade73](https://github.com/AliMD/alwatr/commit/feade735a6f141db77b81d7791d8872d45c8bf7e))
|
package/README.md
CHANGED
|
@@ -5,11 +5,11 @@ Fancy colorful console debugger with custom scope written in tiny TypeScript, ES
|
|
|
5
5
|
## Example usage
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
|
-
import {
|
|
8
|
+
import {createLogger} from 'https://esm.run/@alwatr/logger';
|
|
9
9
|
|
|
10
10
|
const logger = createLogger('demo');
|
|
11
11
|
|
|
12
|
-
function sayHello
|
|
12
|
+
function sayHello(name: string) {
|
|
13
13
|
logger.logMethodArgs('sayHello', {name});
|
|
14
14
|
}
|
|
15
15
|
```
|
|
@@ -22,19 +22,19 @@ Please remember to **reload** the window after changing the debug mode.
|
|
|
22
22
|
- Debugging all scopes
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
|
-
window.localStorage?.setItem('
|
|
25
|
+
window.localStorage?.setItem('ALWATR_DEBUG', '*');
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
- Debugging specific scope
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
|
-
window.localStorage?.setItem('
|
|
31
|
+
window.localStorage?.setItem('ALWATR_DEBUG', 'scope_name');
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
- Debugging some scopes with pattern
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
-
window.localStorage?.setItem('
|
|
37
|
+
window.localStorage?.setItem('ALWATR_DEBUG', '*alwatr*');
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
### API
|
|
@@ -44,7 +44,7 @@ Please remember to **reload** the window after changing the debug mode.
|
|
|
44
44
|
Create a logger function for fancy console debug with custom scope.
|
|
45
45
|
|
|
46
46
|
- **color** is optional and automatically select from internal fancy color list.
|
|
47
|
-
- **
|
|
47
|
+
- **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`
|
|
48
48
|
|
|
49
49
|
Example:
|
|
50
50
|
|
|
@@ -55,15 +55,15 @@ const logger = createLogger('logger/demo');
|
|
|
55
55
|
|
|
56
56
|
### `logger.debug: boolean`
|
|
57
57
|
|
|
58
|
-
Debug state for current scope base on localStorage `
|
|
58
|
+
Debug state for current scope base on localStorage `ALWATR_DEBUG` pattern.
|
|
59
59
|
|
|
60
60
|
### `logger.color: string`
|
|
61
61
|
|
|
62
|
-
Debug state for current scope base on localStorage `
|
|
62
|
+
Debug state for current scope base on localStorage `ALWATR_DEBUG` pattern.
|
|
63
63
|
|
|
64
64
|
### `logger.scope: string`
|
|
65
65
|
|
|
66
|
-
Debug state for current scope base on localStorage `
|
|
66
|
+
Debug state for current scope base on localStorage `ALWATR_DEBUG` pattern.
|
|
67
67
|
|
|
68
68
|
### `logger.logProperty(property, value)`
|
|
69
69
|
|
|
@@ -82,7 +82,7 @@ logger.logProperty('name', 'ali');
|
|
|
82
82
|
Example:
|
|
83
83
|
|
|
84
84
|
```ts
|
|
85
|
-
function myMethod
|
|
85
|
+
function myMethod() {
|
|
86
86
|
logger.logMethod('myMethod');
|
|
87
87
|
}
|
|
88
88
|
```
|
|
@@ -94,7 +94,7 @@ function myMethod () {
|
|
|
94
94
|
Example:
|
|
95
95
|
|
|
96
96
|
```ts
|
|
97
|
-
function myMethod
|
|
97
|
+
function myMethod(a: number, b: number) {
|
|
98
98
|
logger.logMethodArgs('myMethod', {a, b});
|
|
99
99
|
}
|
|
100
100
|
```
|
|
@@ -106,7 +106,7 @@ function myMethod (a: number, b: number) {
|
|
|
106
106
|
Example:
|
|
107
107
|
|
|
108
108
|
```ts
|
|
109
|
-
function add
|
|
109
|
+
function add(a: number, b: number): number {
|
|
110
110
|
const result = a + b;
|
|
111
111
|
logger.logMethodFull('add', {a, b}, result);
|
|
112
112
|
return result;
|
|
@@ -130,7 +130,9 @@ logger.incident('fetch', 'abort_signal', 'aborted signal received', {url: '/test
|
|
|
130
130
|
Example:
|
|
131
131
|
|
|
132
132
|
```ts
|
|
133
|
-
logger.accident('fetch', 'file_not_found', 'url requested return 404 not found', {
|
|
133
|
+
logger.accident('fetch', 'file_not_found', 'url requested return 404 not found', {
|
|
134
|
+
url: '/test.json',
|
|
135
|
+
});
|
|
134
136
|
```
|
|
135
137
|
|
|
136
138
|
### `logger.error(method, code, errorStack, ...args)`
|
|
@@ -163,22 +165,28 @@ logger.logOther('foo:', 'bar', {a: 1});
|
|
|
163
165
|
For example with a promise function with error:
|
|
164
166
|
|
|
165
167
|
```ts
|
|
166
|
-
const failPromiseTest = (): Promise<never> =>
|
|
168
|
+
const failPromiseTest = (): Promise<never> =>
|
|
169
|
+
new Promise((_, reject) => reject(new Error('my_error_code')));
|
|
167
170
|
```
|
|
168
171
|
|
|
169
172
|
Best practices to catch the error and log it:
|
|
170
173
|
|
|
171
174
|
```ts
|
|
172
175
|
// Unhandled promise rejection (just log it)
|
|
173
|
-
failPromiseTest()
|
|
174
|
-
|
|
176
|
+
failPromiseTest().catch((err) =>
|
|
177
|
+
logger.error('myMethod', (err as Error).message || 'error_code', (err as Error).stack || err)
|
|
178
|
+
);
|
|
175
179
|
|
|
176
180
|
// Handled promise rejection
|
|
177
181
|
try {
|
|
178
182
|
await failPromiseTest();
|
|
179
183
|
} catch (err) {
|
|
180
|
-
logger.accident(
|
|
181
|
-
|
|
184
|
+
logger.accident(
|
|
185
|
+
'myMethod',
|
|
186
|
+
'error_code',
|
|
187
|
+
'failPromiseTest failed!, ' + (err as Error).message,
|
|
188
|
+
(err as Error).stack || err
|
|
189
|
+
);
|
|
182
190
|
// do something to handle the error...
|
|
183
191
|
}
|
|
184
192
|
```
|
package/logger.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from './type';
|
|
2
2
|
/**
|
|
3
|
-
* Define `
|
|
3
|
+
* Define `globalThis.Alwatr.registeredList`
|
|
4
4
|
*/
|
|
5
5
|
export declare const alwatrRegisteredList: {
|
|
6
6
|
name: string;
|
|
@@ -14,7 +14,7 @@ export declare const style: {
|
|
|
14
14
|
* Create a logger function for fancy console debug with custom scope.
|
|
15
15
|
*
|
|
16
16
|
* - **color** is optional and automatically select from internal fancy color list.
|
|
17
|
-
* - **
|
|
17
|
+
* - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`
|
|
18
18
|
*
|
|
19
19
|
* Example:
|
|
20
20
|
*
|
|
@@ -23,5 +23,5 @@ export declare const style: {
|
|
|
23
23
|
* const logger = createLogger('logger/demo');
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
export declare const createLogger: (scope: string, color?: string,
|
|
26
|
+
export declare const createLogger: (scope: string, color?: string, debug?: boolean) => Logger;
|
|
27
27
|
//# sourceMappingURL=logger.d.ts.map
|
package/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAInC;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;GAA0C,CAAC;AAkF5E,eAAO,MAAM,KAAK;;;CAGjB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,UACd,MAAM,UACN,MAAM,sBAEd,MA+FF,CAAC"}
|
package/logger.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var _a, _b, _c, _d;
|
|
1
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
2
|
+
const isBrowser = typeof process === 'undefined';
|
|
2
3
|
/**
|
|
3
|
-
* Define `
|
|
4
|
+
* Define `globalThis.Alwatr.registeredList`
|
|
4
5
|
*/
|
|
5
|
-
export const alwatrRegisteredList = ((_a =
|
|
6
|
-
(_b =
|
|
7
|
-
window.Alwatr.registeredList = alwatrRegisteredList;
|
|
6
|
+
export const alwatrRegisteredList = ((_a = globalThis.Alwatr) === null || _a === void 0 ? void 0 : _a.registeredList) || [];
|
|
7
|
+
(_b = globalThis.Alwatr) !== null && _b !== void 0 ? _b : (globalThis.Alwatr = { registeredList: alwatrRegisteredList });
|
|
8
8
|
alwatrRegisteredList.push({
|
|
9
9
|
name: '@alwatr/logger',
|
|
10
10
|
version: '{{ALWATR_VERSION}}', // TODO: replace with real version at release time.
|
|
@@ -13,23 +13,25 @@ alwatrRegisteredList.push({
|
|
|
13
13
|
* Color list storage for logger.
|
|
14
14
|
*/
|
|
15
15
|
let colorIndex = 0;
|
|
16
|
-
const colorList =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
const colorList = isBrowser ?
|
|
17
|
+
[
|
|
18
|
+
'#35b997',
|
|
19
|
+
'#f05561',
|
|
20
|
+
'#ee224a',
|
|
21
|
+
'#91c13e',
|
|
22
|
+
'#22af4b',
|
|
23
|
+
'#f0e995',
|
|
24
|
+
'#0fe995',
|
|
25
|
+
'#0f89ca',
|
|
26
|
+
'#08b9a5',
|
|
27
|
+
'#fee851',
|
|
28
|
+
'#ee573d',
|
|
29
|
+
'#f9df30',
|
|
30
|
+
'#1da2dc',
|
|
31
|
+
'#f05123',
|
|
32
|
+
'#ee2524',
|
|
33
|
+
] :
|
|
34
|
+
['0;36', '0;35', '0;34', '0;33', '0;32']; // red and white omitted
|
|
33
35
|
const getNextColor = () => {
|
|
34
36
|
const color = colorList[colorIndex];
|
|
35
37
|
colorIndex++;
|
|
@@ -38,14 +40,23 @@ const getNextColor = () => {
|
|
|
38
40
|
}
|
|
39
41
|
return color;
|
|
40
42
|
};
|
|
41
|
-
const debugString =
|
|
42
|
-
|
|
43
|
+
const debugString = isBrowser ?
|
|
44
|
+
(_d = (_c = globalThis.localStorage) === null || _c === void 0 ? void 0 : _c.getItem('ALWATR_DEBUG')) === null || _d === void 0 ? void 0 : _d.trim() :
|
|
45
|
+
(_g = (_f = (_e = globalThis.process) === null || _e === void 0 ? void 0 : _e.env) === null || _f === void 0 ? void 0 : _f.ALWATR_DEBUG) === null || _g === void 0 ? void 0 : _g.trim();
|
|
46
|
+
const getDebugState = (scope) => {
|
|
47
|
+
if (debugString == null &&
|
|
48
|
+
isBrowser === false &&
|
|
49
|
+
globalThis.process.env.NODE_ENV !== 'production') {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
// prettier-ignore
|
|
43
53
|
if (debugString == null ||
|
|
44
54
|
debugString == '') {
|
|
45
55
|
return false;
|
|
46
56
|
}
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
// prettier-ignore
|
|
58
|
+
if (debugString === scope ||
|
|
59
|
+
debugString === '*' ||
|
|
49
60
|
(debugString.indexOf('*') === 0 && // starts with `*` for example: `*alwatr*`
|
|
50
61
|
scope.indexOf(debugString.replaceAll('*', '')) !== -1) ||
|
|
51
62
|
(debugString.indexOf('*') === debugString.length - 1 && // ends with `*` for example: `alwatr/*`
|
|
@@ -56,14 +67,14 @@ const getDebugState = (scope, force) => {
|
|
|
56
67
|
return false;
|
|
57
68
|
};
|
|
58
69
|
export const style = {
|
|
59
|
-
scope: 'color: {{color}};',
|
|
60
|
-
reset: 'color: inherit;',
|
|
70
|
+
scope: isBrowser ? 'color: {{color}};' : '\x1b[{{color}}m',
|
|
71
|
+
reset: isBrowser ? 'color: inherit;' : '\x1b[0m',
|
|
61
72
|
};
|
|
62
73
|
/**
|
|
63
74
|
* Create a logger function for fancy console debug with custom scope.
|
|
64
75
|
*
|
|
65
76
|
* - **color** is optional and automatically select from internal fancy color list.
|
|
66
|
-
* - **
|
|
77
|
+
* - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`
|
|
67
78
|
*
|
|
68
79
|
* Example:
|
|
69
80
|
*
|
|
@@ -72,15 +83,15 @@ export const style = {
|
|
|
72
83
|
* const logger = createLogger('logger/demo');
|
|
73
84
|
* ```
|
|
74
85
|
*/
|
|
75
|
-
export const createLogger = (scope, color = getNextColor(),
|
|
86
|
+
export const createLogger = (scope, color = getNextColor(), debug = getDebugState(scope)) => {
|
|
76
87
|
scope = scope.trim();
|
|
77
|
-
const debug = getDebugState(scope, force);
|
|
78
88
|
const first = scope.charAt(0);
|
|
79
89
|
if (first !== '[' && first !== '{' && first !== '(' && first !== '<') {
|
|
80
90
|
scope = '[' + scope + ']';
|
|
81
91
|
}
|
|
82
92
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
83
93
|
const empty = () => { };
|
|
94
|
+
const keySection = isBrowser ? '%c%s%c' : '%s%s%s';
|
|
84
95
|
const styleScope = style.scope.replaceAll('{{color}}', color);
|
|
85
96
|
/**
|
|
86
97
|
* Required logger object, accident, error always reported even when the debug is false.
|
|
@@ -89,8 +100,12 @@ export const createLogger = (scope, color = getNextColor(), force = false) => {
|
|
|
89
100
|
debug,
|
|
90
101
|
color,
|
|
91
102
|
scope,
|
|
92
|
-
accident:
|
|
93
|
-
|
|
103
|
+
accident: isBrowser ?
|
|
104
|
+
console.error.bind(console, '%c%s%c.%s "%s" => Accident: "%s" (%s)!', styleScope, scope, style.reset) :
|
|
105
|
+
console.error.bind(console, `${styleScope}⚠️ %s\x1b[33m.%s "%s" =>${style.reset}`, scope),
|
|
106
|
+
error: isBrowser ?
|
|
107
|
+
console.error.bind(console, '%c%s%c.%s "%s" =>', styleScope, scope, style.reset) :
|
|
108
|
+
console.error.bind(console, `${styleScope}❌ %s\x1b[31m.%s "%s" =>\x1b[0;2m`, scope),
|
|
94
109
|
};
|
|
95
110
|
if (!debug) {
|
|
96
111
|
return {
|
|
@@ -106,12 +121,14 @@ export const createLogger = (scope, color = getNextColor(), force = false) => {
|
|
|
106
121
|
// else if debug is true for this scope
|
|
107
122
|
return {
|
|
108
123
|
...requiredItems,
|
|
109
|
-
logProperty: console.debug.bind(console, '
|
|
110
|
-
logMethod: console.debug.bind(console, '
|
|
111
|
-
logMethodArgs: console.debug.bind(console, '
|
|
112
|
-
logMethodFull: console.debug.bind(console, '
|
|
113
|
-
incident:
|
|
114
|
-
|
|
124
|
+
logProperty: console.debug.bind(console, keySection + '.%s = %o;', styleScope, scope, style.reset),
|
|
125
|
+
logMethod: console.debug.bind(console, keySection + '.%s();', styleScope, scope, style.reset),
|
|
126
|
+
logMethodArgs: console.debug.bind(console, keySection + '.%s(%o);', styleScope, scope, style.reset),
|
|
127
|
+
logMethodFull: console.debug.bind(console, keySection + '.%s(%o); // %o', styleScope, scope, style.reset),
|
|
128
|
+
incident: isBrowser ?
|
|
129
|
+
console.trace.bind(console, '%c%s%c.%s() => Incident: "%s" (%s)!', styleScope, scope, style.reset) :
|
|
130
|
+
console.log.bind(console, `${styleScope}🔸 %s${style.reset}.%s() => Incident: "%s" (%s)!\x1b[0;2m`, scope),
|
|
131
|
+
logOther: console.debug.bind(console, keySection, styleScope, scope, style.reset),
|
|
115
132
|
};
|
|
116
133
|
};
|
|
117
134
|
//# sourceMappingURL=logger.js.map
|
package/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":";AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAA,MAAA,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":";AAEA,MAAM,SAAS,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAA,MAAA,UAAU,CAAC,MAAM,0CAAE,cAAc,KAAI,EAAE,CAAC;AAC5E,MAAA,UAAU,CAAC,MAAM,oCAAjB,UAAU,CAAC,MAAM,GAAK,EAAC,cAAc,EAAE,oBAAoB,EAAC,EAAC;AAE7D,oBAAoB,CAAC,IAAI,CAAC;IACxB,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,oBAAoB,EAAE,mDAAmD;CACnF,CAAC,CAAC;AAEH;;GAEG;AACH,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,MAAM,SAAS,G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B,OAAO,EACP,UAAU,GAAG,UAAU,EACvB,UAAU,EACV,KAAK,EACL,KAAK,CAAC,KAAK,CACd;QAED,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAC7B,OAAO,EACP,UAAU,GAAG,gBAAgB,EAC7B,UAAU,EACV,KAAK,EACL,KAAK,CAAC,KAAK,CACd;QAED,QAAQ,EAAE,SAAS,CAAC,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,IAAI,CACd,OAAO,EACP,qCAAqC,EACrC,UAAU,EACV,KAAK,EACL,KAAK,CAAC,KAAK,CACd,CAAC,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,IAAI,CACZ,OAAO,EACP,GAAG,UAAU,QAAQ,KAAK,CAAC,KAAK,wCAAwC,EACxE,KAAK,CACR;QAEH,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;KAClF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/logger",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"log",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "https://github.com/AliMD/alwatr",
|
|
28
|
-
"directory": "
|
|
28
|
+
"directory": "packages/core/logger"
|
|
29
29
|
},
|
|
30
|
-
"homepage": "https://github.com/AliMD/alwatr/tree/main/
|
|
30
|
+
"homepage": "https://github.com/AliMD/alwatr/tree/main/packages/core/logger#readme",
|
|
31
31
|
"bugs": {
|
|
32
32
|
"url": "https://github.com/AliMD/alwatr/issues"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"tslib": "^2.3.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "2da92e22ea946abf6155122d0a28674dd4c0308b"
|
|
38
38
|
}
|
package/type.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
export interface GlobalAlwatr {
|
|
2
|
+
registeredList: Array<{
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
}>;
|
|
6
|
+
}
|
|
1
7
|
declare global {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
registeredList?: Array<{
|
|
5
|
-
name: string;
|
|
6
|
-
version: string;
|
|
7
|
-
}>;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
8
|
+
var Alwatr: GlobalAlwatr;
|
|
9
|
+
var ALWATR_DEBUG: string | undefined;
|
|
10
10
|
/**
|
|
11
11
|
* @TODO: Make an issue to TS, WTF is this way! any better solution for more args in bind?!
|
|
12
12
|
*/
|
package/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,KAAK,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACJ;AAED,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,MAAM,EAAE,YAAY,CAAC;IACzB,IAAI,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAErC;;OAEG;IACH,UAAU,gBAAgB;QACxB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAChD,IAAI,EAAE,CAAC,I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