@logtape/pretty 1.0.0-dev.231 → 1.0.0-dev.234
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 +167 -92
- package/deno.json +1 -1
- package/dist/formatter.cjs +78 -84
- package/dist/formatter.d.cts +25 -35
- package/dist/formatter.d.cts.map +1 -1
- package/dist/formatter.d.ts +25 -35
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +78 -84
- package/dist/formatter.js.map +1 -1
- package/dist/wcwidth.cjs +193 -2
- package/dist/wcwidth.js +193 -2
- package/dist/wcwidth.js.map +1 -1
- package/formatter.test.ts +24 -2
- package/formatter.ts +121 -143
- package/package.json +3 -3
- package/wcwidth.ts +210 -179
package/dist/formatter.d.cts
CHANGED
|
@@ -80,7 +80,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
80
80
|
*
|
|
81
81
|
* @default `"rgb(100,116,139)"` (slate gray)
|
|
82
82
|
*/
|
|
83
|
-
timestampColor?: Color;
|
|
83
|
+
readonly timestampColor?: Color;
|
|
84
84
|
/**
|
|
85
85
|
* Visual style applied to timestamp text.
|
|
86
86
|
*
|
|
@@ -99,7 +99,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
99
99
|
*
|
|
100
100
|
* @default `"dim"`
|
|
101
101
|
*/
|
|
102
|
-
timestampStyle?: Style;
|
|
102
|
+
readonly timestampStyle?: Style;
|
|
103
103
|
/**
|
|
104
104
|
* Custom colors for each log level.
|
|
105
105
|
*
|
|
@@ -119,7 +119,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
119
119
|
*
|
|
120
120
|
* @default Built-in color scheme (purple trace, blue debug, green info, amber warning, red error, dark red fatal)
|
|
121
121
|
*/
|
|
122
|
-
levelColors?: Partial<Record<LogLevel, Color>>;
|
|
122
|
+
readonly levelColors?: Partial<Record<LogLevel, Color>>;
|
|
123
123
|
/**
|
|
124
124
|
* Visual style applied to log level text.
|
|
125
125
|
*
|
|
@@ -136,9 +136,9 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
136
136
|
* levelStyle: null // No additional styling
|
|
137
137
|
* ```
|
|
138
138
|
*
|
|
139
|
-
* @default `
|
|
139
|
+
* @default `"underline"`
|
|
140
140
|
*/
|
|
141
|
-
levelStyle?: Style;
|
|
141
|
+
readonly levelStyle?: Style;
|
|
142
142
|
/**
|
|
143
143
|
* Icon configuration for each log level.
|
|
144
144
|
*
|
|
@@ -162,7 +162,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
162
162
|
*
|
|
163
163
|
* @default `true` (use default emoji icons)
|
|
164
164
|
*/
|
|
165
|
-
icons?: boolean | Partial<Record<LogLevel, string>>;
|
|
165
|
+
readonly icons?: boolean | Partial<Record<LogLevel, string>>;
|
|
166
166
|
/**
|
|
167
167
|
* Character(s) used to separate category hierarchy levels.
|
|
168
168
|
*
|
|
@@ -180,7 +180,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
180
180
|
*
|
|
181
181
|
* @default `"·"` (interpunct)
|
|
182
182
|
*/
|
|
183
|
-
categorySeparator?: string;
|
|
183
|
+
readonly categorySeparator?: string;
|
|
184
184
|
/**
|
|
185
185
|
* Default color for category display.
|
|
186
186
|
*
|
|
@@ -197,7 +197,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
197
197
|
*
|
|
198
198
|
* @default `"rgb(100,116,139)"` (slate gray)
|
|
199
199
|
*/
|
|
200
|
-
categoryColor?: Color;
|
|
200
|
+
readonly categoryColor?: Color;
|
|
201
201
|
/**
|
|
202
202
|
* Category-specific color mapping based on prefixes.
|
|
203
203
|
*
|
|
@@ -215,7 +215,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
215
215
|
* ])
|
|
216
216
|
* ```
|
|
217
217
|
*/
|
|
218
|
-
categoryColorMap?: CategoryColorMap;
|
|
218
|
+
readonly categoryColorMap?: CategoryColorMap;
|
|
219
219
|
/**
|
|
220
220
|
* Visual style applied to category text.
|
|
221
221
|
*
|
|
@@ -234,26 +234,16 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
234
234
|
*
|
|
235
235
|
* @default `["dim", "italic"]` (dimmed for subtle appearance)
|
|
236
236
|
*/
|
|
237
|
-
categoryStyle?: Style;
|
|
237
|
+
readonly categoryStyle?: Style;
|
|
238
238
|
/**
|
|
239
239
|
* Maximum display width for category names.
|
|
240
240
|
*
|
|
241
241
|
* Controls layout consistency by limiting category width.
|
|
242
242
|
* Long categories are truncated according to `categoryTruncate` strategy.
|
|
243
243
|
*
|
|
244
|
-
*
|
|
245
|
-
* - `"auto"`: No width limit, categories display at full length
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* ```typescript
|
|
249
|
-
* categoryWidth: 20 // Limit to 20 characters
|
|
250
|
-
* categoryWidth: 30 // Limit to 30 characters
|
|
251
|
-
* categoryWidth: "auto" // No limit
|
|
252
|
-
* ```
|
|
253
|
-
*
|
|
254
|
-
* @default `20` (20 character limit)
|
|
244
|
+
* @default `20`
|
|
255
245
|
*/
|
|
256
|
-
categoryWidth?: number
|
|
246
|
+
readonly categoryWidth?: number;
|
|
257
247
|
/**
|
|
258
248
|
* Strategy for truncating long category names.
|
|
259
249
|
*
|
|
@@ -273,7 +263,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
273
263
|
*
|
|
274
264
|
* @default `"middle"` (smart context-preserving truncation)
|
|
275
265
|
*/
|
|
276
|
-
categoryTruncate?: TruncationStrategy;
|
|
266
|
+
readonly categoryTruncate?: TruncationStrategy;
|
|
277
267
|
/**
|
|
278
268
|
* Color for log message text content.
|
|
279
269
|
*
|
|
@@ -290,7 +280,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
290
280
|
*
|
|
291
281
|
* @default `"rgb(148,163,184)"` (light slate gray)
|
|
292
282
|
*/
|
|
293
|
-
messageColor?: Color;
|
|
283
|
+
readonly messageColor?: Color;
|
|
294
284
|
/**
|
|
295
285
|
* Visual style applied to log message text.
|
|
296
286
|
*
|
|
@@ -309,7 +299,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
309
299
|
*
|
|
310
300
|
* @default `"dim"` (dimmed for subtle readability)
|
|
311
301
|
*/
|
|
312
|
-
messageStyle?: Style;
|
|
302
|
+
readonly messageStyle?: Style;
|
|
313
303
|
/**
|
|
314
304
|
* Global color control for the entire formatter.
|
|
315
305
|
*
|
|
@@ -325,7 +315,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
325
315
|
*
|
|
326
316
|
* @default `true` (colors enabled)
|
|
327
317
|
*/
|
|
328
|
-
colors?: boolean;
|
|
318
|
+
readonly colors?: boolean;
|
|
329
319
|
/**
|
|
330
320
|
* Column alignment for consistent visual layout.
|
|
331
321
|
*
|
|
@@ -341,7 +331,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
341
331
|
*
|
|
342
332
|
* @default `true` (alignment enabled)
|
|
343
333
|
*/
|
|
344
|
-
align?: boolean;
|
|
334
|
+
readonly align?: boolean;
|
|
345
335
|
/**
|
|
346
336
|
* Configuration for structured value inspection and rendering.
|
|
347
337
|
*
|
|
@@ -359,22 +349,22 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
359
349
|
*
|
|
360
350
|
* @default `{}` (use built-in defaults: depth=unlimited, colors=auto, compact=true)
|
|
361
351
|
*/
|
|
362
|
-
inspectOptions?: {
|
|
352
|
+
readonly inspectOptions?: {
|
|
363
353
|
/**
|
|
364
354
|
* Maximum depth to traverse when inspecting nested objects.
|
|
365
355
|
* @default Infinity (no depth limit)
|
|
366
356
|
*/
|
|
367
|
-
depth?: number;
|
|
357
|
+
readonly depth?: number;
|
|
368
358
|
/**
|
|
369
359
|
* Whether to use syntax highlighting colors for inspected values.
|
|
370
360
|
* @default Inherited from global `colors` setting
|
|
371
361
|
*/
|
|
372
|
-
colors?: boolean;
|
|
362
|
+
readonly colors?: boolean;
|
|
373
363
|
/**
|
|
374
364
|
* Whether to use compact formatting for objects and arrays.
|
|
375
365
|
* @default `true` (compact formatting)
|
|
376
366
|
*/
|
|
377
|
-
compact?: boolean;
|
|
367
|
+
readonly compact?: boolean;
|
|
378
368
|
};
|
|
379
369
|
/**
|
|
380
370
|
* Enable word wrapping for long messages.
|
|
@@ -399,10 +389,10 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
399
389
|
* wordWrap: false
|
|
400
390
|
* ```
|
|
401
391
|
*
|
|
402
|
-
* @default `
|
|
392
|
+
* @default `true` (auto-detect terminal width)
|
|
403
393
|
* @since 1.0.0
|
|
404
394
|
*/
|
|
405
|
-
wordWrap?: boolean | number;
|
|
395
|
+
readonly wordWrap?: boolean | number;
|
|
406
396
|
}
|
|
407
397
|
/**
|
|
408
398
|
* Creates a beautiful console formatter optimized for local development.
|
|
@@ -426,7 +416,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
426
416
|
* @example
|
|
427
417
|
* ```typescript
|
|
428
418
|
* import { configure } from "@logtape/logtape";
|
|
429
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
419
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
430
420
|
* import { getPrettyFormatter } from "@logtape/pretty";
|
|
431
421
|
*
|
|
432
422
|
* await configure({
|
|
@@ -468,7 +458,7 @@ declare function getPrettyFormatter(options?: PrettyFormatterOptions): TextForma
|
|
|
468
458
|
* @example
|
|
469
459
|
* ```typescript
|
|
470
460
|
* import { configure } from "@logtape/logtape";
|
|
471
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
461
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
472
462
|
* import { prettyFormatter } from "@logtape/pretty";
|
|
473
463
|
*
|
|
474
464
|
* await configure({
|
package/dist/formatter.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.cts","names":[],"sources":["../formatter.ts"],"sourcesContent":[],"mappings":";;;;;;;AAQ0E;AAiChE,cAPJ,MAqBI,EAAA;EAKE,SAAK,KAAA,EAAA,WACA;EAsBL,SAAA,IAAA,EAAA,WAAgB;EAAA,SAAA,GAAA,EAAA,WAAA;EAAA,SAA0B,MAAA,EAAA,WAAA;EAAK,SAA5B,SAAA,EAAA,WAAA;EAAG,SAAA,aAAA,EAAA,WAAA;AAalC,CAAA;;;;AAA8D,cAlDxD,UAkDwD,EAAA;
|
|
1
|
+
{"version":3,"file":"formatter.d.cts","names":[],"sources":["../formatter.ts"],"sourcesContent":[],"mappings":";;;;;;;AAQ0E;AAiChE,cAPJ,MAqBI,EAAA;EAKE,SAAK,KAAA,EAAA,WACA;EAsBL,SAAA,IAAA,EAAA,WAAgB;EAAA,SAAA,GAAA,EAAA,WAAA;EAAA,SAA0B,MAAA,EAAA,WAAA;EAAK,SAA5B,SAAA,EAAA,WAAA;EAAG,SAAA,aAAA,EAAA,WAAA;AAalC,CAAA;;;;AAA8D,cAlDxD,UAkDwD,EAAA;EA8K7C,SAAA,KAAA,EAAA,YACf;EAAA,SAAA,GAAA,EAAA,YAAA;EAAA,SAAa,KAAA,EAAA,YAAA;EAAoB,SAiBP,MAAA,EAAA,YAAA;EAAK,SAoBL,IAAA,EAAA,YAAA;EAAK,SAqBO,OAAA,EAAA,YAAA;EAAQ,SAAE,IAAA,EAAA,YAAA;EAAK,SAAtB,KAAA,EAAA,YAAA;CAAM;;;;AA6CV,KA1TjB,KAAA,GA0TiB,MAAA,OAzTZ,UAyTY,GAAA,OAAA,MAAA,IAAA,MAAA,IAAA,MAAA,GAAA,GAAA,IAAA,MAAA,EAAA,GAAA,IAAA;;;;;;;;AAvGf;AAyYd;;;;AAEgB;AA4VhB;;;;KAn6BY,gBAAA,GAAmB,uBAAuB;;;;KAa1C,KAAA,gBAAqB,uBAAuB;;;;;;;;;;;UA8KvC,sBAAA,SACP,KAAK;;;;;;;;;;;;;;;;;4BAiBa;;;;;;;;;;;;;;;;;;;4BAoBA;;;;;;;;;;;;;;;;;;;;yBAqBH,QAAQ,OAAO,UAAU;;;;;;;;;;;;;;;;;;;wBAoB1B;;;;;;;;;;;;;;;;;;;;;;;;6BAyBK,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAqCjB;;;;;;;;;;;;;;;;;;8BAmBG;;;;;;;;;;;;;;;;;;;2BAoBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BA+BG;;;;;;;;;;;;;;;;;0BAkBJ;;;;;;;;;;;;;;;;;;;0BAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiJV,kBAAA,WACL,yBACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4VU,iBAAiB"}
|
package/dist/formatter.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
80
80
|
*
|
|
81
81
|
* @default `"rgb(100,116,139)"` (slate gray)
|
|
82
82
|
*/
|
|
83
|
-
timestampColor?: Color;
|
|
83
|
+
readonly timestampColor?: Color;
|
|
84
84
|
/**
|
|
85
85
|
* Visual style applied to timestamp text.
|
|
86
86
|
*
|
|
@@ -99,7 +99,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
99
99
|
*
|
|
100
100
|
* @default `"dim"`
|
|
101
101
|
*/
|
|
102
|
-
timestampStyle?: Style;
|
|
102
|
+
readonly timestampStyle?: Style;
|
|
103
103
|
/**
|
|
104
104
|
* Custom colors for each log level.
|
|
105
105
|
*
|
|
@@ -119,7 +119,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
119
119
|
*
|
|
120
120
|
* @default Built-in color scheme (purple trace, blue debug, green info, amber warning, red error, dark red fatal)
|
|
121
121
|
*/
|
|
122
|
-
levelColors?: Partial<Record<LogLevel, Color>>;
|
|
122
|
+
readonly levelColors?: Partial<Record<LogLevel, Color>>;
|
|
123
123
|
/**
|
|
124
124
|
* Visual style applied to log level text.
|
|
125
125
|
*
|
|
@@ -136,9 +136,9 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
136
136
|
* levelStyle: null // No additional styling
|
|
137
137
|
* ```
|
|
138
138
|
*
|
|
139
|
-
* @default `
|
|
139
|
+
* @default `"underline"`
|
|
140
140
|
*/
|
|
141
|
-
levelStyle?: Style;
|
|
141
|
+
readonly levelStyle?: Style;
|
|
142
142
|
/**
|
|
143
143
|
* Icon configuration for each log level.
|
|
144
144
|
*
|
|
@@ -162,7 +162,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
162
162
|
*
|
|
163
163
|
* @default `true` (use default emoji icons)
|
|
164
164
|
*/
|
|
165
|
-
icons?: boolean | Partial<Record<LogLevel, string>>;
|
|
165
|
+
readonly icons?: boolean | Partial<Record<LogLevel, string>>;
|
|
166
166
|
/**
|
|
167
167
|
* Character(s) used to separate category hierarchy levels.
|
|
168
168
|
*
|
|
@@ -180,7 +180,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
180
180
|
*
|
|
181
181
|
* @default `"·"` (interpunct)
|
|
182
182
|
*/
|
|
183
|
-
categorySeparator?: string;
|
|
183
|
+
readonly categorySeparator?: string;
|
|
184
184
|
/**
|
|
185
185
|
* Default color for category display.
|
|
186
186
|
*
|
|
@@ -197,7 +197,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
197
197
|
*
|
|
198
198
|
* @default `"rgb(100,116,139)"` (slate gray)
|
|
199
199
|
*/
|
|
200
|
-
categoryColor?: Color;
|
|
200
|
+
readonly categoryColor?: Color;
|
|
201
201
|
/**
|
|
202
202
|
* Category-specific color mapping based on prefixes.
|
|
203
203
|
*
|
|
@@ -215,7 +215,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
215
215
|
* ])
|
|
216
216
|
* ```
|
|
217
217
|
*/
|
|
218
|
-
categoryColorMap?: CategoryColorMap;
|
|
218
|
+
readonly categoryColorMap?: CategoryColorMap;
|
|
219
219
|
/**
|
|
220
220
|
* Visual style applied to category text.
|
|
221
221
|
*
|
|
@@ -234,26 +234,16 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
234
234
|
*
|
|
235
235
|
* @default `["dim", "italic"]` (dimmed for subtle appearance)
|
|
236
236
|
*/
|
|
237
|
-
categoryStyle?: Style;
|
|
237
|
+
readonly categoryStyle?: Style;
|
|
238
238
|
/**
|
|
239
239
|
* Maximum display width for category names.
|
|
240
240
|
*
|
|
241
241
|
* Controls layout consistency by limiting category width.
|
|
242
242
|
* Long categories are truncated according to `categoryTruncate` strategy.
|
|
243
243
|
*
|
|
244
|
-
*
|
|
245
|
-
* - `"auto"`: No width limit, categories display at full length
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* ```typescript
|
|
249
|
-
* categoryWidth: 20 // Limit to 20 characters
|
|
250
|
-
* categoryWidth: 30 // Limit to 30 characters
|
|
251
|
-
* categoryWidth: "auto" // No limit
|
|
252
|
-
* ```
|
|
253
|
-
*
|
|
254
|
-
* @default `20` (20 character limit)
|
|
244
|
+
* @default `20`
|
|
255
245
|
*/
|
|
256
|
-
categoryWidth?: number
|
|
246
|
+
readonly categoryWidth?: number;
|
|
257
247
|
/**
|
|
258
248
|
* Strategy for truncating long category names.
|
|
259
249
|
*
|
|
@@ -273,7 +263,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
273
263
|
*
|
|
274
264
|
* @default `"middle"` (smart context-preserving truncation)
|
|
275
265
|
*/
|
|
276
|
-
categoryTruncate?: TruncationStrategy;
|
|
266
|
+
readonly categoryTruncate?: TruncationStrategy;
|
|
277
267
|
/**
|
|
278
268
|
* Color for log message text content.
|
|
279
269
|
*
|
|
@@ -290,7 +280,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
290
280
|
*
|
|
291
281
|
* @default `"rgb(148,163,184)"` (light slate gray)
|
|
292
282
|
*/
|
|
293
|
-
messageColor?: Color;
|
|
283
|
+
readonly messageColor?: Color;
|
|
294
284
|
/**
|
|
295
285
|
* Visual style applied to log message text.
|
|
296
286
|
*
|
|
@@ -309,7 +299,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
309
299
|
*
|
|
310
300
|
* @default `"dim"` (dimmed for subtle readability)
|
|
311
301
|
*/
|
|
312
|
-
messageStyle?: Style;
|
|
302
|
+
readonly messageStyle?: Style;
|
|
313
303
|
/**
|
|
314
304
|
* Global color control for the entire formatter.
|
|
315
305
|
*
|
|
@@ -325,7 +315,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
325
315
|
*
|
|
326
316
|
* @default `true` (colors enabled)
|
|
327
317
|
*/
|
|
328
|
-
colors?: boolean;
|
|
318
|
+
readonly colors?: boolean;
|
|
329
319
|
/**
|
|
330
320
|
* Column alignment for consistent visual layout.
|
|
331
321
|
*
|
|
@@ -341,7 +331,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
341
331
|
*
|
|
342
332
|
* @default `true` (alignment enabled)
|
|
343
333
|
*/
|
|
344
|
-
align?: boolean;
|
|
334
|
+
readonly align?: boolean;
|
|
345
335
|
/**
|
|
346
336
|
* Configuration for structured value inspection and rendering.
|
|
347
337
|
*
|
|
@@ -359,22 +349,22 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
359
349
|
*
|
|
360
350
|
* @default `{}` (use built-in defaults: depth=unlimited, colors=auto, compact=true)
|
|
361
351
|
*/
|
|
362
|
-
inspectOptions?: {
|
|
352
|
+
readonly inspectOptions?: {
|
|
363
353
|
/**
|
|
364
354
|
* Maximum depth to traverse when inspecting nested objects.
|
|
365
355
|
* @default Infinity (no depth limit)
|
|
366
356
|
*/
|
|
367
|
-
depth?: number;
|
|
357
|
+
readonly depth?: number;
|
|
368
358
|
/**
|
|
369
359
|
* Whether to use syntax highlighting colors for inspected values.
|
|
370
360
|
* @default Inherited from global `colors` setting
|
|
371
361
|
*/
|
|
372
|
-
colors?: boolean;
|
|
362
|
+
readonly colors?: boolean;
|
|
373
363
|
/**
|
|
374
364
|
* Whether to use compact formatting for objects and arrays.
|
|
375
365
|
* @default `true` (compact formatting)
|
|
376
366
|
*/
|
|
377
|
-
compact?: boolean;
|
|
367
|
+
readonly compact?: boolean;
|
|
378
368
|
};
|
|
379
369
|
/**
|
|
380
370
|
* Enable word wrapping for long messages.
|
|
@@ -399,10 +389,10 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
399
389
|
* wordWrap: false
|
|
400
390
|
* ```
|
|
401
391
|
*
|
|
402
|
-
* @default `
|
|
392
|
+
* @default `true` (auto-detect terminal width)
|
|
403
393
|
* @since 1.0.0
|
|
404
394
|
*/
|
|
405
|
-
wordWrap?: boolean | number;
|
|
395
|
+
readonly wordWrap?: boolean | number;
|
|
406
396
|
}
|
|
407
397
|
/**
|
|
408
398
|
* Creates a beautiful console formatter optimized for local development.
|
|
@@ -426,7 +416,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
426
416
|
* @example
|
|
427
417
|
* ```typescript
|
|
428
418
|
* import { configure } from "@logtape/logtape";
|
|
429
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
419
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
430
420
|
* import { getPrettyFormatter } from "@logtape/pretty";
|
|
431
421
|
*
|
|
432
422
|
* await configure({
|
|
@@ -468,7 +458,7 @@ declare function getPrettyFormatter(options?: PrettyFormatterOptions): TextForma
|
|
|
468
458
|
* @example
|
|
469
459
|
* ```typescript
|
|
470
460
|
* import { configure } from "@logtape/logtape";
|
|
471
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
461
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
472
462
|
* import { prettyFormatter } from "@logtape/pretty";
|
|
473
463
|
*
|
|
474
464
|
* await configure({
|
package/dist/formatter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","names":[],"sources":["../formatter.ts"],"sourcesContent":[],"mappings":";;;;;;;AAQ0E;AAiChE,cAPJ,MAqBI,EAAA;EAKE,SAAK,KAAA,EAAA,WACA;EAsBL,SAAA,IAAA,EAAA,WAAgB;EAAA,SAAA,GAAA,EAAA,WAAA;EAAA,SAA0B,MAAA,EAAA,WAAA;EAAK,SAA5B,SAAA,EAAA,WAAA;EAAG,SAAA,aAAA,EAAA,WAAA;AAalC,CAAA;;;;AAA8D,cAlDxD,UAkDwD,EAAA;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","names":[],"sources":["../formatter.ts"],"sourcesContent":[],"mappings":";;;;;;;AAQ0E;AAiChE,cAPJ,MAqBI,EAAA;EAKE,SAAK,KAAA,EAAA,WACA;EAsBL,SAAA,IAAA,EAAA,WAAgB;EAAA,SAAA,GAAA,EAAA,WAAA;EAAA,SAA0B,MAAA,EAAA,WAAA;EAAK,SAA5B,SAAA,EAAA,WAAA;EAAG,SAAA,aAAA,EAAA,WAAA;AAalC,CAAA;;;;AAA8D,cAlDxD,UAkDwD,EAAA;EA8K7C,SAAA,KAAA,EAAA,YACf;EAAA,SAAA,GAAA,EAAA,YAAA;EAAA,SAAa,KAAA,EAAA,YAAA;EAAoB,SAiBP,MAAA,EAAA,YAAA;EAAK,SAoBL,IAAA,EAAA,YAAA;EAAK,SAqBO,OAAA,EAAA,YAAA;EAAQ,SAAE,IAAA,EAAA,YAAA;EAAK,SAAtB,KAAA,EAAA,YAAA;CAAM;;;;AA6CV,KA1TjB,KAAA,GA0TiB,MAAA,OAzTZ,UAyTY,GAAA,OAAA,MAAA,IAAA,MAAA,IAAA,MAAA,GAAA,GAAA,IAAA,MAAA,EAAA,GAAA,IAAA;;;;;;;;AAvGf;AAyYd;;;;AAEgB;AA4VhB;;;;KAn6BY,gBAAA,GAAmB,uBAAuB;;;;KAa1C,KAAA,gBAAqB,uBAAuB;;;;;;;;;;;UA8KvC,sBAAA,SACP,KAAK;;;;;;;;;;;;;;;;;4BAiBa;;;;;;;;;;;;;;;;;;;4BAoBA;;;;;;;;;;;;;;;;;;;;yBAqBH,QAAQ,OAAO,UAAU;;;;;;;;;;;;;;;;;;;wBAoB1B;;;;;;;;;;;;;;;;;;;;;;;;6BAyBK,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAqCjB;;;;;;;;;;;;;;;;;;8BAmBG;;;;;;;;;;;;;;;;;;;2BAoBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BA+BG;;;;;;;;;;;;;;;;;0BAkBJ;;;;;;;;;;;;;;;;;;;0BAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiJV,kBAAA,WACL,yBACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4VU,iBAAiB"}
|
package/dist/formatter.js
CHANGED
|
@@ -45,18 +45,20 @@ const ansiColors = {
|
|
|
45
45
|
cyan: "\x1B[36m",
|
|
46
46
|
white: "\x1B[37m"
|
|
47
47
|
};
|
|
48
|
+
const RGB_PATTERN = /^rgb\((\d+),(\d+),(\d+)\)$/;
|
|
49
|
+
const HEX_PATTERN = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
48
50
|
/**
|
|
49
51
|
* Helper function to convert color to ANSI escape code
|
|
50
52
|
*/
|
|
51
53
|
function colorToAnsi(color) {
|
|
52
54
|
if (color === null) return "";
|
|
53
55
|
if (color in ansiColors) return ansiColors[color];
|
|
54
|
-
const rgbMatch = color.match(
|
|
56
|
+
const rgbMatch = color.match(RGB_PATTERN);
|
|
55
57
|
if (rgbMatch) {
|
|
56
58
|
const [, r, g, b] = rgbMatch;
|
|
57
59
|
return `\x1b[38;2;${r};${g};${b}m`;
|
|
58
60
|
}
|
|
59
|
-
const hexMatch = color.match(
|
|
61
|
+
const hexMatch = color.match(HEX_PATTERN);
|
|
60
62
|
if (hexMatch) {
|
|
61
63
|
let hex = hexMatch[1];
|
|
62
64
|
if (hex.length === 3) hex = hex.split("").map((c) => c + c).join("");
|
|
@@ -125,14 +127,9 @@ const defaultIcons = {
|
|
|
125
127
|
* @returns A new icon map with consistent spacing
|
|
126
128
|
*/
|
|
127
129
|
function normalizeIconSpacing(iconMap) {
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
const currentWidth = getDisplayWidth(icon);
|
|
132
|
-
const spacesToAdd = maxWidth - currentWidth;
|
|
133
|
-
normalizedMap[level] = icon + " ".repeat(spacesToAdd);
|
|
134
|
-
}
|
|
135
|
-
return normalizedMap;
|
|
130
|
+
const entries = Object.entries(iconMap);
|
|
131
|
+
const maxWidth = Math.max(...entries.map(([, icon]) => getDisplayWidth(icon)));
|
|
132
|
+
return Object.fromEntries(entries.map(([level, icon]) => [level, icon + " ".repeat(maxWidth - getDisplayWidth(icon))]));
|
|
136
133
|
}
|
|
137
134
|
/**
|
|
138
135
|
* Platform-specific inspect function. Uses Node.js `util.inspect()` which
|
|
@@ -171,7 +168,7 @@ const inspect$1 = typeof document !== "undefined" || typeof navigator !== "undef
|
|
|
171
168
|
* @example
|
|
172
169
|
* ```typescript
|
|
173
170
|
* import { configure } from "@logtape/logtape";
|
|
174
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
171
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
175
172
|
* import { getPrettyFormatter } from "@logtape/pretty";
|
|
176
173
|
*
|
|
177
174
|
* await configure({
|
|
@@ -193,7 +190,7 @@ const inspect$1 = typeof document !== "undefined" || typeof navigator !== "undef
|
|
|
193
190
|
* @since 1.0.0
|
|
194
191
|
*/
|
|
195
192
|
function getPrettyFormatter(options = {}) {
|
|
196
|
-
const { timestamp = "none", timestampColor = "rgb(100,116,139)", timestampStyle = "dim", level: levelFormat = "full", levelColors = {}, levelStyle = "underline", icons = true, categorySeparator = "·", categoryColor = "rgb(100,116,139)", categoryColorMap = /* @__PURE__ */ new Map(), categoryStyle = ["dim", "italic"], categoryWidth = 20, categoryTruncate = "middle", messageColor = "rgb(148,163,184)", messageStyle = "dim", colors: useColors = true, align = true, inspectOptions = {}, wordWrap =
|
|
193
|
+
const { timestamp = "none", timestampColor = "rgb(100,116,139)", timestampStyle = "dim", level: levelFormat = "full", levelColors = {}, levelStyle = "underline", icons = true, categorySeparator = "·", categoryColor = "rgb(100,116,139)", categoryColorMap = /* @__PURE__ */ new Map(), categoryStyle = ["dim", "italic"], categoryWidth = 20, categoryTruncate = "middle", messageColor = "rgb(148,163,184)", messageStyle = "dim", colors: useColors = true, align = true, inspectOptions = {}, wordWrap = true } = options;
|
|
197
194
|
const baseIconMap = icons === false ? {
|
|
198
195
|
trace: "",
|
|
199
196
|
debug: "",
|
|
@@ -215,81 +212,78 @@ function getPrettyFormatter(options = {}) {
|
|
|
215
212
|
fatal: defaultColors.fatal,
|
|
216
213
|
...levelColors
|
|
217
214
|
};
|
|
215
|
+
const levelMappings = {
|
|
216
|
+
"ABBR": {
|
|
217
|
+
trace: "TRC",
|
|
218
|
+
debug: "DBG",
|
|
219
|
+
info: "INF",
|
|
220
|
+
warning: "WRN",
|
|
221
|
+
error: "ERR",
|
|
222
|
+
fatal: "FTL"
|
|
223
|
+
},
|
|
224
|
+
"L": {
|
|
225
|
+
trace: "T",
|
|
226
|
+
debug: "D",
|
|
227
|
+
info: "I",
|
|
228
|
+
warning: "W",
|
|
229
|
+
error: "E",
|
|
230
|
+
fatal: "F"
|
|
231
|
+
},
|
|
232
|
+
"abbr": {
|
|
233
|
+
trace: "trc",
|
|
234
|
+
debug: "dbg",
|
|
235
|
+
info: "inf",
|
|
236
|
+
warning: "wrn",
|
|
237
|
+
error: "err",
|
|
238
|
+
fatal: "ftl"
|
|
239
|
+
},
|
|
240
|
+
"l": {
|
|
241
|
+
trace: "t",
|
|
242
|
+
debug: "d",
|
|
243
|
+
info: "i",
|
|
244
|
+
warning: "w",
|
|
245
|
+
error: "e",
|
|
246
|
+
fatal: "f"
|
|
247
|
+
}
|
|
248
|
+
};
|
|
218
249
|
const formatLevel = (level) => {
|
|
219
250
|
if (typeof levelFormat === "function") return levelFormat(level);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
warning: "w",
|
|
252
|
-
error: "e",
|
|
253
|
-
fatal: "f"
|
|
254
|
-
}[level];
|
|
255
|
-
default: return level;
|
|
256
|
-
}
|
|
251
|
+
if (levelFormat === "FULL") return level.toUpperCase();
|
|
252
|
+
if (levelFormat === "full") return level;
|
|
253
|
+
return levelMappings[levelFormat]?.[level] ?? level;
|
|
254
|
+
};
|
|
255
|
+
const timestampFormatters = {
|
|
256
|
+
"date-time-timezone": (ts) => {
|
|
257
|
+
const iso = new Date(ts).toISOString();
|
|
258
|
+
return iso.replace("T", " ").replace("Z", " +00:00");
|
|
259
|
+
},
|
|
260
|
+
"date-time-tz": (ts) => {
|
|
261
|
+
const iso = new Date(ts).toISOString();
|
|
262
|
+
return iso.replace("T", " ").replace("Z", " +00");
|
|
263
|
+
},
|
|
264
|
+
"date-time": (ts) => {
|
|
265
|
+
const iso = new Date(ts).toISOString();
|
|
266
|
+
return iso.replace("T", " ").replace("Z", "");
|
|
267
|
+
},
|
|
268
|
+
"time-timezone": (ts) => {
|
|
269
|
+
const iso = new Date(ts).toISOString();
|
|
270
|
+
return iso.replace(/.*T/, "").replace("Z", " +00:00");
|
|
271
|
+
},
|
|
272
|
+
"time-tz": (ts) => {
|
|
273
|
+
const iso = new Date(ts).toISOString();
|
|
274
|
+
return iso.replace(/.*T/, "").replace("Z", " +00");
|
|
275
|
+
},
|
|
276
|
+
"time": (ts) => {
|
|
277
|
+
const iso = new Date(ts).toISOString();
|
|
278
|
+
return iso.replace(/.*T/, "").replace("Z", "");
|
|
279
|
+
},
|
|
280
|
+
"date": (ts) => new Date(ts).toISOString().replace(/T.*/, ""),
|
|
281
|
+
"rfc3339": (ts) => new Date(ts).toISOString()
|
|
257
282
|
};
|
|
258
283
|
let timestampFn = null;
|
|
259
284
|
if (timestamp === "none" || timestamp === "disabled") timestampFn = null;
|
|
260
|
-
else if (timestamp === "date-time-timezone") timestampFn = (ts) => {
|
|
261
|
-
const date = new Date(ts);
|
|
262
|
-
return date.toISOString().replace("T", " ").replace("Z", " +00:00");
|
|
263
|
-
};
|
|
264
|
-
else if (timestamp === "date-time-tz") timestampFn = (ts) => {
|
|
265
|
-
const date = new Date(ts);
|
|
266
|
-
return date.toISOString().replace("T", " ").replace("Z", " +00");
|
|
267
|
-
};
|
|
268
|
-
else if (timestamp === "date-time") timestampFn = (ts) => {
|
|
269
|
-
const date = new Date(ts);
|
|
270
|
-
return date.toISOString().replace("T", " ").replace("Z", "");
|
|
271
|
-
};
|
|
272
|
-
else if (timestamp === "time-timezone") timestampFn = (ts) => {
|
|
273
|
-
const date = new Date(ts);
|
|
274
|
-
return date.toISOString().replace(/.*T/, "").replace("Z", " +00:00");
|
|
275
|
-
};
|
|
276
|
-
else if (timestamp === "time-tz") timestampFn = (ts) => {
|
|
277
|
-
const date = new Date(ts);
|
|
278
|
-
return date.toISOString().replace(/.*T/, "").replace("Z", " +00");
|
|
279
|
-
};
|
|
280
|
-
else if (timestamp === "time") timestampFn = (ts) => {
|
|
281
|
-
const date = new Date(ts);
|
|
282
|
-
return date.toISOString().replace(/.*T/, "").replace("Z", "");
|
|
283
|
-
};
|
|
284
|
-
else if (timestamp === "date") timestampFn = (ts) => {
|
|
285
|
-
const date = new Date(ts);
|
|
286
|
-
return date.toISOString().replace(/T.*/, "");
|
|
287
|
-
};
|
|
288
|
-
else if (timestamp === "rfc3339") timestampFn = (ts) => {
|
|
289
|
-
const date = new Date(ts);
|
|
290
|
-
return date.toISOString();
|
|
291
|
-
};
|
|
292
285
|
else if (typeof timestamp === "function") timestampFn = timestamp;
|
|
286
|
+
else timestampFn = timestampFormatters[timestamp] ?? null;
|
|
293
287
|
const wordWrapEnabled = wordWrap !== false;
|
|
294
288
|
let wordWrapWidth;
|
|
295
289
|
if (typeof wordWrap === "number") wordWrapWidth = wordWrap;
|
|
@@ -308,7 +302,7 @@ function getPrettyFormatter(options = {}) {
|
|
|
308
302
|
return (record) => {
|
|
309
303
|
const icon = iconMap[record.level] || "";
|
|
310
304
|
const level = formatLevel(record.level);
|
|
311
|
-
const categoryStr = truncateCategory(record.category,
|
|
305
|
+
const categoryStr = truncateCategory(record.category, categoryWidth, categorySeparator, categoryTruncate);
|
|
312
306
|
let message = "";
|
|
313
307
|
const messageColorCode = useColors ? colorToAnsi(messageColor) : "";
|
|
314
308
|
const messageStyleCode = useColors ? styleToAnsi(messageStyle) : "";
|
|
@@ -359,7 +353,7 @@ function getPrettyFormatter(options = {}) {
|
|
|
359
353
|
const levelColorLength = useColors ? colorToAnsi(resolvedLevelColors[record.level]).length + styleToAnsi(levelStyle).length + RESET.length : 0;
|
|
360
354
|
const categoryColorLength = useColors ? colorToAnsi(finalCategoryColor).length + styleToAnsi(categoryStyle).length + RESET.length : 0;
|
|
361
355
|
const paddedLevel = formattedLevel.padEnd(levelWidth + levelColorLength);
|
|
362
|
-
const paddedCategory = formattedCategory.padEnd(
|
|
356
|
+
const paddedCategory = formattedCategory.padEnd(categoryWidth + categoryColorLength);
|
|
363
357
|
let result = `${formattedTimestamp}${formattedIcon} ${paddedLevel} ${paddedCategory} ${formattedMessage}`;
|
|
364
358
|
if (wordWrapEnabled || message.includes("\n")) result = wrapText(result, wordWrapEnabled ? wordWrapWidth : Infinity, message);
|
|
365
359
|
return result + "\n";
|
|
@@ -390,7 +384,7 @@ function getPrettyFormatter(options = {}) {
|
|
|
390
384
|
* @example
|
|
391
385
|
* ```typescript
|
|
392
386
|
* import { configure } from "@logtape/logtape";
|
|
393
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
387
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
394
388
|
* import { prettyFormatter } from "@logtape/pretty";
|
|
395
389
|
*
|
|
396
390
|
* await configure({
|