@renpwn/simplelog 0.0.1 โ 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -39
- package/package.json +2 -2
- package/src/Formatter.js +70 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# simpleLog
|
|
2
2
|
|
|
3
|
-
> Lightweight, opinionated, **TTY-aware logger** for Node.js with progress
|
|
3
|
+
> Lightweight, opinionated, **TTY-aware logger** for Node.js with progress bars, file output, safe stringify, and zero dependencies.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@renpwn/simplelog)
|
|
6
6
|
[](https://www.npmjs.com/package/@renpwn/simplelog)
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
## โจ Features
|
|
12
12
|
|
|
13
13
|
- ๐จ Colored log levels (log, debug, info, warn, error)
|
|
14
|
-
- ๐ง Safe stringify (object โ JSON, anti
|
|
15
|
-
- ๐ Timestamp with locale (`id`, `en`)
|
|
16
|
-
- ๐ File logging (TXT / JSONL
|
|
14
|
+
- ๐ง Safe stringify (object โ JSON, anti-crash, truncate)
|
|
15
|
+
- ๐ Timestamp with locale support (`id`, `en`)
|
|
16
|
+
- ๐ File logging (TXT / JSONL with auto-backup)
|
|
17
17
|
- ๐ Multi progress bar (TTY-aware, auto redraw)
|
|
18
|
-
- ๐งน
|
|
18
|
+
- ๐งน CI & non-TTY safe
|
|
19
19
|
- โก Zero dependencies
|
|
20
20
|
- ๐งฉ Modular & audit-friendly
|
|
21
21
|
|
|
@@ -57,18 +57,18 @@ log.error('error')
|
|
|
57
57
|
|
|
58
58
|
---
|
|
59
59
|
|
|
60
|
-
## ๐ง Full Usage
|
|
60
|
+
## ๐ง Full Usage Examples
|
|
61
61
|
|
|
62
|
-
### 1๏ธโฃ Logger
|
|
62
|
+
### 1๏ธโฃ Logger with Level, Color & Time
|
|
63
63
|
|
|
64
64
|
```js
|
|
65
65
|
import { simpleLog } from '@renpwn/simplelog'
|
|
66
66
|
|
|
67
67
|
const log = simpleLog({
|
|
68
68
|
level: 'debug', // log | debug | info | warn | error | silent
|
|
69
|
-
color: true, // enable ANSI color
|
|
69
|
+
color: true, // enable ANSI color (TTY only)
|
|
70
70
|
time: {
|
|
71
|
-
locale: '
|
|
71
|
+
locale: 'en', // en | id
|
|
72
72
|
position: 'prefix' // prefix | suffix
|
|
73
73
|
}
|
|
74
74
|
})
|
|
@@ -79,10 +79,10 @@ log.warn('Memory usage high')
|
|
|
79
79
|
log.error({ code: 500, msg: 'Fatal error' })
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
- `level` โ
|
|
84
|
-
- `color` โ
|
|
85
|
-
- `time` โ
|
|
82
|
+
**Notes**
|
|
83
|
+
- `level` โ minimum log level to display
|
|
84
|
+
- `color` โ auto-disabled in non-TTY / CI
|
|
85
|
+
- `time` โ compact and consistent timestamp
|
|
86
86
|
|
|
87
87
|
---
|
|
88
88
|
|
|
@@ -100,7 +100,7 @@ log.info({
|
|
|
100
100
|
})
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
Objects are safely stringified and automatically truncated.
|
|
104
104
|
|
|
105
105
|
---
|
|
106
106
|
|
|
@@ -137,18 +137,19 @@ Output:
|
|
|
137
137
|
{"time":"2026-01-20T07:21:10.120Z","level":"info","message":"App started"}
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
File writes are atomic with automatic `.bak` backup.
|
|
141
141
|
|
|
142
142
|
---
|
|
143
143
|
|
|
144
|
-
### 4๏ธโฃ Progress Bar (Multi Slot)
|
|
144
|
+
### 4๏ธโฃ Progress Bar (Multi Slot, Styled & Unstyled)
|
|
145
145
|
|
|
146
146
|
```js
|
|
147
147
|
const log = simpleLog({
|
|
148
148
|
progress: {
|
|
149
149
|
slots: [
|
|
150
150
|
['Scraping', { color: 'cyan' }],
|
|
151
|
-
['DB Queue', 'auto']
|
|
151
|
+
['DB Queue', 'auto'],
|
|
152
|
+
'WEB Queue'
|
|
152
153
|
]
|
|
153
154
|
}
|
|
154
155
|
})
|
|
@@ -166,9 +167,9 @@ const timer = setInterval(() => {
|
|
|
166
167
|
}, 300)
|
|
167
168
|
```
|
|
168
169
|
|
|
169
|
-
|
|
170
|
-
- Progress
|
|
171
|
-
-
|
|
170
|
+
**Notes**
|
|
171
|
+
- Progress bars are shown only in TTY
|
|
172
|
+
- Normal logs temporarily clear progress and redraw it
|
|
172
173
|
|
|
173
174
|
---
|
|
174
175
|
|
|
@@ -192,7 +193,193 @@ const log = simpleLog({
|
|
|
192
193
|
|
|
193
194
|
---
|
|
194
195
|
|
|
195
|
-
##
|
|
196
|
+
## ๐จ Styles Object
|
|
197
|
+
|
|
198
|
+
The `style` object controls **text color, background color, and emphasis**
|
|
199
|
+
for **Logger output** and **ProgressBar rendering**.
|
|
200
|
+
|
|
201
|
+
It supports:
|
|
202
|
+
- single style
|
|
203
|
+
- dual style (0% vs >0%)
|
|
204
|
+
- auto style (threshold-based)
|
|
205
|
+
- global style
|
|
206
|
+
- per-slot style
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
### ๐งฉ Basic Style Object
|
|
211
|
+
|
|
212
|
+
```js
|
|
213
|
+
{
|
|
214
|
+
color: 'green',
|
|
215
|
+
bg: 'black',
|
|
216
|
+
bold: true,
|
|
217
|
+
dim: false
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### Properties
|
|
222
|
+
|
|
223
|
+
| Property | Type | Description |
|
|
224
|
+
|---------|------|-------------|
|
|
225
|
+
| `color` | `string` | Foreground color name |
|
|
226
|
+
| `bg` | `string` | Background color name |
|
|
227
|
+
| `bold` | `boolean` | Bold text |
|
|
228
|
+
| `dim` | `boolean` | Dim / faded text |
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
### ๐จ Supported Color Names
|
|
233
|
+
|
|
234
|
+
#### Basic & Bright
|
|
235
|
+
```
|
|
236
|
+
black, red, green, yellow, blue, magenta, cyan, white
|
|
237
|
+
brightBlack, brightRed, brightGreen, brightYellow,
|
|
238
|
+
brightBlue, brightMagenta, brightCyan, brightWhite
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
#### Extended (examples)
|
|
242
|
+
```
|
|
243
|
+
/*Grayscale*/
|
|
244
|
+
gray0 gray1 gray2 gray3 gray4 gray5 gray6 gray7 gray8 gray9
|
|
245
|
+
|
|
246
|
+
/*Soft / Pastel*/
|
|
247
|
+
softRed softGreen softYellow softBlue softMagenta softCyan
|
|
248
|
+
|
|
249
|
+
/*Strong / Vivid*/
|
|
250
|
+
orange pink violet teal lime amber
|
|
251
|
+
|
|
252
|
+
/*Extra / Utility*/
|
|
253
|
+
gold sky mint coral indigo brown olive navy maroon aqua chartreuse plum salmon steel sand forest wine slate smoke
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
> All colors work for both `color` and `bg`.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
### ๐ข Single Style (Always Applied)
|
|
261
|
+
|
|
262
|
+
```js
|
|
263
|
+
style: { color: 'cyan', bold: true }
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Use case: static label color, consistent emphasis.
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
### ๐ต Dual Style (0% vs >0%)
|
|
271
|
+
|
|
272
|
+
```js
|
|
273
|
+
style: [
|
|
274
|
+
{ dim: true }, // 0%
|
|
275
|
+
{ color: 'blue', bold: true } // >0%
|
|
276
|
+
]
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
### โช Partial Dual Style (`null` allowed)
|
|
282
|
+
|
|
283
|
+
```js
|
|
284
|
+
style: [
|
|
285
|
+
null, // 0%
|
|
286
|
+
{ color: 'green', bold: true } // >0%
|
|
287
|
+
]
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
### ๐ค Auto Style (Threshold-Based)
|
|
293
|
+
|
|
294
|
+
```js
|
|
295
|
+
style: 'auto'
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
| Percent | Color |
|
|
299
|
+
|---------|-------|
|
|
300
|
+
| < 50% | Blue |
|
|
301
|
+
| 50โ79% | Yellow |
|
|
302
|
+
| โฅ 80% | Red (bold) |
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
### ๐ Global ProgressBar Style
|
|
307
|
+
|
|
308
|
+
```js
|
|
309
|
+
const log = simpleLog({
|
|
310
|
+
progress: {
|
|
311
|
+
slots: ['๐ Scraping', '๐ DB Queue'],
|
|
312
|
+
theme: {
|
|
313
|
+
style: { color: 'magenta', bold: true }
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
})
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
### ๐ฏ Per-Slot Progress Style
|
|
322
|
+
|
|
323
|
+
```js
|
|
324
|
+
const log = simpleLog({
|
|
325
|
+
progress: {
|
|
326
|
+
slots: [
|
|
327
|
+
['Scraping', { color: 'cyan' }],
|
|
328
|
+
['DB Queue', 'auto']
|
|
329
|
+
'WEB Queue',
|
|
330
|
+
]
|
|
331
|
+
}
|
|
332
|
+
})
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
### ๐จ Combined Example (Global + Slot)
|
|
338
|
+
|
|
339
|
+
```js
|
|
340
|
+
const log = simpleLog({
|
|
341
|
+
progress: {
|
|
342
|
+
slots: [
|
|
343
|
+
['Scraping', { color: 'cyan' }],
|
|
344
|
+
['DB Queue', 'auto']
|
|
345
|
+
'WEB Queue',
|
|
346
|
+
],
|
|
347
|
+
theme: {
|
|
348
|
+
style: { color: 'magenta', bold: true }
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
})
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Visual concept:
|
|
355
|
+
```
|
|
356
|
+
MAGENTA ๐ Scraping [BLUE โโโโโโโโโโโโโโโโโโ] 30% page 3 MAGENTA
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
### โ ๏ธ Notes
|
|
362
|
+
|
|
363
|
+
- Styles only affect console output, never file logs
|
|
364
|
+
- Colors apply only when `process.stdout.isTTY === true`
|
|
365
|
+
- Logger styles and ProgressBar styles are independent by design
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
### โ
Summary
|
|
370
|
+
|
|
371
|
+
| Feature | Supported |
|
|
372
|
+
|--------|-----------|
|
|
373
|
+
| Single style | โ
|
|
|
374
|
+
| Dual style | โ
|
|
|
375
|
+
| Partial dual (`null`) | โ
|
|
|
376
|
+
| Auto style | โ
|
|
|
377
|
+
| Global ProgressBar style | โ
|
|
|
378
|
+
| Per-slot override | โ
|
|
|
379
|
+
| 256-color palette | โ
|
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
## ๐งฉ API Summary
|
|
196
383
|
|
|
197
384
|
```js
|
|
198
385
|
log.log(...args)
|
|
@@ -247,18 +434,16 @@ simpleLog()
|
|
|
247
434
|
simplelog/
|
|
248
435
|
โโ package.json
|
|
249
436
|
โโ src/
|
|
250
|
-
โโ index.js
|
|
251
|
-
|
|
252
|
-
โโ
|
|
253
|
-
โโ
|
|
254
|
-
โโ
|
|
255
|
-
โโ
|
|
256
|
-
โโ
|
|
257
|
-
โโ FileSink.js # file logging
|
|
258
|
-
โ
|
|
437
|
+
โโ index.js
|
|
438
|
+
โโ Logger.js
|
|
439
|
+
โโ Levels.js
|
|
440
|
+
โโ Formatter.js
|
|
441
|
+
โโ Stringify.js
|
|
442
|
+
โโ Time.js
|
|
443
|
+
โโ FileSink.js
|
|
259
444
|
โโ Progress/
|
|
260
|
-
โโ ProgressManager.js
|
|
261
|
-
โโ ProgressRenderer.js
|
|
445
|
+
โโ ProgressManager.js
|
|
446
|
+
โโ ProgressRenderer.js
|
|
262
447
|
```
|
|
263
448
|
|
|
264
449
|
---
|
|
@@ -266,17 +451,17 @@ simplelog/
|
|
|
266
451
|
## ๐ง Design Philosophy
|
|
267
452
|
|
|
268
453
|
- Small core
|
|
269
|
-
-
|
|
454
|
+
- Zero dependencies
|
|
270
455
|
- Predictable output
|
|
271
|
-
- Audit
|
|
456
|
+
- Audit-friendly
|
|
272
457
|
- Library-first design
|
|
273
458
|
|
|
274
|
-
|
|
459
|
+
Perfect for:
|
|
275
460
|
- CLI tools
|
|
276
|
-
-
|
|
277
|
-
-
|
|
278
|
-
-
|
|
279
|
-
- Base
|
|
461
|
+
- WhatsApp / Telegram bots
|
|
462
|
+
- Scrapers
|
|
463
|
+
- Workers / queues
|
|
464
|
+
- Base libraries (`simpleStore`, `simpleFetch`, etc.)
|
|
280
465
|
|
|
281
466
|
---
|
|
282
467
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renpwn/simplelog",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Lightweight, safe, audit-friendly logger for CLI tools and long-running Node.js processes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"author": "RenPwn",
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
28
|
-
"url": "
|
|
28
|
+
"url": "https://github.com/renpwn/simpleLog.git"
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/renpwn/simpleLog",
|
|
31
31
|
"bugs": {
|
package/src/Formatter.js
CHANGED
|
@@ -1,21 +1,83 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const EXT = {
|
|
2
|
+
// --- grayscale (10)
|
|
3
|
+
gray0:232, gray1:233, gray2:234, gray3:235, gray4:236,
|
|
4
|
+
gray5:237, gray6:238, gray7:239, gray8:240, gray9:241,
|
|
5
|
+
|
|
6
|
+
// --- soft colors (pastel-ish)
|
|
7
|
+
softRed:203,
|
|
8
|
+
softGreen:114,
|
|
9
|
+
softYellow:221,
|
|
10
|
+
softBlue:111,
|
|
11
|
+
softMagenta:183,
|
|
12
|
+
softCyan:159,
|
|
13
|
+
|
|
14
|
+
// --- strong colors
|
|
15
|
+
orange:208,
|
|
16
|
+
pink:212,
|
|
17
|
+
violet:177,
|
|
18
|
+
teal:37,
|
|
19
|
+
lime:154,
|
|
20
|
+
amber:214,
|
|
21
|
+
|
|
22
|
+
// --- extra useful
|
|
23
|
+
gold:220,
|
|
24
|
+
sky:117,
|
|
25
|
+
mint:121,
|
|
26
|
+
coral:209,
|
|
27
|
+
indigo:63,
|
|
28
|
+
brown:130,
|
|
29
|
+
olive:100,
|
|
30
|
+
navy:17,
|
|
31
|
+
maroon:124,
|
|
32
|
+
aqua:51,
|
|
33
|
+
chartreuse:118,
|
|
34
|
+
plum:176,
|
|
35
|
+
salmon:210,
|
|
36
|
+
steel:67,
|
|
37
|
+
sand:215,
|
|
38
|
+
forest:28,
|
|
39
|
+
wine:88,
|
|
40
|
+
slate:66,
|
|
41
|
+
smoke:245
|
|
4
42
|
}
|
|
5
|
-
|
|
43
|
+
|
|
44
|
+
const COLORS = Object.assign({
|
|
45
|
+
// --- basic (8)
|
|
46
|
+
black:30, red:31, green:32, yellow:33,
|
|
47
|
+
blue:34, magenta:35, cyan:36, white:37,
|
|
48
|
+
|
|
49
|
+
// --- bright (8)
|
|
50
|
+
brightBlack:90, brightRed:91, brightGreen:92, brightYellow:93,
|
|
51
|
+
brightBlue:94, brightMagenta:95, brightCyan:96, brightWhite:97
|
|
52
|
+
}, EXT)
|
|
53
|
+
|
|
54
|
+
const BG = Object.assign({
|
|
55
|
+
// --- basic
|
|
6
56
|
black:40, red:41, green:42, yellow:43,
|
|
7
|
-
blue:44, magenta:45, cyan:46, white:47
|
|
8
|
-
|
|
57
|
+
blue:44, magenta:45, cyan:46, white:47,
|
|
58
|
+
|
|
59
|
+
// --- bright
|
|
60
|
+
brightBlack:100, brightRed:101, brightGreen:102, brightYellow:103,
|
|
61
|
+
brightBlue:104, brightMagenta:105, brightCyan:106, brightWhite:107
|
|
62
|
+
}, EXT)
|
|
9
63
|
|
|
10
64
|
export function format(text, style, tty = true) {
|
|
11
65
|
if (!tty || !style) return text
|
|
66
|
+
COLORS = COLORS.concat(EXT)
|
|
67
|
+
BG = BG.concat(EXT)
|
|
12
68
|
|
|
13
69
|
const codes = []
|
|
14
70
|
if (style.bold) codes.push(1)
|
|
15
71
|
if (style.dim) codes.push(2)
|
|
16
|
-
|
|
17
|
-
|
|
72
|
+
|
|
73
|
+
// foreground
|
|
74
|
+
const c = COLORS[style.color]
|
|
75
|
+
style.color in COLORS && codes.push(c <= 97 ? c : `38;5;${c}`)
|
|
18
76
|
|
|
77
|
+
// background
|
|
78
|
+
const b = BG[style.bg]
|
|
79
|
+
style.bg in BG && codes.push(b <= 107 ? b : `48;5;${b}`)
|
|
80
|
+
|
|
19
81
|
return codes.length
|
|
20
82
|
? `\x1b[${codes.join(';')}m${text}\x1b[0m`
|
|
21
83
|
: text
|