@alwatr/logger 0.6.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 +72 -0
- package/LICENSE +21 -0
- package/README.md +140 -0
- package/logger.d.ts +23 -0
- package/logger.d.ts.map +1 -0
- package/logger.js +112 -0
- package/logger.js.map +1 -0
- package/package.json +42 -0
- package/type.d.ts +114 -0
- package/type.d.ts.map +1 -0
- package/type.js +2 -0
- package/type.js.map +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [0.6.0](https://github.com/AliMD/alwatr/compare/v0.5.0...v0.6.0) (2022-03-11)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* alalwatr ([898aa6e](https://github.com/AliMD/alwatr/commit/898aa6ed0888eab9265c83b96a50f1b8c216d143))
|
|
12
|
+
* **packages:** duplicate alwatr keyword ([77d4aa2](https://github.com/AliMD/alwatr/commit/77d4aa2105ad47515c3eee251fd6b8c281d0d1fc))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# [0.5.0](https://github.com/AliMD/alwatr/compare/v0.4.0...v0.5.0) (2022-03-11)
|
|
19
|
+
|
|
20
|
+
### Performance Improvements
|
|
21
|
+
|
|
22
|
+
* **logger:** refactor making logger object ([bc38018](https://github.com/AliMD/alwatr/commit/bc38018758540130df2f46c44521aea0a867bbe8))
|
|
23
|
+
|
|
24
|
+
# [0.4.0](https://github.com/AliMD/alwatr/compare/v0.3.0...v0.4.0) (2022-03-11)
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* **logger:** types missing ([712363d](https://github.com/AliMD/alwatr/commit/712363d3cf77a712f8c801c4dc9d06d256dfc0e6))
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* **logger:** add logProperty, logMethodFull ([8b0317d](https://github.com/AliMD/alwatr/commit/8b0317db88ed73604a27935a3a30cd5c31cb0804))
|
|
33
|
+
* **logger:** complete refactor the logger with new API and fix show correct line number ([7efe8cf](https://github.com/AliMD/alwatr/commit/7efe8cf0f566e148406f38fdd60fa3d747c9bc51))
|
|
34
|
+
|
|
35
|
+
# [0.3.0](https://github.com/AliMD/alwatr/compare/v0.2.1...v0.3.0) (2022-03-06)
|
|
36
|
+
|
|
37
|
+
**Note:** Version bump only for package @alwatr/logger
|
|
38
|
+
|
|
39
|
+
## [0.2.1](https://github.com/AliMD/alwatr/compare/v0.2.0...v0.2.1) (2022-03-05)
|
|
40
|
+
|
|
41
|
+
### Bug Fixes
|
|
42
|
+
|
|
43
|
+
* **logger:** alwatrRegisteredList name ([ff59133](https://github.com/AliMD/alwatr/commit/ff5913321c4eafa1ce53fdacebf8fb4f23bfe430))
|
|
44
|
+
|
|
45
|
+
# [0.2.0](https://github.com/AliMD/alwatr/compare/v0.1.2...v0.2.0) (2022-03-05)
|
|
46
|
+
|
|
47
|
+
**Note:** Version bump only for package @alwatr/logger
|
|
48
|
+
|
|
49
|
+
## [0.1.2](https://github.com/AliMD/alwatr/compare/v0.1.1...v0.1.2) (2022-03-03)
|
|
50
|
+
|
|
51
|
+
**Note:** Version bump only for package @alwatr/logger
|
|
52
|
+
|
|
53
|
+
## [0.1.1](https://github.com/AliMD/alwatr/compare/v0.1.0...v0.1.1) (2022-03-03)
|
|
54
|
+
|
|
55
|
+
### Bug Fixes
|
|
56
|
+
|
|
57
|
+
* **packages:** add publish config to public ([9cb3710](https://github.com/AliMD/alwatr/commit/9cb37106b5a35d24d5195ff54232e5769ccc034e))
|
|
58
|
+
|
|
59
|
+
# 0.1.0 (2022-03-02)
|
|
60
|
+
|
|
61
|
+
### Bug Fixes
|
|
62
|
+
|
|
63
|
+
* **logger:** fix debug scope ([be62f14](https://github.com/AliMD/alwatr/commit/be62f142cbe3fe4d328e3fd9941ea7c2d640a23f))
|
|
64
|
+
* **logger:** fix logger debug scope ([e734d21](https://github.com/AliMD/alwatr/commit/e734d218db888ecec33a03dc805b98dd75543efd))
|
|
65
|
+
* tsconfig issues ([159adeb](https://github.com/AliMD/alwatr/commit/159adeb72de4626dc16f6657765605b0a2ddccb1))
|
|
66
|
+
|
|
67
|
+
### Features
|
|
68
|
+
|
|
69
|
+
* **logger:** debug scope ([6e4190d](https://github.com/AliMD/alwatr/commit/6e4190dc9dafc28e3a7a481aa43622a23527993c))
|
|
70
|
+
* **logger:** debug scope logger package ([1a4baeb](https://github.com/AliMD/alwatr/commit/1a4baeb7a253ba66563dbcf06079242dabb9f246))
|
|
71
|
+
* **logger:** alwatr logger package ([711268e](https://github.com/AliMD/alwatr/commit/711268e17dea8ada9c901ef1e9d605b3212abd97))
|
|
72
|
+
* **logger:** alwatr meta structure ([feade73](https://github.com/AliMD/alwatr/commit/feade735a6f141db77b81d7791d8872d45c8bf7e))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 S. Ali Mihandoost
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# @alwatr/logger
|
|
2
|
+
|
|
3
|
+
Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.
|
|
4
|
+
|
|
5
|
+
## Example usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createLogger } from 'https://esm.run/@alwatr/logger';
|
|
9
|
+
|
|
10
|
+
const logger = createLogger('demo');
|
|
11
|
+
|
|
12
|
+
function sayHello (name: string) {
|
|
13
|
+
logger.logMethodArgs('sayHello', {name});
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Debug Mode
|
|
18
|
+
|
|
19
|
+
Many of the methods in the logger are no-ops when the debug mode is off.
|
|
20
|
+
Please remember to **reload** the window after changing the debug mode.
|
|
21
|
+
|
|
22
|
+
- Debugging all scopes
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
window.localStorage?.setItem('ALWATR_LOG', '*');
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- Debugging specific scope
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
window.localStorage?.setItem('ALWATR_LOG', 'scope_name');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- Debugging some scopes with pattern
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
window.localStorage?.setItem('ALWATR_LOG', '*alwatr*');
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### API
|
|
41
|
+
|
|
42
|
+
### Prepare the logger
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import {createLogger} from 'https://esm.run/@alwatr/logger';
|
|
46
|
+
const logger = createLogger('logger/demo', 'green');
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### `logProperty(property, value)`
|
|
50
|
+
|
|
51
|
+
`console.debug` property change.
|
|
52
|
+
|
|
53
|
+
Example:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
logger.logProperty('name', 'ali');
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### `logMethod(method)`
|
|
60
|
+
|
|
61
|
+
`console.debug` function or method calls.
|
|
62
|
+
|
|
63
|
+
Example:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
function myMethod () {
|
|
67
|
+
logger.logMethod('myMethod');
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### `logMethodArgs(method, args)`
|
|
72
|
+
|
|
73
|
+
`console.debug` function or method calls with arguments.
|
|
74
|
+
|
|
75
|
+
Example:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
function myMethod (a: number, b: number) {
|
|
79
|
+
logger.logMethodArgs('myMethod', {a, b});
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### `logMethodFull(method, args, result)`
|
|
84
|
+
|
|
85
|
+
`console.debug` function or method calls with arguments.
|
|
86
|
+
|
|
87
|
+
Example:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
function add (a: number, b: number): number {
|
|
91
|
+
const result = a + b;
|
|
92
|
+
logger.logMethodFull('add', {a, b}, result);
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### `incident(method, code, description, ...args)`
|
|
98
|
+
|
|
99
|
+
`console.trace` an event or expected accident. (not warn or error)
|
|
100
|
+
|
|
101
|
+
Example:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
logger.incident('fetch', 'abort_signal', 'aborted signal received', {url: '/test.json'});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### `accident(method, code, description, ...args)`
|
|
108
|
+
|
|
109
|
+
`console.warn` an unexpected accident or error that you handled.
|
|
110
|
+
|
|
111
|
+
Example:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
logger.accident('fetch', 'file_not_found', 'url requested return 404 not found', {url: '/test.json'});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### `error(method, code, errorStack, ...args)`
|
|
118
|
+
|
|
119
|
+
`console.error` an unexpected error.
|
|
120
|
+
|
|
121
|
+
Example:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
try {
|
|
125
|
+
...
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
logger.error('myMethod', 'error_code', (err as Error).stack || err, {a: 1, b: 2});
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `logOther(...args)`
|
|
133
|
+
|
|
134
|
+
Simple `console.debug` with styled scope.
|
|
135
|
+
|
|
136
|
+
Example:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
logger.logOther('foo:', 'bar', {a: 1});
|
|
140
|
+
```
|
package/logger.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Logger } from './type';
|
|
2
|
+
/**
|
|
3
|
+
* Define `window.Alwatr.registeredList`
|
|
4
|
+
*/
|
|
5
|
+
export declare const alwatrRegisteredList: {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
}[];
|
|
9
|
+
export declare const style: {
|
|
10
|
+
scope: string;
|
|
11
|
+
reset: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Create a logger function for fancy console debug with custom scope.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const logger = createLogger('demo');
|
|
18
|
+
* function sayHello (name: string) {
|
|
19
|
+
* logger.logMethodArgs('sayHello', {name});
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export declare const createLogger: (scope: string, color?: string, force?: boolean) => Logger;
|
|
23
|
+
//# sourceMappingURL=logger.d.ts.map
|
package/logger.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;GAAsC,CAAC;AAoExE,eAAO,MAAM,KAAK;;;CAGjB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,UACd,MAAM,UACN,MAAM,sBAEd,MAsGF,CAAC"}
|
package/logger.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var _a, _b, _c, _d;
|
|
2
|
+
/**
|
|
3
|
+
* Define `window.Alwatr.registeredList`
|
|
4
|
+
*/
|
|
5
|
+
export const alwatrRegisteredList = ((_a = window.Alwatr) === null || _a === void 0 ? void 0 : _a.registeredList) || [];
|
|
6
|
+
(_b = window.Alwatr) !== null && _b !== void 0 ? _b : (window.Alwatr = {});
|
|
7
|
+
window.Alwatr.registeredList = alwatrRegisteredList;
|
|
8
|
+
alwatrRegisteredList.push({
|
|
9
|
+
name: '@alwatr/logger',
|
|
10
|
+
version: '{{ALWATR_VERSION}}', // TODO: replace with real version at release time.
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Color list storage for logger.
|
|
14
|
+
*/
|
|
15
|
+
let colorIndex = 0;
|
|
16
|
+
const colorList = [
|
|
17
|
+
'#f05561',
|
|
18
|
+
'#35b997',
|
|
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
|
+
const getNextColor = () => {
|
|
34
|
+
const color = colorList[colorIndex];
|
|
35
|
+
colorIndex++;
|
|
36
|
+
if (colorIndex >= colorList.length) {
|
|
37
|
+
colorIndex = 0;
|
|
38
|
+
}
|
|
39
|
+
return color;
|
|
40
|
+
};
|
|
41
|
+
const debugString = (_d = (_c = window.localStorage) === null || _c === void 0 ? void 0 : _c.getItem('ALWATR_LOG')) === null || _d === void 0 ? void 0 : _d.trim();
|
|
42
|
+
const getDebugState = (scope, force) => {
|
|
43
|
+
if (debugString == null ||
|
|
44
|
+
debugString == '') {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (force ||
|
|
48
|
+
debugString === scope ||
|
|
49
|
+
(debugString.indexOf('*') === 0 && // starts with `*` for example: `*alwatr*`
|
|
50
|
+
scope.indexOf(debugString.replaceAll('*', '')) !== -1) ||
|
|
51
|
+
(debugString.indexOf('*') === debugString.length - 1 && // ends with `*` for example: `alwatr/*`
|
|
52
|
+
scope.indexOf(debugString.replaceAll('*', '')) === 0)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
// else
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
export const style = {
|
|
59
|
+
scope: 'color: {{color}};',
|
|
60
|
+
reset: 'color: inherit;',
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Create a logger function for fancy console debug with custom scope.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const logger = createLogger('demo');
|
|
67
|
+
* function sayHello (name: string) {
|
|
68
|
+
* logger.logMethodArgs('sayHello', {name});
|
|
69
|
+
* }
|
|
70
|
+
*/
|
|
71
|
+
export const createLogger = (scope, color = getNextColor(), force = false) => {
|
|
72
|
+
scope = scope.trim();
|
|
73
|
+
const debug = getDebugState(scope, force);
|
|
74
|
+
const first = scope.charAt(0);
|
|
75
|
+
if (first !== '[' && first !== '{' && first !== '(' && first !== '<') {
|
|
76
|
+
scope = '[' + scope + ']';
|
|
77
|
+
}
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
79
|
+
const empty = () => { };
|
|
80
|
+
const styleScope = style.scope.replaceAll('{{color}}', color);
|
|
81
|
+
/**
|
|
82
|
+
* Required logger object, accident, error always reported even when the debug is false.
|
|
83
|
+
*/
|
|
84
|
+
const requiredItems = {
|
|
85
|
+
color,
|
|
86
|
+
scope,
|
|
87
|
+
accident: console.warn.bind(console, '%c%s%c.%s => Accident: "%s" (%s)!', styleScope, scope, style.reset),
|
|
88
|
+
error: console.error.bind(console, '%c%s%c.%s "%s" =>', styleScope, scope, style.reset),
|
|
89
|
+
};
|
|
90
|
+
if (!debug) {
|
|
91
|
+
return {
|
|
92
|
+
...requiredItems,
|
|
93
|
+
logProperty: empty,
|
|
94
|
+
logMethod: empty,
|
|
95
|
+
logMethodArgs: empty,
|
|
96
|
+
logMethodFull: empty,
|
|
97
|
+
incident: empty,
|
|
98
|
+
logOther: empty,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
// else if debug is true for this scope
|
|
102
|
+
return {
|
|
103
|
+
...requiredItems,
|
|
104
|
+
logProperty: console.debug.bind(console, '%c%s%c.%s = %o;', styleScope, scope, style.reset),
|
|
105
|
+
logMethod: console.debug.bind(console, '%c%s%c.%s();', styleScope, scope, style.reset),
|
|
106
|
+
logMethodArgs: console.debug.bind(console, '%c%s%c.%s(%o);', styleScope, scope, style.reset),
|
|
107
|
+
logMethodFull: console.debug.bind(console, '%c%s%c.%s(%o); // %o', styleScope, scope, style.reset),
|
|
108
|
+
incident: console.trace.bind(console, '%c%s%c.%s() => Incident: "%s" (%s)!', styleScope, scope, style.reset),
|
|
109
|
+
logOther: console.debug.bind(console, '%c%s', styleScope, scope),
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=logger.js.map
|
package/logger.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":";AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAA,MAAA,MAAM,CAAC,MAAM,0CAAE,cAAc,KAAI,EAAE,CAAC;AACxE,MAAA,MAAM,CAAC,MAAM,oCAAb,MAAM,CAAC,MAAM,GAAK,EAAE,EAAC;AACrB,MAAM,CAAC,MAAM,CAAC,cAAc,GAAG,oBAAoB,CAAC;AAEpD,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;IAChB,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC;AAEF,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,CAAC;KAChB;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,MAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,OAAO,CAAC,YAAY,CAAC,0CAAE,IAAI,EAAE,CAAC;AACvE,MAAM,aAAa,GAAG,CAAC,KA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AAK,CAAC,IAAI,CACxB,OAAO,EACP,qCAAqC,EACrC,UAAU,EACV,KAAK,EACL,KAAK,CAAC,KAAK,CACd;QAED,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CACxB,OAAO,EACP,MAAM,EACN,UAAU,EACV,KAAK,CACR;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alwatr/logger",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"log",
|
|
7
|
+
"logger",
|
|
8
|
+
"console",
|
|
9
|
+
"debug",
|
|
10
|
+
"typescript",
|
|
11
|
+
"esm",
|
|
12
|
+
"alwatr"
|
|
13
|
+
],
|
|
14
|
+
"main": "logger.js",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"types": "logger.d.ts",
|
|
17
|
+
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"files": [
|
|
20
|
+
"**/*.js",
|
|
21
|
+
"**/*.d.ts",
|
|
22
|
+
"**/*.map",
|
|
23
|
+
"**/*.html",
|
|
24
|
+
"**/*.md"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/AliMD/alwatr",
|
|
32
|
+
"directory": "package/logger"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/AliMD/alwatr/tree/main/package/logger#readme",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/AliMD/alwatr/issues"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"tslib": "^2.3.1"
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "8ed13adce22d7bb0cc24eb17c9f8ecfb6bbe8553"
|
|
42
|
+
}
|
package/type.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
Alwatr?: {
|
|
4
|
+
registeredList?: Array<{
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @TODO: Make an issue to TS, WTF is this way! any better solution for more args in bind?!
|
|
12
|
+
*/
|
|
13
|
+
interface CallableFunction {
|
|
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
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export interface Logger {
|
|
18
|
+
readonly color: string;
|
|
19
|
+
readonly scope: string;
|
|
20
|
+
/**
|
|
21
|
+
* `console.debug` property change.
|
|
22
|
+
*
|
|
23
|
+
* Example:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* logger.logProperty('name', 'ali');
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
logProperty(property: string, value: unknown): void;
|
|
30
|
+
/**
|
|
31
|
+
* `console.debug` function or method calls.
|
|
32
|
+
*
|
|
33
|
+
* Example:
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* function myMethod () {
|
|
37
|
+
* logger.logMethod('myMethod');
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
logMethod(method: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* `console.debug` function or method calls with arguments.
|
|
44
|
+
*
|
|
45
|
+
* Example:
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* function myMethod (a: number, b: number) {
|
|
49
|
+
* logger.logMethodArgs('myMethod', {a, b});
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
logMethodArgs(method: string, args: Record<string, unknown> | string | number | boolean): void;
|
|
54
|
+
/**
|
|
55
|
+
* `console.debug` function or method calls with arguments.
|
|
56
|
+
*
|
|
57
|
+
* Example:
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* function add (a: number, b: number): number {
|
|
61
|
+
* const result = a + b;
|
|
62
|
+
* logger.logMethodFull('add', {a, b}, result);
|
|
63
|
+
* return result;
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
logMethodFull(method: string, args: Record<string, unknown> | string | number | boolean, result: unknown): void;
|
|
68
|
+
/**
|
|
69
|
+
* `console.trace` an event or expected accident. (not warn or error)
|
|
70
|
+
*
|
|
71
|
+
* Example:
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* logger.incident('fetch', 'abort_signal', 'aborted signal received', {url: '/test.json'});
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
incident(method: string, code: string, desc: string, ...args: unknown[]): void;
|
|
78
|
+
/**
|
|
79
|
+
* `console.warn` an unexpected accident or error that you handled.
|
|
80
|
+
*
|
|
81
|
+
* Example:
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* logger.accident('fetch', 'file_not_found', 'url requested return 404 not found', {url: '/test.json'});
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
accident(method: string, code: string, desc: string, ...args: unknown[]): void;
|
|
88
|
+
/**
|
|
89
|
+
* `console.error` an unexpected error.
|
|
90
|
+
*
|
|
91
|
+
* Example:
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* try {
|
|
95
|
+
* ...
|
|
96
|
+
* }
|
|
97
|
+
* catch (err) {
|
|
98
|
+
* logger.error('myMethod', 'error_code', (err as Error).stack || err, {a: 1, b: 2});
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
error(method: string, code: string, errorStack: string | unknown, ...args: unknown[]): void;
|
|
103
|
+
/**
|
|
104
|
+
* Simple `console.debug` with styled scope.
|
|
105
|
+
*
|
|
106
|
+
* Example:
|
|
107
|
+
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* logger.logOther('foo:', 'bar', {a: 1});
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
logOther(...args: unknown[]): void;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=type.d.ts.map
|
package/type.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,CAAC,EAAE;YACP,cAAc,CAAC,EAAE,KAAK,CAAC;gBACrB,IAAI,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,CAAC;aACjB,CAAC,CAAC;SACJ,CAAA;KACF;IAED;;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,EAC/C,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,KACxE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,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