@alwatr/logger 0.10.0 → 0.13.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 +31 -34
- package/README.md +24 -17
- package/logger.d.ts +5 -4
- package/logger.d.ts.map +1 -1
- package/logger.js +53 -39
- package/logger.js.map +1 -1
- package/package.json +5 -9
- package/type.d.ts +9 -9
- package/type.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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.
|
|
6
|
+
# [0.13.0](https://github.com/AliMD/alwatr/compare/v0.12.0...v0.13.0) (2022-08-06)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @alwatr/logger
|
|
9
9
|
|
|
@@ -11,69 +11,66 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
# [0.
|
|
14
|
+
# [0.12.0](https://github.com/AliMD/alwatr/compare/v0.11.0...v0.12.0) (2022-07-22)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
### Bug Fixes
|
|
17
17
|
|
|
18
|
+
- **logger:** refactor behavior of force ([7d9307b](https://github.com/AliMD/alwatr/commit/7d9307bb78523f3dae17b3bd80fa2fb47c90975f))
|
|
18
19
|
|
|
20
|
+
### Features
|
|
19
21
|
|
|
22
|
+
- **logger:** compatible with node.js ([7ee8b6d](https://github.com/AliMD/alwatr/commit/7ee8b6de3143e39c300345dec6864c9c56a4aae7))
|
|
23
|
+
- **logger:** node coloring support ([2b4aab6](https://github.com/AliMD/alwatr/commit/2b4aab655bc0707761587a7439de98bbd4ad0e08))
|
|
20
24
|
|
|
25
|
+
# [0.11.0](https://github.com/AliMD/alwatr/compare/v0.10.1...v0.11.0) (2022-04-16)
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
**Note:** Version bump only for package @alwatr/logger
|
|
28
|
+
|
|
29
|
+
# [0.10.0](https://github.com/AliMD/alwatr/compare/v0.9.0...v0.10.0) (2022-04-02)
|
|
23
30
|
|
|
24
31
|
**Note:** Version bump only for package @alwatr/logger
|
|
25
32
|
|
|
33
|
+
# [0.9.0](https://github.com/AliMD/alwatr/compare/v0.8.0...v0.9.0) (2022-03-22)
|
|
26
34
|
|
|
35
|
+
**Note:** Version bump only for package @alwatr/logger
|
|
27
36
|
|
|
37
|
+
# [0.8.0](https://github.com/AliMD/alwatr/compare/v0.7.2...v0.8.0) (2022-03-14)
|
|
28
38
|
|
|
39
|
+
**Note:** Version bump only for package @alwatr/logger
|
|
29
40
|
|
|
30
41
|
## [0.7.2](https://github.com/AliMD/alwatr/compare/v0.7.1...v0.7.2) (2022-03-12)
|
|
31
42
|
|
|
32
|
-
|
|
33
43
|
### Features
|
|
34
44
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
- **logger:** add debug and improve documents ([8f83d29](https://github.com/AliMD/alwatr/commit/8f83d2956e521f016fe530322f657c343f1a0b80))
|
|
40
46
|
|
|
41
47
|
# [0.7.0](https://github.com/AliMD/alwatr/compare/v0.6.1...v0.7.0) (2022-03-12)
|
|
42
48
|
|
|
43
49
|
**Note:** Version bump only for package @alwatr/logger
|
|
44
50
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
51
|
# [0.6.0](https://github.com/AliMD/alwatr/compare/v0.5.0...v0.6.0) (2022-03-11)
|
|
50
52
|
|
|
51
|
-
|
|
52
53
|
### Bug Fixes
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
- alalwatr ([898aa6e](https://github.com/AliMD/alwatr/commit/898aa6ed0888eab9265c83b96a50f1b8c216d143))
|
|
56
|
+
- **packages:** duplicate alwatr keyword ([77d4aa2](https://github.com/AliMD/alwatr/commit/77d4aa2105ad47515c3eee251fd6b8c281d0d1fc))
|
|
60
57
|
|
|
61
58
|
# [0.5.0](https://github.com/AliMD/alwatr/compare/v0.4.0...v0.5.0) (2022-03-11)
|
|
62
59
|
|
|
63
60
|
### Performance Improvements
|
|
64
61
|
|
|
65
|
-
|
|
62
|
+
- **logger:** refactor making logger object ([bc38018](https://github.com/AliMD/alwatr/commit/bc38018758540130df2f46c44521aea0a867bbe8))
|
|
66
63
|
|
|
67
64
|
# [0.4.0](https://github.com/AliMD/alwatr/compare/v0.3.0...v0.4.0) (2022-03-11)
|
|
68
65
|
|
|
69
66
|
### Bug Fixes
|
|
70
67
|
|
|
71
|
-
|
|
68
|
+
- **logger:** types missing ([712363d](https://github.com/AliMD/alwatr/commit/712363d3cf77a712f8c801c4dc9d06d256dfc0e6))
|
|
72
69
|
|
|
73
70
|
### Features
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
- **logger:** add logProperty, logMethodFull ([8b0317d](https://github.com/AliMD/alwatr/commit/8b0317db88ed73604a27935a3a30cd5c31cb0804))
|
|
73
|
+
- **logger:** complete refactor the logger with new API and fix show correct line number ([7efe8cf](https://github.com/AliMD/alwatr/commit/7efe8cf0f566e148406f38fdd60fa3d747c9bc51))
|
|
77
74
|
|
|
78
75
|
# [0.3.0](https://github.com/AliMD/alwatr/compare/v0.2.1...v0.3.0) (2022-03-06)
|
|
79
76
|
|
|
@@ -83,7 +80,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
83
80
|
|
|
84
81
|
### Bug Fixes
|
|
85
82
|
|
|
86
|
-
|
|
83
|
+
- **logger:** alwatrRegisteredList name ([ff59133](https://github.com/AliMD/alwatr/commit/ff5913321c4eafa1ce53fdacebf8fb4f23bfe430))
|
|
87
84
|
|
|
88
85
|
# [0.2.0](https://github.com/AliMD/alwatr/compare/v0.1.2...v0.2.0) (2022-03-05)
|
|
89
86
|
|
|
@@ -97,19 +94,19 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
97
94
|
|
|
98
95
|
### Bug Fixes
|
|
99
96
|
|
|
100
|
-
|
|
97
|
+
- **packages:** add publish config to public ([9cb3710](https://github.com/AliMD/alwatr/commit/9cb37106b5a35d24d5195ff54232e5769ccc034e))
|
|
101
98
|
|
|
102
99
|
# 0.1.0 (2022-03-02)
|
|
103
100
|
|
|
104
101
|
### Bug Fixes
|
|
105
102
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
- **logger:** fix debug scope ([be62f14](https://github.com/AliMD/alwatr/commit/be62f142cbe3fe4d328e3fd9941ea7c2d640a23f))
|
|
104
|
+
- **logger:** fix logger debug scope ([e734d21](https://github.com/AliMD/alwatr/commit/e734d218db888ecec33a03dc805b98dd75543efd))
|
|
105
|
+
- tsconfig issues ([159adeb](https://github.com/AliMD/alwatr/commit/159adeb72de4626dc16f6657765605b0a2ddccb1))
|
|
109
106
|
|
|
110
107
|
### Features
|
|
111
108
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
- **logger:** debug scope ([6e4190d](https://github.com/AliMD/alwatr/commit/6e4190dc9dafc28e3a7a481aa43622a23527993c))
|
|
110
|
+
- **logger:** debug scope logger package ([1a4baeb](https://github.com/AliMD/alwatr/commit/1a4baeb7a253ba66563dbcf06079242dabb9f246))
|
|
111
|
+
- **logger:** alwatr logger package ([711268e](https://github.com/AliMD/alwatr/commit/711268e17dea8ada9c901ef1e9d605b3212abd97))
|
|
112
|
+
- **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)`
|
|
@@ -170,15 +172,20 @@ Best practices to catch the error and log it:
|
|
|
170
172
|
|
|
171
173
|
```ts
|
|
172
174
|
// Unhandled promise rejection (just log it)
|
|
173
|
-
failPromiseTest()
|
|
174
|
-
|
|
175
|
+
failPromiseTest().catch((err) =>
|
|
176
|
+
logger.error('myMethod', (err as Error).message || 'error_code', (err as Error).stack || err)
|
|
177
|
+
);
|
|
175
178
|
|
|
176
179
|
// Handled promise rejection
|
|
177
180
|
try {
|
|
178
181
|
await failPromiseTest();
|
|
179
182
|
} catch (err) {
|
|
180
|
-
logger.accident(
|
|
181
|
-
|
|
183
|
+
logger.accident(
|
|
184
|
+
'myMethod',
|
|
185
|
+
'error_code',
|
|
186
|
+
'failPromiseTest failed!, ' + (err as Error).message,
|
|
187
|
+
(err as Error).stack || err
|
|
188
|
+
);
|
|
182
189
|
// do something to handle the error...
|
|
183
190
|
}
|
|
184
191
|
```
|
package/logger.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AlwatrLogger } from './type';
|
|
2
|
+
export { AlwatrLogger };
|
|
2
3
|
/**
|
|
3
|
-
* Define `
|
|
4
|
+
* Define `globalThis.Alwatr.registeredList`
|
|
4
5
|
*/
|
|
5
6
|
export declare const alwatrRegisteredList: {
|
|
6
7
|
name: string;
|
|
@@ -14,7 +15,7 @@ export declare const style: {
|
|
|
14
15
|
* Create a logger function for fancy console debug with custom scope.
|
|
15
16
|
*
|
|
16
17
|
* - **color** is optional and automatically select from internal fancy color list.
|
|
17
|
-
* - **
|
|
18
|
+
* - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`
|
|
18
19
|
*
|
|
19
20
|
* Example:
|
|
20
21
|
*
|
|
@@ -23,5 +24,5 @@ export declare const style: {
|
|
|
23
24
|
* const logger = createLogger('logger/demo');
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
|
-
export declare const createLogger: (scope: string, color?: string,
|
|
27
|
+
export declare const createLogger: (scope: string, color?: string, debug?: boolean) => AlwatrLogger;
|
|
27
28
|
//# 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,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAC,YAAY,EAAC,CAAC;AAItB;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;GAA0C,CAAC;AA8E5E,eAAO,MAAM,KAAK;;;CAGjB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,UACd,MAAM,UACN,MAAM,sBAEd,YA6DF,CAAC"}
|
package/logger.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
const isBrowser = typeof process === 'undefined';
|
|
2
2
|
/**
|
|
3
|
-
* Define `
|
|
3
|
+
* Define `globalThis.Alwatr.registeredList`
|
|
4
4
|
*/
|
|
5
|
-
export const alwatrRegisteredList =
|
|
6
|
-
|
|
7
|
-
window.Alwatr.registeredList = alwatrRegisteredList;
|
|
5
|
+
export const alwatrRegisteredList = globalThis.Alwatr?.registeredList || [];
|
|
6
|
+
globalThis.Alwatr ?? (globalThis.Alwatr = { registeredList: alwatrRegisteredList });
|
|
8
7
|
alwatrRegisteredList.push({
|
|
9
8
|
name: '@alwatr/logger',
|
|
10
9
|
version: '{{ALWATR_VERSION}}', // TODO: replace with real version at release time.
|
|
@@ -13,23 +12,25 @@ alwatrRegisteredList.push({
|
|
|
13
12
|
* Color list storage for logger.
|
|
14
13
|
*/
|
|
15
14
|
let colorIndex = 0;
|
|
16
|
-
const colorList =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
const colorList = isBrowser ?
|
|
16
|
+
[
|
|
17
|
+
'#35b997',
|
|
18
|
+
'#f05561',
|
|
19
|
+
'#ee224a',
|
|
20
|
+
'#91c13e',
|
|
21
|
+
'#22af4b',
|
|
22
|
+
'#f0e995',
|
|
23
|
+
'#0fe995',
|
|
24
|
+
'#0f89ca',
|
|
25
|
+
'#08b9a5',
|
|
26
|
+
'#fee851',
|
|
27
|
+
'#ee573d',
|
|
28
|
+
'#f9df30',
|
|
29
|
+
'#1da2dc',
|
|
30
|
+
'#f05123',
|
|
31
|
+
'#ee2524',
|
|
32
|
+
] :
|
|
33
|
+
['0;36', '0;35', '0;34', '0;33', '0;32']; // red and white omitted
|
|
33
34
|
const getNextColor = () => {
|
|
34
35
|
const color = colorList[colorIndex];
|
|
35
36
|
colorIndex++;
|
|
@@ -38,14 +39,21 @@ const getNextColor = () => {
|
|
|
38
39
|
}
|
|
39
40
|
return color;
|
|
40
41
|
};
|
|
41
|
-
const debugString =
|
|
42
|
-
|
|
42
|
+
const debugString = isBrowser ?
|
|
43
|
+
globalThis.localStorage?.getItem('ALWATR_DEBUG')?.trim() :
|
|
44
|
+
globalThis.process?.env?.ALWATR_DEBUG?.trim();
|
|
45
|
+
const getDebugState = (scope) => {
|
|
46
|
+
if (debugString == null && isBrowser === false && globalThis.process.env.NODE_ENV !== 'production') {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
// prettier-ignore
|
|
43
50
|
if (debugString == null ||
|
|
44
51
|
debugString == '') {
|
|
45
52
|
return false;
|
|
46
53
|
}
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
// prettier-ignore
|
|
55
|
+
if (debugString === scope ||
|
|
56
|
+
debugString === '*' ||
|
|
49
57
|
(debugString.indexOf('*') === 0 && // starts with `*` for example: `*alwatr*`
|
|
50
58
|
scope.indexOf(debugString.replaceAll('*', '')) !== -1) ||
|
|
51
59
|
(debugString.indexOf('*') === debugString.length - 1 && // ends with `*` for example: `alwatr/*`
|
|
@@ -56,14 +64,14 @@ const getDebugState = (scope, force) => {
|
|
|
56
64
|
return false;
|
|
57
65
|
};
|
|
58
66
|
export const style = {
|
|
59
|
-
scope: 'color: {{color}};',
|
|
60
|
-
reset: 'color: inherit;',
|
|
67
|
+
scope: isBrowser ? 'color: {{color}};' : '\x1b[{{color}}m',
|
|
68
|
+
reset: isBrowser ? 'color: inherit;' : '\x1b[0m',
|
|
61
69
|
};
|
|
62
70
|
/**
|
|
63
71
|
* Create a logger function for fancy console debug with custom scope.
|
|
64
72
|
*
|
|
65
73
|
* - **color** is optional and automatically select from internal fancy color list.
|
|
66
|
-
* - **
|
|
74
|
+
* - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`
|
|
67
75
|
*
|
|
68
76
|
* Example:
|
|
69
77
|
*
|
|
@@ -72,15 +80,15 @@ export const style = {
|
|
|
72
80
|
* const logger = createLogger('logger/demo');
|
|
73
81
|
* ```
|
|
74
82
|
*/
|
|
75
|
-
export const createLogger = (scope, color = getNextColor(),
|
|
83
|
+
export const createLogger = (scope, color = getNextColor(), debug = getDebugState(scope)) => {
|
|
76
84
|
scope = scope.trim();
|
|
77
|
-
const debug = getDebugState(scope, force);
|
|
78
85
|
const first = scope.charAt(0);
|
|
79
86
|
if (first !== '[' && first !== '{' && first !== '(' && first !== '<') {
|
|
80
87
|
scope = '[' + scope + ']';
|
|
81
88
|
}
|
|
82
89
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
83
90
|
const empty = () => { };
|
|
91
|
+
const keySection = isBrowser ? '%c%s%c' : '%s%s%s';
|
|
84
92
|
const styleScope = style.scope.replaceAll('{{color}}', color);
|
|
85
93
|
/**
|
|
86
94
|
* Required logger object, accident, error always reported even when the debug is false.
|
|
@@ -89,8 +97,12 @@ export const createLogger = (scope, color = getNextColor(), force = false) => {
|
|
|
89
97
|
debug,
|
|
90
98
|
color,
|
|
91
99
|
scope,
|
|
92
|
-
accident:
|
|
93
|
-
|
|
100
|
+
accident: isBrowser ?
|
|
101
|
+
console.error.bind(console, '%c%s%c.%s "%s" => Accident: "%s" (%s)!', styleScope, scope, style.reset) :
|
|
102
|
+
console.error.bind(console, `${styleScope}⚠️ %s\x1b[33m.%s "%s" =>${style.reset}`, scope),
|
|
103
|
+
error: isBrowser ?
|
|
104
|
+
console.error.bind(console, '%c%s%c.%s "%s" =>', styleScope, scope, style.reset) :
|
|
105
|
+
console.error.bind(console, `${styleScope}❌ %s\x1b[31m.%s "%s" =>\x1b[0;2m`, scope),
|
|
94
106
|
};
|
|
95
107
|
if (!debug) {
|
|
96
108
|
return {
|
|
@@ -106,12 +118,14 @@ export const createLogger = (scope, color = getNextColor(), force = false) => {
|
|
|
106
118
|
// else if debug is true for this scope
|
|
107
119
|
return {
|
|
108
120
|
...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
|
-
|
|
121
|
+
logProperty: console.debug.bind(console, keySection + '.%s = %o;', styleScope, scope, style.reset),
|
|
122
|
+
logMethod: console.debug.bind(console, keySection + '.%s();', styleScope, scope, style.reset),
|
|
123
|
+
logMethodArgs: console.debug.bind(console, keySection + '.%s(%o);', styleScope, scope, style.reset),
|
|
124
|
+
logMethodFull: console.debug.bind(console, keySection + '.%s(%o); // %o', styleScope, scope, style.reset),
|
|
125
|
+
incident: isBrowser ?
|
|
126
|
+
console.trace.bind(console, '%c%s%c.%s() => Incident: "%s" (%s)!', styleScope, scope, style.reset) :
|
|
127
|
+
console.log.bind(console, `${styleScope}🔸 %s${style.reset}.%s() => Incident: "%s" (%s)!\x1b[0;2m`, scope),
|
|
128
|
+
logOther: console.debug.bind(console, keySection, styleScope, scope, style.reset),
|
|
115
129
|
};
|
|
116
130
|
};
|
|
117
131
|
//# sourceMappingURL=logger.js.map
|
package/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAGA,MAAM,SAAS,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC,MAAM,EAAE,cAAc,IAAI,EAAE,CAAC;AAC5E,UAAU,CAAC,MAAM,KAAjB,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,GAAG,SAAS,CAAC,CAAC;IAC3B;QACE,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;KACV,CAAC,CAAC;IACH,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,wBAAwB;AAEpE,MAAM,YAAY,GAAG,GAAW,EAAE;IAChC,MAAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IACpC,UAAU,EAAE,CAAC;IACb,IAAI,UAAU,IAAI,SAAS,CAAC,MAAM,EAAE;QAClC,UAAU,GAAG,CAAC,C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AC;QAE5G,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.13.0",
|
|
4
4
|
"description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"log",
|
|
@@ -17,11 +17,7 @@
|
|
|
17
17
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"files": [
|
|
20
|
-
"**/*.js"
|
|
21
|
-
"**/*.d.ts",
|
|
22
|
-
"**/*.map",
|
|
23
|
-
"**/*.html",
|
|
24
|
-
"**/*.md"
|
|
20
|
+
"**/*.{d.ts.map,d.ts,js.map,js,html,md}"
|
|
25
21
|
],
|
|
26
22
|
"publishConfig": {
|
|
27
23
|
"access": "public"
|
|
@@ -29,14 +25,14 @@
|
|
|
29
25
|
"repository": {
|
|
30
26
|
"type": "git",
|
|
31
27
|
"url": "https://github.com/AliMD/alwatr",
|
|
32
|
-
"directory": "
|
|
28
|
+
"directory": "packages/core/logger"
|
|
33
29
|
},
|
|
34
|
-
"homepage": "https://github.com/AliMD/alwatr/tree/main/
|
|
30
|
+
"homepage": "https://github.com/AliMD/alwatr/tree/main/packages/core/logger#readme",
|
|
35
31
|
"bugs": {
|
|
36
32
|
"url": "https://github.com/AliMD/alwatr/issues"
|
|
37
33
|
},
|
|
38
34
|
"dependencies": {
|
|
39
35
|
"tslib": "^2.3.1"
|
|
40
36
|
},
|
|
41
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "2739e45b8d36caf18b25f5d779467c53a3efc835"
|
|
42
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
|
*/
|
|
@@ -14,7 +14,7 @@ declare global {
|
|
|
14
14
|
bind<T, A0, A1, A2, A3, A4, A extends unknown[], R>(this: (this: T, arg0: A0, arg1: A1, arg2: A2, arg3: A3, arg4: A4, ...args: A) => R, thisArg: T, arg0: A0, arg1: A1, arg2: A2, arg3: A3, arg4: A4): (...args: A) => R;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
export interface
|
|
17
|
+
export interface AlwatrLogger {
|
|
18
18
|
/**
|
|
19
19
|
* Debug state for current scope base on localStorage `ALWATR_LOG` pattern.
|
|
20
20
|
*/
|
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,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