@alwatr/logger 5.6.1 → 6.0.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 +34 -0
- package/README.md +380 -38
- package/dist/logger.d.ts +7 -6
- package/dist/logger.d.ts.map +1 -1
- package/dist/main.cjs +38 -39
- package/dist/main.cjs.map +2 -2
- package/dist/main.mjs +38 -39
- package/dist/main.mjs.map +2 -2
- package/dist/type.d.ts +19 -0
- package/dist/type.d.ts.map +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,40 @@
|
|
|
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
|
+
## [6.0.0](https://github.com/Alwatr/nanolib/compare/@alwatr/logger@5.6.2...@alwatr/logger@6.0.0) (2025-09-14)
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
* Internal logger config keys renamed and Color API now returns normalized values; callers must update config and run tests.
|
|
11
|
+
|
|
12
|
+
با توکل بر خدا آپدیت کنید طوری نمیشه انشاالله
|
|
13
|
+
|
|
14
|
+
### ✨ Features
|
|
15
|
+
|
|
16
|
+
* add logTable method to AlwatrLogger interface and implement in createLogger ([33682dd](https://github.com/Alwatr/nanolib/commit/33682dde84814b121234e58a97de300d4f8b09ee))
|
|
17
|
+
|
|
18
|
+
### 🐛 Bug Fixes
|
|
19
|
+
|
|
20
|
+
* access self in logger ([4898e2a](https://github.com/Alwatr/nanolib/commit/4898e2ab42482662444fede6459284004fe2ec9e))
|
|
21
|
+
* change logTable parameter type from any to unknown for better type safety ([8f7d632](https://github.com/Alwatr/nanolib/commit/8f7d632139d0387af224b7779b3f8e3d7c061791))
|
|
22
|
+
* correct regex in sanitizeDomain function to properly validate domain format ([831c56d](https://github.com/Alwatr/nanolib/commit/831c56d2cb77a6d8b053121cd4a034bb060b82e1))
|
|
23
|
+
* replace globalThis initialization with getGlobalThis for improved consistency ([dff4090](https://github.com/Alwatr/nanolib/commit/dff40901f060815ff0f8800487a7bb091c2367ff))
|
|
24
|
+
* update default debug mode logic to include NODE_ENV check for CLI environments ([c334071](https://github.com/Alwatr/nanolib/commit/c33407167a4be02b450249d985f43daac46b52f0))
|
|
25
|
+
|
|
26
|
+
### 🔨 Code Refactoring
|
|
27
|
+
|
|
28
|
+
* enhance logger configuration and improve color handling ([7ab540d](https://github.com/Alwatr/nanolib/commit/7ab540dc5ac81561810ab1e6922b80be617f8dd6))
|
|
29
|
+
|
|
30
|
+
### 🧹 Miscellaneous Chores
|
|
31
|
+
|
|
32
|
+
* remove unnecessary types from tsconfig.json for cleaner configuration ([986afde](https://github.com/Alwatr/nanolib/commit/986afde2dc976cf69f550f715d74fc5eb7a96086))
|
|
33
|
+
|
|
34
|
+
## [5.6.2](https://github.com/Alwatr/nanolib/compare/@alwatr/logger@5.6.1...@alwatr/logger@5.6.2) (2025-09-13)
|
|
35
|
+
|
|
36
|
+
### 🔗 Dependencies update
|
|
37
|
+
|
|
38
|
+
* update @types/node version to ^22.18.3 in multiple package.json files ([13db6fc](https://github.com/Alwatr/nanolib/commit/13db6fc176bc6cdcefedc50d77ac550bd5052c9a))
|
|
39
|
+
|
|
6
40
|
## [5.6.1](https://github.com/Alwatr/nanolib/compare/@alwatr/logger@5.6.0...@alwatr/logger@5.6.1) (2025-09-13)
|
|
7
41
|
|
|
8
42
|
### 🧹 Miscellaneous Chores
|
package/README.md
CHANGED
|
@@ -1,79 +1,421 @@
|
|
|
1
|
-
|
|
1
|
+
# Alwatr Logger
|
|
2
2
|
|
|
3
|
-
A lightweight, flexible, and colorful console logging library for TypeScript and
|
|
3
|
+
**A lightweight, flexible, and colorful console logging library for TypeScript and modern JavaScript.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`@alwatr/logger` is designed to enhance the debugging experience by providing a structured, colorful, and highly customizable logging utility. It helps you organize log messages with custom scopes, control verbosity for different environments, and easily trace application flow from method calls to incidents and errors.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
[](https://www.google.com/search?q=https://www.npmjs.com/package/%40alwatr/logger)
|
|
8
|
+
[](https://www.google.com/search?q=https://www.npmjs.com/package/%40alwatr/nanolib)
|
|
9
|
+
[](https://www.google.com/search?q=alwatr+logger)
|
|
10
|
+
[](https://www.google.com/search?q=alwatr+nanolib)
|
|
11
|
+
[](https://www.google.com/search?q=alwatr)
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Accurate Call Site Reporting:** The browser's developer console correctly displays the file and line number where the logger is called in **your code**, not from within the logger's internal source. This makes debugging intuitive and directs you straight to the relevant line in your own codebase.
|
|
16
|
+
- **Customizable Scopes:** Organize log messages using scopes for easy filtering and debugging. Each logger instance gets a unique, persistent color.
|
|
17
|
+
- **Colorful Output:** Visually distinguish different log levels and scopes with vibrant, automatically assigned colors, optimized for both browser and terminal environments.
|
|
18
|
+
- **Debug/Development Mode:** Automatically enables detailed logging in development environments and disables it in production to optimize performance. Can be manually overridden.
|
|
19
|
+
- **Structured Logging Methods:** Provides a rich set of methods (`logMethod`, `logMethodArgs`, `incident`, `accident`, `error`, etc.) to log different types of events in a structured way.
|
|
20
|
+
- **Tiny Footprint:** Minimal overhead, keeping your project lean and efficient. It's a zero-dependency library.
|
|
21
|
+
- **Cross-Platform:** Works seamlessly in both Node.js and browser environments.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
13
26
|
|
|
14
27
|
```bash
|
|
15
28
|
npm install @alwatr/logger
|
|
16
29
|
```
|
|
17
30
|
|
|
18
|
-
|
|
31
|
+
or using yarn:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
yarn add @alwatr/logger
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
### Basic Usage
|
|
42
|
+
|
|
43
|
+
First, create a logger instance with a unique scope. This scope will prefix all messages logged by this instance.
|
|
19
44
|
|
|
20
45
|
```typescript
|
|
21
46
|
import {createLogger} from '@alwatr/logger';
|
|
22
47
|
|
|
23
|
-
|
|
48
|
+
// Create a logger with a specific scope
|
|
49
|
+
const logger = createLogger('my-app:main');
|
|
24
50
|
|
|
25
51
|
function greet(name: string) {
|
|
26
|
-
|
|
52
|
+
// Log the method call with its arguments
|
|
53
|
+
logger.logMethodArgs?.('greet', {name});
|
|
54
|
+
|
|
55
|
+
if (!name) {
|
|
56
|
+
// Log an unexpected incident (a warning)
|
|
57
|
+
logger.accident('greet', 'name_is_empty', 'Guest name was not provided.');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
27
61
|
console.log(`Hello, ${name}!`);
|
|
28
62
|
}
|
|
29
63
|
|
|
30
64
|
greet('Ali');
|
|
65
|
+
greet('');
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Advanced Usage Examples
|
|
69
|
+
|
|
70
|
+
Here is a demonstration of various logging methods available.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import {createLogger} from '@alwatr/logger';
|
|
74
|
+
|
|
75
|
+
const logger = createLogger('api-service');
|
|
76
|
+
|
|
77
|
+
// 1. Banner: For important announcements
|
|
78
|
+
logger.banner('API Service Initialized - v2.0');
|
|
79
|
+
|
|
80
|
+
// 2. Log Property: Track state changes
|
|
81
|
+
let userState = {loggedIn: false};
|
|
82
|
+
logger.logProperty?.('userState', userState);
|
|
83
|
+
userState.loggedIn = true;
|
|
84
|
+
logger.logProperty?.('userState', userState);
|
|
85
|
+
|
|
86
|
+
// 3. Log Method & Arguments: Trace function calls
|
|
87
|
+
function fetchData(url: string, options: Record<string, any>) {
|
|
88
|
+
logger.logMethodArgs?.('fetchData', {url, options});
|
|
89
|
+
|
|
90
|
+
// 4. Incident: Log expected, non-critical events
|
|
91
|
+
if (options.retries > 0) {
|
|
92
|
+
logger.incident?.('fetchData', 'retry_attempt', `Retrying... attempt ${options.retries}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 5. Error: Log critical errors
|
|
96
|
+
try {
|
|
97
|
+
throw new Error('Network request failed');
|
|
98
|
+
} catch (err) {
|
|
99
|
+
logger.error('fetchData', 'network_failure', err, {url});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fetchData('/api/data', {retries: 1});
|
|
31
104
|
```
|
|
32
105
|
|
|
33
|
-
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## API Reference
|
|
109
|
+
|
|
110
|
+
The `createLogger` function returns a logger instance with the following methods. Methods marked with `?` (optional chaining) are only available when `debugMode` is `true`.
|
|
111
|
+
|
|
112
|
+
- **`debugMode: boolean`**
|
|
113
|
+
Indicates if debug mode is active.
|
|
114
|
+
|
|
115
|
+
- **`banner(message: string)`**
|
|
116
|
+
Logs a large, prominent banner message. Useful for versioning or startup messages.
|
|
117
|
+
|
|
118
|
+
- **`logProperty?(propertyName: string, value: unknown)`**
|
|
119
|
+
Logs a property name and its value. Ideal for tracking state.
|
|
120
|
+
|
|
121
|
+
- **`logMethod?(methodName: string)`**
|
|
122
|
+
Logs the entry into a function or method.
|
|
123
|
+
|
|
124
|
+
- **`logMethodArgs?(methodName: string, args: unknown)`**
|
|
125
|
+
Logs a method call along with its arguments.
|
|
126
|
+
|
|
127
|
+
- **`logMethodFull?(methodName: string, args: unknown, result: unknown)`**
|
|
128
|
+
Logs a method call with its arguments and the returned result.
|
|
129
|
+
|
|
130
|
+
- **`logStep?(methodName: string, stepName: string, props?: unknown)`**
|
|
131
|
+
Logs specific steps within a method, useful for tracking progress in complex functions.
|
|
132
|
+
|
|
133
|
+
- **`incident?(methodName:string, code: string, ...args: unknown[])`**
|
|
134
|
+
Logs an expected event or incident (informational). This uses `console.log` and is styled to be noticeable but not alarming.
|
|
135
|
+
_Example: A user cancels a request._
|
|
34
136
|
|
|
35
|
-
- **`
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- **`logMethodArgs(methodName, args)`:** Logs a method call with its arguments.
|
|
39
|
-
- **`logStep(methodName, stepName, props?)`:** Logs specific steps within a method.
|
|
40
|
-
- **`logMethodFull(methodName, args, result)`:** Logs a method call with arguments and result.
|
|
41
|
-
- **`incident(methodName, code, ...args)`:** Logs an event or expected incident (informational).
|
|
42
|
-
- **`accident(methodName, code, ...args)`:** Logs an unexpected incident or handled error (warning).
|
|
43
|
-
- **`error(methodName, code, ...args)`:** Logs an unexpected error (critical).
|
|
44
|
-
- **`logOther(...args)`:** General-purpose logging with styled scope.
|
|
45
|
-
- **`time(label)`:** Starts a timer.
|
|
46
|
-
- **`timeEnd(label)`:** Ends a timer and logs the elapsed time.
|
|
47
|
-
- **`banner(message)`:** Logs a large, prominent banner message.
|
|
137
|
+
- **`accident(methodName: string, code: string, ...args: unknown[])`**
|
|
138
|
+
Logs an unexpected incident or a handled error (warning) using `console.warn`.
|
|
139
|
+
_Example: A file was not found, but the application can recover._
|
|
48
140
|
|
|
49
|
-
|
|
141
|
+
- **`error(methodName: string, code: string, ...args: unknown[])`**
|
|
142
|
+
Logs a critical, unexpected error using `console.error`.
|
|
143
|
+
_Example: A database connection fails._
|
|
50
144
|
|
|
51
|
-
|
|
145
|
+
- **`logOther?(...args: unknown[])`**
|
|
146
|
+
A general-purpose logger with the standard scope styling.
|
|
147
|
+
|
|
148
|
+
- **`time?(label: string)`** / **`timeEnd?(label: string)`**
|
|
149
|
+
Starts and ends a timer to measure performance. The label is automatically prefixed with the logger's scope.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Best Practices
|
|
154
|
+
|
|
155
|
+
1. **Use Meaningful Scopes:**
|
|
156
|
+
Choose descriptive scopes to easily identify the source of logs. A good practice is to use the module or component path, e.g., `app:http-client`, `ui:user-form`.
|
|
157
|
+
|
|
158
|
+
2. **Log Arguments and Results in Development:**
|
|
159
|
+
Use `logMethodArgs` and `logMethodFull` generously during development. Since they are stripped in production builds, they won't impact performance.
|
|
160
|
+
|
|
161
|
+
3. **Distinguish Between `incident`, `accident`, and `error`:**
|
|
162
|
+
- **`incident`**: For events that are part of the normal application flow but are worth noting (e.g., cache miss, user abort).
|
|
163
|
+
- **`accident`**: For handled errors or unexpected situations where the app can recover (e.g., failed API call with a retry mechanism).
|
|
164
|
+
- **`error`**: For critical failures that disrupt functionality and require immediate attention.
|
|
165
|
+
|
|
166
|
+
4. **Keep Production Logs Clean:**
|
|
167
|
+
Rely on `accident` and `error` for production logs. These are always active and highlight important issues without the noise of debug messages.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Enabling Debug Mode
|
|
172
|
+
|
|
173
|
+
Debug logs are enabled by default if `NODE_ENV` is `development`. You can manually control it as follows:
|
|
174
|
+
|
|
175
|
+
### Browser
|
|
52
176
|
|
|
53
177
|
1. Open your browser's developer tools.
|
|
54
|
-
2. Go to the "Application"
|
|
55
|
-
3.
|
|
56
|
-
4.
|
|
57
|
-
5. Reload the page.
|
|
178
|
+
2. Go to the "Application" tab.
|
|
179
|
+
3. Under "Local Storage," add a new key `ALWATR_DEBUG` with the value `1`.
|
|
180
|
+
4. Reload the page.
|
|
58
181
|
|
|
59
|
-
|
|
182
|
+
Alternatively, run this in the console:
|
|
60
183
|
|
|
61
184
|
```javascript
|
|
62
|
-
window.localStorage
|
|
185
|
+
window.localStorage.setItem('ALWATR_DEBUG', '1');
|
|
63
186
|
```
|
|
64
187
|
|
|
65
188
|
> **Note:** Ensure the browser console's log level is set to include "Verbose" or "All" to see debug messages.
|
|
66
189
|
|
|
67
|
-
|
|
190
|
+
### Node.js
|
|
191
|
+
|
|
192
|
+
Set the `DEBUG` environment variable to `1` when running your application:
|
|
68
193
|
|
|
69
194
|
```bash
|
|
70
195
|
DEBUG=1 node index.js
|
|
71
196
|
```
|
|
72
197
|
|
|
73
|
-
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Contributing
|
|
201
|
+
|
|
202
|
+
Contributions are welcome\! Please read our [contribution guidelines](https://github.com/Alwatr/.github/blob/next/CONTRIBUTING.md) before submitting a pull request.
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
This project is licensed under the [MPL-2.0 License](https://www.google.com/search?q=LICENSE).
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
<br>
|
|
211
|
+
<br>
|
|
212
|
+
<div dir="rtl">
|
|
213
|
+
|
|
214
|
+
# Alwatr Logger (راهنمای فارسی)
|
|
215
|
+
|
|
216
|
+
**یک کتابخانه لاگ (گزارشگیری) سبک، انعطافپذیر و رنگارنگ برای کنسول، مخصوص تایپاسکریپت و جاوااسکریپت مدرن.**
|
|
217
|
+
|
|
218
|
+
کتابخانه `@alwatr/logger` برای بهبود تجربه دیباگ کردن طراحی شده است. این ابزار با فراهم کردن یک سیستم لاگگیری ساختاریافته، رنگی و کاملاً قابل تنظیم به شما کمک میکند تا پیامهای لاگ را با استفاده از حوزههای (scopes) سفارشی سازماندهی کنید، سطح جزئیات لاگها را برای محیطهای مختلف کنترل کرده و جریان اجرای برنامه را از فراخوانی متدها گرفته تا رخدادها و خطاها به راحتی ردیابی کنید.
|
|
219
|
+
|
|
220
|
+
## ویژگیها
|
|
221
|
+
|
|
222
|
+
- **گزارش دقیق محل فراخوانی:** کنسول توسعهدهندگان مرورگر (DevTools)، آدرس فایل و شماره خطی که لاگر در **کد شما** فراخوانی شده است را به درستی نمایش میدهد و نه فایلهای داخلی خود کتابخانه را. این ویژگی دیباگ کردن را بسیار مستقیم و آسان میکند و شما را مستقیماً به خط مورد نظر در کد خودتان هدایت میکند.
|
|
223
|
+
- **حوزههای قابل تنظیم (Customizable Scopes):** پیامهای لاگ را با استفاده از حوزهها سازماندهی کنید تا فیلتر کردن و دیباگ کردن آسانتر شود. هر نمونه از لاگر یک رنگ منحصر به فرد و ثابت دریافت میکند.
|
|
224
|
+
- **خروجی رنگی:** سطوح مختلف لاگ و حوزهها را با رنگهای زنده و اختصاصی از یکدیگر متمایز کنید. این رنگها برای هر دو محیط مرورگر و ترمینال بهینهسازی شدهاند.
|
|
225
|
+
- **حالت توسعه/دیباگ (Debug/Development Mode):** به طور خودکار لاگهای دقیق را در محیط توسعه فعال کرده و در محیط پروداکشن برای بهینهسازی عملکرد، غیرفعال میکند. این رفتار قابل تغییر است.
|
|
226
|
+
- **متدهای لاگگیری ساختاریافته:** مجموعهای غنی از متدها (`logMethod`, `logMethodArgs`, `incident`, `accident`, `error` و غیره) برای ثبت انواع مختلف رویدادها به صورت ساختاریافته فراهم میکند.
|
|
227
|
+
- **حجم بسیار کم (Tiny Footprint):** سربار بسیار کمی دارد و پروژه شما را سبک و کارآمد نگه میدارد. این کتابخانه هیچ وابستگی خارجی ندارد.
|
|
228
|
+
- **چندسکویی (Cross-Platform):** به صورت یکپارچه در محیطهای Node.js و مرورگر کار میکند.
|
|
229
|
+
|
|
230
|
+
[](https://www.google.com/search?q=https://www.npmjs.com/package/%40alwatr/logger)
|
|
231
|
+
[](https://www.google.com/search?q=https://www.npmjs.com/package/%40alwatr/nanolib)
|
|
232
|
+
[](https://www.google.com/search?q=alwatr+logger)
|
|
233
|
+
[](https://www.google.com/search?q=alwatr+nanolib)
|
|
234
|
+
[](https://www.google.com/search?q=alwatr)
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## نصب و راهاندازی
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
npm install @alwatr/logger
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
یا با استفاده از yarn:
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
yarn add @alwatr/logger
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## نحوه استفاده
|
|
253
|
+
|
|
254
|
+
### استفاده پایه
|
|
255
|
+
|
|
256
|
+
ابتدا، یک نمونه لاگر با یک حوزه (scope) منحصر به فرد ایجاد کنید. این حوزه به ابتدای تمام پیامهایی که توسط این نمونه ثبت میشوند، اضافه خواهد شد.
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import {createLogger} from '@alwatr/logger';
|
|
260
|
+
|
|
261
|
+
// ساخت یک لاگر با یک حوزه مشخص
|
|
262
|
+
const logger = createLogger('my-app:main');
|
|
263
|
+
|
|
264
|
+
function greet(name: string) {
|
|
265
|
+
// لاگ کردن فراخوانی متد به همراه آرگومانهای آن
|
|
266
|
+
logger.logMethodArgs?.('greet', {name});
|
|
267
|
+
|
|
268
|
+
if (!name) {
|
|
269
|
+
// ثبت یک رخداد غیرمنتظره (یک هشدار)
|
|
270
|
+
logger.accident('greet', 'name_is_empty', 'Guest name was not provided.');
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
console.log(`Hello, ${name}!`);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
greet('Ali');
|
|
278
|
+
greet('');
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### مثالهای پیشرفته
|
|
282
|
+
|
|
283
|
+
در اینجا نمونهای از متدهای مختلف لاگگیری موجود نمایش داده شده است.
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import {createLogger} from '@alwatr/logger';
|
|
287
|
+
|
|
288
|
+
const logger = createLogger('api-service');
|
|
289
|
+
|
|
290
|
+
// ۱. بنر (Banner): برای اطلاعیههای مهم
|
|
291
|
+
logger.banner('API Service Initialized - v2.0');
|
|
292
|
+
|
|
293
|
+
// ۲. لاگ پراپرتی (Log Property): برای ردیابی تغییرات state
|
|
294
|
+
let userState = {loggedIn: false};
|
|
295
|
+
logger.logProperty?.('userState', userState);
|
|
296
|
+
userState.loggedIn = true;
|
|
297
|
+
logger.logProperty?.('userState', userState);
|
|
298
|
+
|
|
299
|
+
// ۳. لاگ متد و آرگومانها: برای ردیابی فراخوانی توابع
|
|
300
|
+
function fetchData(url: string, options: Record<string, any>) {
|
|
301
|
+
logger.logMethodArgs?.('fetchData', {url, options});
|
|
302
|
+
|
|
303
|
+
// ۴. رخداد (Incident): برای ثبت رویدادهای قابل انتظار و غیربحرانی
|
|
304
|
+
if (options.retries > 0) {
|
|
305
|
+
logger.incident?.('fetchData', 'retry_attempt', `Retrying... attempt ${options.retries}`);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// ۵. خطا (Error): برای ثبت خطاهای بحرانی
|
|
309
|
+
try {
|
|
310
|
+
throw new Error('Network request failed');
|
|
311
|
+
} catch (err) {
|
|
312
|
+
logger.error('fetchData', 'network_failure', err, {url});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
fetchData('/api/data', {retries: 1});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## مستندات API
|
|
322
|
+
|
|
323
|
+
تابع `createLogger` یک نمونه لاگر با متدهای زیر برمیگرداند. متدهایی که با `?` (optional chaining) مشخص شدهاند، تنها زمانی در دسترس هستند که `debugMode` فعال باشد.
|
|
324
|
+
|
|
325
|
+
- **`debugMode: boolean`**
|
|
326
|
+
نشان میدهد که آیا حالت دیباگ فعال است یا خیر.
|
|
327
|
+
|
|
328
|
+
- **`banner(message: string)`**
|
|
329
|
+
یک پیام بزرگ و برجسته را لاگ میکند. برای نمایش نسخه یا پیامهای زمان راهاندازی مفید است.
|
|
330
|
+
|
|
331
|
+
- **`logProperty?(propertyName: string, value: unknown)`**
|
|
332
|
+
نام یک پراپرتی و مقدار آن را لاگ میکند. برای ردیابی state ایدهآل است.
|
|
333
|
+
|
|
334
|
+
- **`logMethod?(methodName: string)`**
|
|
335
|
+
ورود به یک تابع یا متد را لاگ میکند.
|
|
336
|
+
|
|
337
|
+
- **`logMethodArgs?(methodName: string, args: unknown)`**
|
|
338
|
+
فراخوانی یک متد را به همراه آرگومانهای آن لاگ میکند.
|
|
339
|
+
|
|
340
|
+
- **`logMethodFull?(methodName: string, args: unknown, result: unknown)`**
|
|
341
|
+
فراخوانی یک متد را به همراه آرگومانها و مقدار بازگشتی آن لاگ میکند.
|
|
342
|
+
|
|
343
|
+
- **`logStep?(methodName: string, stepName: string, props?: unknown)`**
|
|
344
|
+
مراحل خاصی را در یک متد لاگ میکند که برای ردیابی پیشرفت در توابع پیچیده مفید است.
|
|
345
|
+
|
|
346
|
+
- **`incident?(methodName:string, code: string, ...args: unknown[])`**
|
|
347
|
+
یک رویداد یا رخداد قابل انتظار (اطلاعاتی) را لاگ میکند. این متد از `console.log` استفاده میکند و استایل آن به گونهای است که قابل توجه باشد اما نگرانکننده نباشد.
|
|
348
|
+
_مثال: کاربر یک درخواست را لغو میکند._
|
|
349
|
+
|
|
350
|
+
- **`accident(methodName: string, code: string, ...args: unknown[])`**
|
|
351
|
+
یک رخداد غیرمنتظره یا یک خطای مدیریتشده (هشدار) را با استفاده از `console.warn` لاگ میکند.
|
|
352
|
+
_مثال: یک فایل پیدا نمیشود، اما برنامه میتواند به کار خود ادامه دهد._
|
|
353
|
+
|
|
354
|
+
- **`error(methodName: string, code: string, ...args: unknown[])`**
|
|
355
|
+
یک خطای بحرانی و غیرمنتظره را با استفاده از `console.error` لاگ میکند.
|
|
356
|
+
_مثال: اتصال به پایگاه داده با شکست مواجه میشود._
|
|
357
|
+
|
|
358
|
+
- **`logOther?(...args: unknown[])`**
|
|
359
|
+
یک لاگر عمومی با استایل استاندارد حوزه (scope).
|
|
360
|
+
|
|
361
|
+
- **`time?(label: string)`** / **`timeEnd?(label: string)`**
|
|
362
|
+
یک تایمر را برای اندازهگیری عملکرد شروع و پایان میدهد. حوزه لاگر به صورت خودکار به ابتدای `label` اضافه میشود.
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
## بهترین شیوهها (Best Practices)
|
|
367
|
+
|
|
368
|
+
۱. **از حوزههای (Scopes) معنادار استفاده کنید:**
|
|
369
|
+
حوزههای توصیفی انتخاب کنید تا منبع لاگها به راحتی قابل شناسایی باشد. یک روش خوب، استفاده از مسیر ماژول یا کامپوننت است، مانند: `app:http-client` یا `ui:user-form`.
|
|
370
|
+
|
|
371
|
+
۲. **در محیط توسعه، آرگومانها و نتایج را لاگ کنید:**
|
|
372
|
+
در طول توسعه، به طور گسترده از `logMethodArgs` و `logMethodFull` استفاده کنید. از آنجایی که این لاگها در بیلد پروداکشن حذف میشوند، تأثیری بر عملکرد نخواهند داشت.
|
|
373
|
+
|
|
374
|
+
۳. **بین `incident`، `accident` و `error` تمایز قائل شوید:**
|
|
375
|
+
\- **`incident`**: برای رویدادهایی که بخشی از جریان عادی برنامه هستند اما ارزش ثبت شدن دارند (مانند cache miss یا لغو درخواست توسط کاربر).
|
|
376
|
+
\- **`accident`**: برای خطاهای مدیریتشده یا شرایط غیرمنتظرهای که برنامه میتواند از آنها بازیابی شود (مانند فراخوانی ناموفق API با مکانیزم تلاش مجدد).
|
|
377
|
+
\- **`error`**: برای شکستهای بحرانی که عملکرد را مختل کرده و نیاز به توجه فوری دارند.
|
|
378
|
+
|
|
379
|
+
۴. **لاگهای پروداکشن را تمیز نگه دارید:**
|
|
380
|
+
برای لاگهای پروداکشن به `accident` و `error` تکیه کنید. این متدها همیشه فعال هستند و مسائل مهم را بدون نویز پیامهای دیباگ برجسته میکنند.
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## فعالسازی حالت دیباگ
|
|
385
|
+
|
|
386
|
+
لاگهای دیباگ به طور پیشفرض در صورتی که `NODE_ENV` برابر با `development` باشد، فعال هستند. شما میتوانید آن را به صورت دستی کنترل کنید:
|
|
387
|
+
|
|
388
|
+
### مرورگر
|
|
389
|
+
|
|
390
|
+
۱. ابزارهای توسعهدهنده (developer tools) مرورگر خود را باز کنید.
|
|
391
|
+
۲. به تب "Application" بروید.
|
|
392
|
+
۳. در بخش "Local Storage"، یک کلید جدید با نام `ALWATR_DEBUG` و مقدار `1` اضافه کنید.
|
|
393
|
+
۴. صفحه را مجدداً بارگیری کنید.
|
|
394
|
+
|
|
395
|
+
همچنین میتوانید این کد را در کنسول اجرا کنید:
|
|
396
|
+
|
|
397
|
+
```javascript
|
|
398
|
+
window.localStorage.setItem('ALWATR_DEBUG', '1');
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
> **نکته:** اطمینان حاصل کنید که سطح لاگ کنسول مرورگر شما برای نمایش پیامهای "Verbose" یا "All" تنظیم شده باشد.
|
|
402
|
+
|
|
403
|
+
### Node.js
|
|
404
|
+
|
|
405
|
+
متغیر محیطی `DEBUG` را هنگام اجرای برنامه خود برابر `1` قرار دهید:
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
DEBUG=1 node index.js
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## مشارکت
|
|
414
|
+
|
|
415
|
+
از مشارکت شما استقبال میکنیم\! لطفاً قبل از ارسال pull request، [راهنمای مشارکت](https://github.com/Alwatr/.github/blob/next/CONTRIBUTING.md) ما را مطالعه کنید.
|
|
74
416
|
|
|
75
|
-
|
|
417
|
+
## مجوز (License)
|
|
76
418
|
|
|
77
|
-
|
|
419
|
+
این پروژه تحت مجوز [MPL-2.0 License](https://www.google.com/search?q=LICENSE) منتشر شده است.
|
|
78
420
|
|
|
79
|
-
|
|
421
|
+
</div>
|
package/dist/logger.d.ts
CHANGED
|
@@ -2,14 +2,15 @@ import type { AlwatrLogger } from './type.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Create a logger function for fancy console debug with custom scope.
|
|
4
4
|
*
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
8
|
-
* Example:
|
|
5
|
+
* - `color` is optional and automatically selected from an internal list.
|
|
6
|
+
* - `debug` is optional and automatically detected from `ALWATR_DEBUG` in localStorage or `process.env.DEBUG`.
|
|
9
7
|
*
|
|
8
|
+
* @example
|
|
10
9
|
* ```ts
|
|
11
|
-
* import {createLogger} from '
|
|
12
|
-
* const logger = createLogger('
|
|
10
|
+
* import {createLogger} from '@alwatr/logger';
|
|
11
|
+
* const logger = createLogger('my-module');
|
|
12
|
+
*
|
|
13
|
+
* logger.logMethodArgs?.('myMethod', {a: 1}); // This line is ignored if debugMode is false.
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
16
|
export declare const createLogger: (domain: string, debugMode?: boolean) => AlwatrLogger;
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AA8E5C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,mBAA4B,KAAG,YA8D3E,CAAC"}
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @alwatr/logger
|
|
1
|
+
/* @alwatr/logger v6.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -26,9 +26,11 @@ __export(main_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(main_exports);
|
|
27
27
|
|
|
28
28
|
// src/logger.ts
|
|
29
|
+
var import_global_this = require("@alwatr/global-this");
|
|
29
30
|
var import_platform_info = require("@alwatr/platform-info");
|
|
31
|
+
var console_ = (0, import_global_this.getGlobalThis)().console;
|
|
30
32
|
var defaultDebugMode = /* @__PURE__ */ (() => {
|
|
31
|
-
return import_platform_info.platformInfo.development || (import_platform_info.platformInfo.isCli ? Boolean(process.env.DEBUG) : typeof localStorage !== "undefined" && localStorage.getItem("ALWATR_DEBUG") === "1");
|
|
33
|
+
return import_platform_info.platformInfo.development || (import_platform_info.platformInfo.isCli ? process.env.NODE_ENV !== "production" || Boolean(process.env.DEBUG) : typeof localStorage !== "undefined" && localStorage.getItem("ALWATR_DEBUG") === "1");
|
|
32
34
|
})();
|
|
33
35
|
var colorList = /* @__PURE__ */ (() => import_platform_info.platformInfo.isCli ? ["0;36", "0;35", "0;34", "0;33", "0;32"] : [
|
|
34
36
|
"#35b997",
|
|
@@ -47,61 +49,58 @@ var colorList = /* @__PURE__ */ (() => import_platform_info.platformInfo.isCli ?
|
|
|
47
49
|
"#f05123",
|
|
48
50
|
"#ee2524"
|
|
49
51
|
])();
|
|
50
|
-
var
|
|
51
|
-
var _getNextColor = () => {
|
|
52
|
-
const color = colorList[_colorIndex];
|
|
53
|
-
_colorIndex++;
|
|
54
|
-
if (_colorIndex >= colorList.length) {
|
|
55
|
-
_colorIndex = 0;
|
|
56
|
-
}
|
|
57
|
-
return color;
|
|
58
|
-
};
|
|
59
|
-
var _style = /* @__PURE__ */ (() => ({
|
|
52
|
+
var style_ = /* @__PURE__ */ (() => ({
|
|
60
53
|
scope: import_platform_info.platformInfo.isCli ? "\x1B[{{color}}m" : "color: {{color}};",
|
|
61
54
|
reset: import_platform_info.platformInfo.isCli ? "\x1B[0m" : "color: inherit;"
|
|
62
55
|
}))();
|
|
63
|
-
var
|
|
64
|
-
var
|
|
56
|
+
var keySection_ = /* @__PURE__ */ (() => import_platform_info.platformInfo.isCli ? "%s%s%s" : "%c%s%c")();
|
|
57
|
+
var colorIndex_ = 0;
|
|
58
|
+
function getNextColor_() {
|
|
59
|
+
const color = colorList[colorIndex_];
|
|
60
|
+
colorIndex_ = (colorIndex_ + 1) % colorList.length;
|
|
61
|
+
return color;
|
|
62
|
+
}
|
|
63
|
+
function sanitizeDomain_(domain) {
|
|
65
64
|
domain = domain.trim();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
domain = "{" + domain + "}";
|
|
65
|
+
if (!/^[[{<]/.test(domain)) {
|
|
66
|
+
domain = `{${domain}}`;
|
|
69
67
|
}
|
|
70
68
|
return domain;
|
|
71
|
-
}
|
|
69
|
+
}
|
|
72
70
|
var createLogger = (domain, debugMode = defaultDebugMode) => {
|
|
73
|
-
const color =
|
|
74
|
-
const styleScope =
|
|
75
|
-
|
|
71
|
+
const color = getNextColor_();
|
|
72
|
+
const styleScope = style_.scope.replace("{{color}}", color);
|
|
73
|
+
const sanitizedDomain = sanitizeDomain_(domain);
|
|
76
74
|
const requiredItems = {
|
|
77
75
|
debugMode,
|
|
78
|
-
banner: import_platform_info.platformInfo.isCli ?
|
|
79
|
-
|
|
76
|
+
banner: import_platform_info.platformInfo.isCli ? console_.log.bind(console_, `\x1B[1;37;45m {{{ %s }}} ${style_.reset}`) : console_.log.bind(
|
|
77
|
+
console_,
|
|
80
78
|
"%c%s",
|
|
81
79
|
"font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;"
|
|
82
80
|
),
|
|
83
|
-
accident: import_platform_info.platformInfo.isCli ?
|
|
84
|
-
%s\x1B[33m.%s() Accident \`%s\`!${
|
|
85
|
-
error: import_platform_info.platformInfo.isCli ?
|
|
86
|
-
%s\x1B[31m.%s() Error \`%s\`${
|
|
87
|
-
`,
|
|
81
|
+
accident: import_platform_info.platformInfo.isCli ? console_.warn.bind(console_, `${styleScope}⚠️
|
|
82
|
+
%s\x1B[33m.%s() Accident \`%s\`!${style_.reset}`, sanitizedDomain) : console_.warn.bind(console_, "%c%s%c.%s() Accident `%s`!", styleScope, sanitizedDomain, style_.reset),
|
|
83
|
+
error: import_platform_info.platformInfo.isCli ? console_.error.bind(console_, `${styleScope}❌
|
|
84
|
+
%s\x1B[31m.%s() Error \`%s\`${style_.reset}
|
|
85
|
+
`, sanitizedDomain) : console_.error.bind(console_, "%c%s%c.%s() Error `%s`\n", styleScope, sanitizedDomain, style_.reset)
|
|
88
86
|
};
|
|
89
87
|
if (!debugMode) {
|
|
90
88
|
return requiredItems;
|
|
91
89
|
}
|
|
92
90
|
return {
|
|
93
91
|
...requiredItems,
|
|
94
|
-
logProperty:
|
|
95
|
-
logMethod:
|
|
96
|
-
logFileModule:
|
|
97
|
-
logMethodArgs:
|
|
98
|
-
logMethodFull:
|
|
99
|
-
logStep:
|
|
100
|
-
logOther:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
logProperty: console_.debug.bind(console_, keySection_ + ".%s = %o;", styleScope, sanitizedDomain, style_.reset),
|
|
93
|
+
logMethod: console_.debug.bind(console_, keySection_ + ".%s();", styleScope, sanitizedDomain, style_.reset),
|
|
94
|
+
logFileModule: console_.debug.bind(console_, keySection_ + "/%s.js;", styleScope, sanitizedDomain, style_.reset),
|
|
95
|
+
logMethodArgs: console_.debug.bind(console_, keySection_ + ".%s(%o);", styleScope, sanitizedDomain, style_.reset),
|
|
96
|
+
logMethodFull: console_.debug.bind(console_, keySection_ + ".%s(%o) => %o", styleScope, sanitizedDomain, style_.reset),
|
|
97
|
+
logStep: console_.debug.bind(console_, keySection_ + ".%s() -> %s", styleScope, sanitizedDomain, style_.reset),
|
|
98
|
+
logOther: console_.debug.bind(console_, keySection_, styleScope, sanitizedDomain, style_.reset),
|
|
99
|
+
logTable: console_.table.bind(console_),
|
|
100
|
+
incident: import_platform_info.platformInfo.isCli ? console_.log.bind(console_, `${styleScope}🚸
|
|
101
|
+
%s${style_.reset}.%s() Incident \`%s\`!${style_.reset}`, sanitizedDomain) : console_.log.bind(console_, "%c%s%c.%s() Incident `%s`!", styleScope, sanitizedDomain, "color: orange;"),
|
|
102
|
+
time: (label) => console_.time(sanitizedDomain + "." + label),
|
|
103
|
+
timeEnd: (label) => console_.timeEnd(sanitizedDomain + "." + label)
|
|
105
104
|
};
|
|
106
105
|
};
|
|
107
106
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/main.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts", "../src/logger.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './logger.js';\nexport * from './type.js';\n", "import {platformInfo} from '@alwatr/platform-info';\n\nimport type {AlwatrLogger} from './type.js';\n\nconst defaultDebugMode = /* #__PURE__ */ (() => {\n return (\n platformInfo.development ||\n (platformInfo.isCli
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAA2B;AAI3B,IAAM,mBAAoC,uBAAM;AAC9C,SACE,kCAAa,gBACZ,kCAAa,QAAQ,QAAQ,QAAQ,IAAI,KAAK,
|
|
4
|
+
"sourcesContent": ["export * from './logger.js';\nexport * from './type.js';\n", "import {getGlobalThis} from '@alwatr/global-this';\nimport {platformInfo} from '@alwatr/platform-info';\n\nimport type {AlwatrLogger} from './type.js';\n\nconst console_ = getGlobalThis().console;\n\n/**\n * Default debug mode state, determined by environment variables or localStorage.\n */\nconst defaultDebugMode = /* #__PURE__ */ (() => {\n return (\n platformInfo.development ||\n (platformInfo.isCli\n ? process.env.NODE_ENV !== 'production' || Boolean(process.env.DEBUG)\n : typeof localStorage !== 'undefined' && localStorage.getItem('ALWATR_DEBUG') === '1')\n );\n})();\n\n/**\n * A list of aesthetically pleasing colors for console logging, adapted for CLI and browser environments.\n */\nconst colorList = /* #__PURE__ */ (() =>\n platformInfo.isCli\n ? ['0;36', '0;35', '0;34', '0;33', '0;32'] // CLI-safe colors\n : [\n '#35b997',\n '#f05561',\n '#ee224a',\n '#91c13e',\n '#22af4b',\n '#f0e995',\n '#0fe995',\n '#0f89ca',\n '#08b9a5',\n '#fee851',\n '#ee573d',\n '#f9df30',\n '#1da2dc',\n '#f05123',\n '#ee2524',\n ])();\n\n/**\n * Platform-specific styling templates for logger output.\n */\nconst style_ = /* #__PURE__ */ (() => ({\n scope: platformInfo.isCli ? '\\x1b[{{color}}m' : 'color: {{color}};',\n reset: platformInfo.isCli ? '\\x1b[0m' : 'color: inherit;',\n}))();\n\n/**\n * Platform-specific format for displaying the logger's scope.\n */\nconst keySection_ = /* #__PURE__ */ (() => (platformInfo.isCli ? '%s%s%s' : '%c%s%c'))();\n\n// --- Utility Functions ---\n\nlet colorIndex_ = 0;\n/**\n * Cycles through the `colorList` to provide a new color for each logger instance.\n */\nfunction getNextColor_(): string {\n const color = colorList[colorIndex_];\n colorIndex_ = (colorIndex_ + 1) % colorList.length;\n return color;\n}\n\n/**\n * Sanitizes and formats the logger domain string by wrapping it in brackets if not already.\n */\nfunction sanitizeDomain_(domain: string): string {\n domain = domain.trim();\n if (!/^[[{<]/.test(domain)) {\n domain = `{${domain}}`;\n }\n return domain;\n}\n\n// --- Core Factory ---\n\n/**\n * Create a logger function for fancy console debug with custom scope.\n *\n * - `color` is optional and automatically selected from an internal list.\n * - `debug` is optional and automatically detected from `ALWATR_DEBUG` in localStorage or `process.env.DEBUG`.\n *\n * @example\n * ```ts\n * import {createLogger} from '@alwatr/logger';\n * const logger = createLogger('my-module');\n *\n * logger.logMethodArgs?.('myMethod', {a: 1}); // This line is ignored if debugMode is false.\n * ```\n */\nexport const createLogger = (domain: string, debugMode = defaultDebugMode): AlwatrLogger => {\n const color = getNextColor_();\n const styleScope = style_.scope.replace('{{color}}', color);\n const sanitizedDomain = sanitizeDomain_(domain);\n\n /**\n * Logger methods that are always available, regardless of debugMode.\n */\n const requiredItems: AlwatrLogger = {\n debugMode,\n\n banner: platformInfo.isCli\n ? console_.log.bind(console_, `\\x1b[1;37;45m {{{ %s }}} ${style_.reset}`)\n : console_.log.bind(\n console_,\n '%c%s',\n 'font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;',\n ),\n\n accident: platformInfo.isCli\n ? console_.warn.bind(console_, `${styleScope}⚠️\\n%s\\x1b[33m.%s() Accident \\`%s\\`!${style_.reset}`, sanitizedDomain)\n : console_.warn.bind(console_, '%c%s%c.%s() Accident `%s`!', styleScope, sanitizedDomain, style_.reset),\n\n error: platformInfo.isCli\n ? console_.error.bind(console_, `${styleScope}❌\\n%s\\x1b[31m.%s() Error \\`%s\\`${style_.reset}\\n`, sanitizedDomain)\n : console_.error.bind(console_, '%c%s%c.%s() Error `%s`\\n', styleScope, sanitizedDomain, style_.reset),\n };\n\n if (!debugMode) {\n return requiredItems;\n }\n\n /**\n * Logger methods available only when debugMode is true.\n * Using `console.debug` which is often filtered by default in browsers unless \"Verbose\" logs are enabled.\n */\n return {\n ...requiredItems,\n\n logProperty: console_.debug.bind(console_, keySection_ + '.%s = %o;', styleScope, sanitizedDomain, style_.reset),\n\n logMethod: console_.debug.bind(console_, keySection_ + '.%s();', styleScope, sanitizedDomain, style_.reset),\n\n logFileModule: console_.debug.bind(console_, keySection_ + '/%s.js;', styleScope, sanitizedDomain, style_.reset),\n\n logMethodArgs: console_.debug.bind(console_, keySection_ + '.%s(%o);', styleScope, sanitizedDomain, style_.reset),\n\n logMethodFull: console_.debug.bind(console_, keySection_ + '.%s(%o) => %o', styleScope, sanitizedDomain, style_.reset),\n\n logStep: console_.debug.bind(console_, keySection_ + '.%s() -> %s', styleScope, sanitizedDomain, style_.reset),\n\n logOther: console_.debug.bind(console_, keySection_, styleScope, sanitizedDomain, style_.reset),\n\n logTable: console_.table.bind(console_),\n\n incident: platformInfo.isCli\n ? console_.log.bind(console_, `${styleScope}🚸\\n%s${style_.reset}.%s() Incident \\`%s\\`!${style_.reset}`, sanitizedDomain)\n : console_.log.bind(console_, '%c%s%c.%s() Incident `%s`!', styleScope, sanitizedDomain, 'color: orange;'),\n\n time: (label: string) => console_.time(sanitizedDomain + '.' + label),\n timeEnd: (label: string) => console_.timeEnd(sanitizedDomain + '.' + label),\n } as const;\n};\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/main.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
/* @alwatr/logger
|
|
1
|
+
/* @alwatr/logger v6.0.0 */
|
|
2
2
|
|
|
3
3
|
// src/logger.ts
|
|
4
|
+
import { getGlobalThis } from "@alwatr/global-this";
|
|
4
5
|
import { platformInfo } from "@alwatr/platform-info";
|
|
6
|
+
var console_ = getGlobalThis().console;
|
|
5
7
|
var defaultDebugMode = /* @__PURE__ */ (() => {
|
|
6
|
-
return platformInfo.development || (platformInfo.isCli ? Boolean(process.env.DEBUG) : typeof localStorage !== "undefined" && localStorage.getItem("ALWATR_DEBUG") === "1");
|
|
8
|
+
return platformInfo.development || (platformInfo.isCli ? process.env.NODE_ENV !== "production" || Boolean(process.env.DEBUG) : typeof localStorage !== "undefined" && localStorage.getItem("ALWATR_DEBUG") === "1");
|
|
7
9
|
})();
|
|
8
10
|
var colorList = /* @__PURE__ */ (() => platformInfo.isCli ? ["0;36", "0;35", "0;34", "0;33", "0;32"] : [
|
|
9
11
|
"#35b997",
|
|
@@ -22,61 +24,58 @@ var colorList = /* @__PURE__ */ (() => platformInfo.isCli ? ["0;36", "0;35", "0;
|
|
|
22
24
|
"#f05123",
|
|
23
25
|
"#ee2524"
|
|
24
26
|
])();
|
|
25
|
-
var
|
|
26
|
-
var _getNextColor = () => {
|
|
27
|
-
const color = colorList[_colorIndex];
|
|
28
|
-
_colorIndex++;
|
|
29
|
-
if (_colorIndex >= colorList.length) {
|
|
30
|
-
_colorIndex = 0;
|
|
31
|
-
}
|
|
32
|
-
return color;
|
|
33
|
-
};
|
|
34
|
-
var _style = /* @__PURE__ */ (() => ({
|
|
27
|
+
var style_ = /* @__PURE__ */ (() => ({
|
|
35
28
|
scope: platformInfo.isCli ? "\x1B[{{color}}m" : "color: {{color}};",
|
|
36
29
|
reset: platformInfo.isCli ? "\x1B[0m" : "color: inherit;"
|
|
37
30
|
}))();
|
|
38
|
-
var
|
|
39
|
-
var
|
|
31
|
+
var keySection_ = /* @__PURE__ */ (() => platformInfo.isCli ? "%s%s%s" : "%c%s%c")();
|
|
32
|
+
var colorIndex_ = 0;
|
|
33
|
+
function getNextColor_() {
|
|
34
|
+
const color = colorList[colorIndex_];
|
|
35
|
+
colorIndex_ = (colorIndex_ + 1) % colorList.length;
|
|
36
|
+
return color;
|
|
37
|
+
}
|
|
38
|
+
function sanitizeDomain_(domain) {
|
|
40
39
|
domain = domain.trim();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
domain = "{" + domain + "}";
|
|
40
|
+
if (!/^[[{<]/.test(domain)) {
|
|
41
|
+
domain = `{${domain}}`;
|
|
44
42
|
}
|
|
45
43
|
return domain;
|
|
46
|
-
}
|
|
44
|
+
}
|
|
47
45
|
var createLogger = (domain, debugMode = defaultDebugMode) => {
|
|
48
|
-
const color =
|
|
49
|
-
const styleScope =
|
|
50
|
-
|
|
46
|
+
const color = getNextColor_();
|
|
47
|
+
const styleScope = style_.scope.replace("{{color}}", color);
|
|
48
|
+
const sanitizedDomain = sanitizeDomain_(domain);
|
|
51
49
|
const requiredItems = {
|
|
52
50
|
debugMode,
|
|
53
|
-
banner: platformInfo.isCli ?
|
|
54
|
-
|
|
51
|
+
banner: platformInfo.isCli ? console_.log.bind(console_, `\x1B[1;37;45m {{{ %s }}} ${style_.reset}`) : console_.log.bind(
|
|
52
|
+
console_,
|
|
55
53
|
"%c%s",
|
|
56
54
|
"font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;"
|
|
57
55
|
),
|
|
58
|
-
accident: platformInfo.isCli ?
|
|
59
|
-
%s\x1B[33m.%s() Accident \`%s\`!${
|
|
60
|
-
error: platformInfo.isCli ?
|
|
61
|
-
%s\x1B[31m.%s() Error \`%s\`${
|
|
62
|
-
`,
|
|
56
|
+
accident: platformInfo.isCli ? console_.warn.bind(console_, `${styleScope}⚠️
|
|
57
|
+
%s\x1B[33m.%s() Accident \`%s\`!${style_.reset}`, sanitizedDomain) : console_.warn.bind(console_, "%c%s%c.%s() Accident `%s`!", styleScope, sanitizedDomain, style_.reset),
|
|
58
|
+
error: platformInfo.isCli ? console_.error.bind(console_, `${styleScope}❌
|
|
59
|
+
%s\x1B[31m.%s() Error \`%s\`${style_.reset}
|
|
60
|
+
`, sanitizedDomain) : console_.error.bind(console_, "%c%s%c.%s() Error `%s`\n", styleScope, sanitizedDomain, style_.reset)
|
|
63
61
|
};
|
|
64
62
|
if (!debugMode) {
|
|
65
63
|
return requiredItems;
|
|
66
64
|
}
|
|
67
65
|
return {
|
|
68
66
|
...requiredItems,
|
|
69
|
-
logProperty:
|
|
70
|
-
logMethod:
|
|
71
|
-
logFileModule:
|
|
72
|
-
logMethodArgs:
|
|
73
|
-
logMethodFull:
|
|
74
|
-
logStep:
|
|
75
|
-
logOther:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
logProperty: console_.debug.bind(console_, keySection_ + ".%s = %o;", styleScope, sanitizedDomain, style_.reset),
|
|
68
|
+
logMethod: console_.debug.bind(console_, keySection_ + ".%s();", styleScope, sanitizedDomain, style_.reset),
|
|
69
|
+
logFileModule: console_.debug.bind(console_, keySection_ + "/%s.js;", styleScope, sanitizedDomain, style_.reset),
|
|
70
|
+
logMethodArgs: console_.debug.bind(console_, keySection_ + ".%s(%o);", styleScope, sanitizedDomain, style_.reset),
|
|
71
|
+
logMethodFull: console_.debug.bind(console_, keySection_ + ".%s(%o) => %o", styleScope, sanitizedDomain, style_.reset),
|
|
72
|
+
logStep: console_.debug.bind(console_, keySection_ + ".%s() -> %s", styleScope, sanitizedDomain, style_.reset),
|
|
73
|
+
logOther: console_.debug.bind(console_, keySection_, styleScope, sanitizedDomain, style_.reset),
|
|
74
|
+
logTable: console_.table.bind(console_),
|
|
75
|
+
incident: platformInfo.isCli ? console_.log.bind(console_, `${styleScope}🚸
|
|
76
|
+
%s${style_.reset}.%s() Incident \`%s\`!${style_.reset}`, sanitizedDomain) : console_.log.bind(console_, "%c%s%c.%s() Incident `%s`!", styleScope, sanitizedDomain, "color: orange;"),
|
|
77
|
+
time: (label) => console_.time(sanitizedDomain + "." + label),
|
|
78
|
+
timeEnd: (label) => console_.timeEnd(sanitizedDomain + "." + label)
|
|
80
79
|
};
|
|
81
80
|
};
|
|
82
81
|
export {
|
package/dist/main.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/logger.ts"],
|
|
4
|
-
"sourcesContent": ["import {platformInfo} from '@alwatr/platform-info';\n\nimport type {AlwatrLogger} from './type.js';\n\nconst defaultDebugMode = /* #__PURE__ */ (() => {\n return (\n platformInfo.development ||\n (platformInfo.isCli
|
|
5
|
-
"mappings": ";;;AAAA,SAAQ,oBAAmB;AAI3B,IAAM,mBAAoC,uBAAM;AAC9C,SACE,aAAa,gBACZ,aAAa,QAAQ,QAAQ,QAAQ,IAAI,KAAK,
|
|
4
|
+
"sourcesContent": ["import {getGlobalThis} from '@alwatr/global-this';\nimport {platformInfo} from '@alwatr/platform-info';\n\nimport type {AlwatrLogger} from './type.js';\n\nconst console_ = getGlobalThis().console;\n\n/**\n * Default debug mode state, determined by environment variables or localStorage.\n */\nconst defaultDebugMode = /* #__PURE__ */ (() => {\n return (\n platformInfo.development ||\n (platformInfo.isCli\n ? process.env.NODE_ENV !== 'production' || Boolean(process.env.DEBUG)\n : typeof localStorage !== 'undefined' && localStorage.getItem('ALWATR_DEBUG') === '1')\n );\n})();\n\n/**\n * A list of aesthetically pleasing colors for console logging, adapted for CLI and browser environments.\n */\nconst colorList = /* #__PURE__ */ (() =>\n platformInfo.isCli\n ? ['0;36', '0;35', '0;34', '0;33', '0;32'] // CLI-safe colors\n : [\n '#35b997',\n '#f05561',\n '#ee224a',\n '#91c13e',\n '#22af4b',\n '#f0e995',\n '#0fe995',\n '#0f89ca',\n '#08b9a5',\n '#fee851',\n '#ee573d',\n '#f9df30',\n '#1da2dc',\n '#f05123',\n '#ee2524',\n ])();\n\n/**\n * Platform-specific styling templates for logger output.\n */\nconst style_ = /* #__PURE__ */ (() => ({\n scope: platformInfo.isCli ? '\\x1b[{{color}}m' : 'color: {{color}};',\n reset: platformInfo.isCli ? '\\x1b[0m' : 'color: inherit;',\n}))();\n\n/**\n * Platform-specific format for displaying the logger's scope.\n */\nconst keySection_ = /* #__PURE__ */ (() => (platformInfo.isCli ? '%s%s%s' : '%c%s%c'))();\n\n// --- Utility Functions ---\n\nlet colorIndex_ = 0;\n/**\n * Cycles through the `colorList` to provide a new color for each logger instance.\n */\nfunction getNextColor_(): string {\n const color = colorList[colorIndex_];\n colorIndex_ = (colorIndex_ + 1) % colorList.length;\n return color;\n}\n\n/**\n * Sanitizes and formats the logger domain string by wrapping it in brackets if not already.\n */\nfunction sanitizeDomain_(domain: string): string {\n domain = domain.trim();\n if (!/^[[{<]/.test(domain)) {\n domain = `{${domain}}`;\n }\n return domain;\n}\n\n// --- Core Factory ---\n\n/**\n * Create a logger function for fancy console debug with custom scope.\n *\n * - `color` is optional and automatically selected from an internal list.\n * - `debug` is optional and automatically detected from `ALWATR_DEBUG` in localStorage or `process.env.DEBUG`.\n *\n * @example\n * ```ts\n * import {createLogger} from '@alwatr/logger';\n * const logger = createLogger('my-module');\n *\n * logger.logMethodArgs?.('myMethod', {a: 1}); // This line is ignored if debugMode is false.\n * ```\n */\nexport const createLogger = (domain: string, debugMode = defaultDebugMode): AlwatrLogger => {\n const color = getNextColor_();\n const styleScope = style_.scope.replace('{{color}}', color);\n const sanitizedDomain = sanitizeDomain_(domain);\n\n /**\n * Logger methods that are always available, regardless of debugMode.\n */\n const requiredItems: AlwatrLogger = {\n debugMode,\n\n banner: platformInfo.isCli\n ? console_.log.bind(console_, `\\x1b[1;37;45m {{{ %s }}} ${style_.reset}`)\n : console_.log.bind(\n console_,\n '%c%s',\n 'font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;',\n ),\n\n accident: platformInfo.isCli\n ? console_.warn.bind(console_, `${styleScope}⚠️\\n%s\\x1b[33m.%s() Accident \\`%s\\`!${style_.reset}`, sanitizedDomain)\n : console_.warn.bind(console_, '%c%s%c.%s() Accident `%s`!', styleScope, sanitizedDomain, style_.reset),\n\n error: platformInfo.isCli\n ? console_.error.bind(console_, `${styleScope}❌\\n%s\\x1b[31m.%s() Error \\`%s\\`${style_.reset}\\n`, sanitizedDomain)\n : console_.error.bind(console_, '%c%s%c.%s() Error `%s`\\n', styleScope, sanitizedDomain, style_.reset),\n };\n\n if (!debugMode) {\n return requiredItems;\n }\n\n /**\n * Logger methods available only when debugMode is true.\n * Using `console.debug` which is often filtered by default in browsers unless \"Verbose\" logs are enabled.\n */\n return {\n ...requiredItems,\n\n logProperty: console_.debug.bind(console_, keySection_ + '.%s = %o;', styleScope, sanitizedDomain, style_.reset),\n\n logMethod: console_.debug.bind(console_, keySection_ + '.%s();', styleScope, sanitizedDomain, style_.reset),\n\n logFileModule: console_.debug.bind(console_, keySection_ + '/%s.js;', styleScope, sanitizedDomain, style_.reset),\n\n logMethodArgs: console_.debug.bind(console_, keySection_ + '.%s(%o);', styleScope, sanitizedDomain, style_.reset),\n\n logMethodFull: console_.debug.bind(console_, keySection_ + '.%s(%o) => %o', styleScope, sanitizedDomain, style_.reset),\n\n logStep: console_.debug.bind(console_, keySection_ + '.%s() -> %s', styleScope, sanitizedDomain, style_.reset),\n\n logOther: console_.debug.bind(console_, keySection_, styleScope, sanitizedDomain, style_.reset),\n\n logTable: console_.table.bind(console_),\n\n incident: platformInfo.isCli\n ? console_.log.bind(console_, `${styleScope}🚸\\n%s${style_.reset}.%s() Incident \\`%s\\`!${style_.reset}`, sanitizedDomain)\n : console_.log.bind(console_, '%c%s%c.%s() Incident `%s`!', styleScope, sanitizedDomain, 'color: orange;'),\n\n time: (label: string) => console_.time(sanitizedDomain + '.' + label),\n timeEnd: (label: string) => console_.timeEnd(sanitizedDomain + '.' + label),\n } as const;\n};\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/type.d.ts
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
* Represents the AlwatrLogger interface for logging various types of information at different levels of detail.
|
|
3
3
|
* This interface allows for structured logging of events, method calls, errors, and more,
|
|
4
4
|
* aiding in debugging and understanding application behavior.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import {createLogger} from '@alwatr/logger';
|
|
8
|
+
* const logger = createLogger('my-module'); // Create a logger with a specific scope
|
|
9
|
+
*
|
|
10
|
+
* function greet(name: string) {
|
|
11
|
+
* logger.logMethodArgs?.('greet', {name}); // Log the method call with its arguments
|
|
12
|
+
* // ...
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* greet('Ali');
|
|
5
16
|
*/
|
|
6
17
|
export interface AlwatrLogger {
|
|
7
18
|
/**
|
|
@@ -157,6 +168,14 @@ export interface AlwatrLogger {
|
|
|
157
168
|
* ```
|
|
158
169
|
*/
|
|
159
170
|
logOther?(...args: unknown[]): void;
|
|
171
|
+
/**
|
|
172
|
+
* Try to construct a table with the columns of the properties of `tabularData` (or use `properties`)
|
|
173
|
+
* and rows of `tabularData` and log it.
|
|
174
|
+
* Falls back to just logging the argument if it can't be parsed as tabular.
|
|
175
|
+
* @param tabularData Any data that can be represented in tabular form.
|
|
176
|
+
* @param properties Alternate properties for constructing the table.
|
|
177
|
+
*/
|
|
178
|
+
logTable?(tabularData: unknown, properties?: readonly string[]): void;
|
|
160
179
|
/**
|
|
161
180
|
* Starts a timer with a specified label using `console.time`. Useful for measuring performance.
|
|
162
181
|
*
|
package/dist/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,SAAS,EAAE,OAAO,CAAC;IAEnB;;;;;;;;;;OAUG;IACH,WAAW,CAAC,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzD;;;;;;;;;;OAUG;IACH,aAAa,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvC;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAErC;;;;;;;;;;;;;OAaG;IACH,aAAa,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAExD;;;;;;;;;;;;;;;;;;;OAmBG;IACH,OAAO,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEtE;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzE;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE7E;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE5E;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEvE;;;;;;;;;OASG;IACH,QAAQ,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEpC;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,WAAW,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAEtE;;;;;;;;;OASG;IACH,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B;;;;;;;;;OASG;IACH,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;;;;;;;;OASG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/logger",
|
|
3
3
|
"description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.0.0",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Alwatr/nanolib/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@alwatr/
|
|
8
|
+
"@alwatr/global-this": "5.5.13",
|
|
9
|
+
"@alwatr/platform-info": "5.5.12"
|
|
9
10
|
},
|
|
10
11
|
"devDependencies": {
|
|
11
|
-
"@alwatr/nano-build": "6.1.
|
|
12
|
+
"@alwatr/nano-build": "6.1.2",
|
|
12
13
|
"@alwatr/prettier-config": "5.0.3",
|
|
13
14
|
"@alwatr/tsconfig-base": "6.0.1",
|
|
14
|
-
"@types/node": "^22.18.
|
|
15
|
+
"@types/node": "^22.18.3",
|
|
15
16
|
"typescript": "^5.9.2"
|
|
16
17
|
},
|
|
17
18
|
"exports": {
|
|
@@ -74,5 +75,5 @@
|
|
|
74
75
|
},
|
|
75
76
|
"type": "module",
|
|
76
77
|
"types": "./dist/main.d.ts",
|
|
77
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "4249b4e06eeb5739e1d6dbacfbce5b33a3180263"
|
|
78
79
|
}
|