@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.
Files changed (3) hide show
  1. package/README.md +224 -39
  2. package/package.json +2 -2
  3. 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 bar, file output, safe stringify, and zero dependencies.
3
+ > Lightweight, opinionated, **TTY-aware logger** for Node.js with progress bars, file output, safe stringify, and zero dependencies.
4
4
 
5
5
  [![NPM](https://img.shields.io/npm/v/@renpwn/simplelog)](https://www.npmjs.com/package/@renpwn/simplelog)
6
6
  [![Downloads](https://img.shields.io/npm/dm/@renpwn/simplelog)](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 crash, truncate)
15
- - ๐Ÿ•’ Timestamp with locale (`id`, `en`)
16
- - ๐Ÿ“ File logging (TXT / JSONL + auto backup)
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
- - ๐Ÿงน Non-TTY & CI safe
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 Example
60
+ ## ๐Ÿง  Full Usage Examples
61
61
 
62
- ### 1๏ธโƒฃ Logger dengan Level, Warna & Waktu
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: 'id', // id | en
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
- ๐Ÿ“Œ **Keterangan**
83
- - `level` โ†’ filter minimum level yang ditampilkan
84
- - `color` โ†’ otomatis nonaktif jika non-TTY
85
- - `time` โ†’ format waktu ringkas & konsisten
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
- ๐Ÿ“Œ Object akan di-`JSON.stringify`, dan otomatis dipotong jika terlalu panjang.
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
- ๐Ÿ“Œ File write aman dengan auto-backup `.bak`.
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
- ๐Ÿ“Œ **Catatan**
170
- - Progress hanya muncul di TTY
171
- - Log biasa akan membersihkan progress lalu merender ulang
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
- ## ๐Ÿงฉ API Ringkas
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 # entry point (simpleLog)
251
- โ”‚
252
- โ”œโ”€ Logger.js # logger utama
253
- โ”œโ”€ Levels.js # level & style
254
- โ”œโ”€ Formatter.js # ANSI formatter
255
- โ”œโ”€ Stringify.js # stringify + truncate
256
- โ”œโ”€ Time.js # time formatter
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 # progress state
261
- โ””โ”€ ProgressRenderer.js # progress bar renderer
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
- - No dependency
454
+ - Zero dependencies
270
455
  - Predictable output
271
- - Audit friendly
456
+ - Audit-friendly
272
457
  - Library-first design
273
458
 
274
- Cocok untuk:
459
+ Perfect for:
275
460
  - CLI tools
276
- - Bot WhatsApp / Telegram
277
- - Scraper
278
- - Worker / queue
279
- - Base library (`simpleStore`, `simpleFetch`, dll)
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.1",
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": "git+https://github.com/renpwn/simpleLog.git"
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 COLORS = {
2
- black:30, red:31, green:32, yellow:33,
3
- blue:34, magenta:35, cyan:36, white:37
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
- const BG = {
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
- if (style.color && COLORS[style.color]) codes.push(COLORS[style.color])
17
- if (style.bg && BG[style.bg]) codes.push(BG[style.bg])
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