@logtape/pretty 1.0.0-dev.232 → 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/deno.json +1 -1
- package/dist/formatter.cjs +2 -2
- package/dist/formatter.d.cts +3 -13
- package/dist/formatter.d.cts.map +1 -1
- package/dist/formatter.d.ts +3 -13
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +2 -2
- package/dist/formatter.js.map +1 -1
- package/formatter.ts +5 -16
- package/package.json +2 -2
package/deno.json
CHANGED
package/dist/formatter.cjs
CHANGED
|
@@ -303,7 +303,7 @@ function getPrettyFormatter(options = {}) {
|
|
|
303
303
|
return (record) => {
|
|
304
304
|
const icon = iconMap[record.level] || "";
|
|
305
305
|
const level = formatLevel(record.level);
|
|
306
|
-
const categoryStr = require_truncate.truncateCategory(record.category,
|
|
306
|
+
const categoryStr = require_truncate.truncateCategory(record.category, categoryWidth, categorySeparator, categoryTruncate);
|
|
307
307
|
let message = "";
|
|
308
308
|
const messageColorCode = useColors ? colorToAnsi(messageColor) : "";
|
|
309
309
|
const messageStyleCode = useColors ? styleToAnsi(messageStyle) : "";
|
|
@@ -354,7 +354,7 @@ function getPrettyFormatter(options = {}) {
|
|
|
354
354
|
const levelColorLength = useColors ? colorToAnsi(resolvedLevelColors[record.level]).length + styleToAnsi(levelStyle).length + RESET.length : 0;
|
|
355
355
|
const categoryColorLength = useColors ? colorToAnsi(finalCategoryColor).length + styleToAnsi(categoryStyle).length + RESET.length : 0;
|
|
356
356
|
const paddedLevel = formattedLevel.padEnd(levelWidth + levelColorLength);
|
|
357
|
-
const paddedCategory = formattedCategory.padEnd(
|
|
357
|
+
const paddedCategory = formattedCategory.padEnd(categoryWidth + categoryColorLength);
|
|
358
358
|
let result = `${formattedTimestamp}${formattedIcon} ${paddedLevel} ${paddedCategory} ${formattedMessage}`;
|
|
359
359
|
if (wordWrapEnabled || message.includes("\n")) result = require_wordwrap.wrapText(result, wordWrapEnabled ? wordWrapWidth : Infinity, message);
|
|
360
360
|
return result + "\n";
|
package/dist/formatter.d.cts
CHANGED
|
@@ -136,7 +136,7 @@ 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
141
|
readonly levelStyle?: Style;
|
|
142
142
|
/**
|
|
@@ -241,19 +241,9 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
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
|
-
readonly categoryWidth?: number
|
|
246
|
+
readonly categoryWidth?: number;
|
|
257
247
|
/**
|
|
258
248
|
* Strategy for truncating long category names.
|
|
259
249
|
*
|
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,E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d;;;;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
|
@@ -136,7 +136,7 @@ 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
141
|
readonly levelStyle?: Style;
|
|
142
142
|
/**
|
|
@@ -241,19 +241,9 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
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
|
-
readonly categoryWidth?: number
|
|
246
|
+
readonly categoryWidth?: number;
|
|
257
247
|
/**
|
|
258
248
|
* Strategy for truncating long category names.
|
|
259
249
|
*
|
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;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;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","names":[],"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;;;;;;;;;0BAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiJV,kBAAA,WACL,yBACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4VU,iBAAiB"}
|
package/dist/formatter.js
CHANGED
|
@@ -302,7 +302,7 @@ function getPrettyFormatter(options = {}) {
|
|
|
302
302
|
return (record) => {
|
|
303
303
|
const icon = iconMap[record.level] || "";
|
|
304
304
|
const level = formatLevel(record.level);
|
|
305
|
-
const categoryStr = truncateCategory(record.category,
|
|
305
|
+
const categoryStr = truncateCategory(record.category, categoryWidth, categorySeparator, categoryTruncate);
|
|
306
306
|
let message = "";
|
|
307
307
|
const messageColorCode = useColors ? colorToAnsi(messageColor) : "";
|
|
308
308
|
const messageStyleCode = useColors ? styleToAnsi(messageStyle) : "";
|
|
@@ -353,7 +353,7 @@ function getPrettyFormatter(options = {}) {
|
|
|
353
353
|
const levelColorLength = useColors ? colorToAnsi(resolvedLevelColors[record.level]).length + styleToAnsi(levelStyle).length + RESET.length : 0;
|
|
354
354
|
const categoryColorLength = useColors ? colorToAnsi(finalCategoryColor).length + styleToAnsi(categoryStyle).length + RESET.length : 0;
|
|
355
355
|
const paddedLevel = formattedLevel.padEnd(levelWidth + levelColorLength);
|
|
356
|
-
const paddedCategory = formattedCategory.padEnd(
|
|
356
|
+
const paddedCategory = formattedCategory.padEnd(categoryWidth + categoryColorLength);
|
|
357
357
|
let result = `${formattedTimestamp}${formattedIcon} ${paddedLevel} ${paddedCategory} ${formattedMessage}`;
|
|
358
358
|
if (wordWrapEnabled || message.includes("\n")) result = wrapText(result, wordWrapEnabled ? wordWrapWidth : Infinity, message);
|
|
359
359
|
return result + "\n";
|
package/dist/formatter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","names":["color: Color","style: Style","categoryColorMap: CategoryColorMap","patterns: CategoryPattern[]","category: readonly string[]","prefix: readonly string[]","defaultIcons: Record<LogLevel, string>","iconMap: Record<LogLevel, string>","inspect: (value: unknown, options?: { colors?: boolean }) => string","options: PrettyFormatterOptions","baseIconMap: Record<LogLevel, string>","resolvedLevelColors: Record<LogLevel, Color>","levelMappings: Record<string, Record<LogLevel, string>>","level: LogLevel","timestampFormatters: Record<string, (ts: number) => string>","timestampFn: ((ts: number) => string | null) | null","wordWrapWidth: number","allLevels: LogLevel[]","record: LogRecord","prettyFormatter: TextFormatter"],"sources":["../formatter.ts"],"sourcesContent":["import type {\n LogLevel,\n LogRecord,\n TextFormatter,\n TextFormatterOptions,\n} from \"@logtape/logtape\";\nimport { inspect as nodeInspect } from \"node:util\";\nimport { getOptimalWordWrapWidth } from \"./terminal.ts\";\nimport { truncateCategory, type TruncationStrategy } from \"./truncate.ts\";\nimport { getDisplayWidth } from \"./wcwidth.ts\";\nimport { wrapText } from \"./wordwrap.ts\";\n\n/**\n * ANSI escape codes for styling\n */\nconst RESET = \"\\x1b[0m\";\nconst DIM = \"\\x1b[2m\";\n\n// Default true color values (referenced in JSDoc)\nconst defaultColors = {\n trace: \"rgb(167,139,250)\", // Light purple\n debug: \"rgb(96,165,250)\", // Light blue\n info: \"rgb(52,211,153)\", // Emerald\n warning: \"rgb(251,191,36)\", // Amber\n error: \"rgb(248,113,113)\", // Light red\n fatal: \"rgb(220,38,38)\", // Dark red\n category: \"rgb(100,116,139)\", // Slate\n message: \"rgb(148,163,184)\", // Light slate\n timestamp: \"rgb(100,116,139)\", // Slate\n} as const;\n\n/**\n * ANSI style codes\n */\nconst styles = {\n reset: RESET,\n bold: \"\\x1b[1m\",\n dim: DIM,\n italic: \"\\x1b[3m\",\n underline: \"\\x1b[4m\",\n strikethrough: \"\\x1b[9m\",\n} as const;\n\n/**\n * Standard ANSI colors (16-color)\n */\nconst ansiColors = {\n black: \"\\x1b[30m\",\n red: \"\\x1b[31m\",\n green: \"\\x1b[32m\",\n yellow: \"\\x1b[33m\",\n blue: \"\\x1b[34m\",\n magenta: \"\\x1b[35m\",\n cyan: \"\\x1b[36m\",\n white: \"\\x1b[37m\",\n} as const;\n\n/**\n * Color type definition\n */\nexport type Color =\n | keyof typeof ansiColors\n | `rgb(${number},${number},${number})`\n | `#${string}`\n | null;\n\n/**\n * Category color mapping for prefix-based coloring.\n *\n * Maps category prefixes (as arrays) to colors. The formatter will match\n * categories against these prefixes and use the corresponding color.\n * Longer/more specific prefixes take precedence over shorter ones.\n *\n * @example\n * ```typescript\n * new Map([\n * [[\"app\", \"auth\"], \"#ff6b6b\"], // app.auth.* -> red\n * [[\"app\", \"db\"], \"#4ecdc4\"], // app.db.* -> teal\n * [[\"app\"], \"#45b7d1\"], // app.* (fallback) -> blue\n * [[\"lib\"], \"#96ceb4\"], // lib.* -> green\n * ])\n * ```\n */\nexport type CategoryColorMap = Map<readonly string[], Color>;\n\n/**\n * Internal representation of category prefix patterns\n */\ntype CategoryPattern = {\n prefix: readonly string[];\n color: Color;\n};\n\n/**\n * Style type definition - supports single styles, arrays of styles, or null\n */\nexport type Style = keyof typeof styles | (keyof typeof styles)[] | null;\n\n// Pre-compiled regex patterns for color parsing\nconst RGB_PATTERN = /^rgb\\((\\d+),(\\d+),(\\d+)\\)$/;\nconst HEX_PATTERN = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;\n\n/**\n * Helper function to convert color to ANSI escape code\n */\nfunction colorToAnsi(color: Color): string {\n if (color === null) return \"\";\n if (color in ansiColors) {\n return ansiColors[color as keyof typeof ansiColors];\n }\n\n // Handle rgb() format\n const rgbMatch = color.match(RGB_PATTERN);\n if (rgbMatch) {\n const [, r, g, b] = rgbMatch;\n return `\\x1b[38;2;${r};${g};${b}m`;\n }\n\n // Handle hex format (#rrggbb or #rgb)\n const hexMatch = color.match(HEX_PATTERN);\n if (hexMatch) {\n let hex = hexMatch[1];\n // Convert 3-digit hex to 6-digit\n if (hex.length === 3) {\n hex = hex.split(\"\").map((c) => c + c).join(\"\");\n }\n const r = parseInt(hex.substr(0, 2), 16);\n const g = parseInt(hex.substr(2, 2), 16);\n const b = parseInt(hex.substr(4, 2), 16);\n return `\\x1b[38;2;${r};${g};${b}m`;\n }\n\n return \"\";\n}\n\n/**\n * Helper function to convert style to ANSI escape code\n */\nfunction styleToAnsi(style: Style): string {\n if (style === null) return \"\";\n if (Array.isArray(style)) {\n return style.map((s) => styles[s] || \"\").join(\"\");\n }\n return styles[style] || \"\";\n}\n\n/**\n * Converts a category color map to internal patterns and sorts them by specificity.\n * More specific (longer) prefixes come first for proper matching precedence.\n */\nfunction prepareCategoryPatterns(\n categoryColorMap: CategoryColorMap,\n): CategoryPattern[] {\n const patterns: CategoryPattern[] = [];\n\n for (const [prefix, color] of categoryColorMap) {\n patterns.push({ prefix, color });\n }\n\n // Sort by prefix length (descending) for most-specific-first matching\n return patterns.sort((a, b) => b.prefix.length - a.prefix.length);\n}\n\n/**\n * Matches a category against category color patterns.\n * Returns the color of the first matching pattern, or null if no match.\n */\nfunction matchCategoryColor(\n category: readonly string[],\n patterns: CategoryPattern[],\n): Color {\n for (const pattern of patterns) {\n if (categoryMatches(category, pattern.prefix)) {\n return pattern.color;\n }\n }\n return null;\n}\n\n/**\n * Checks if a category matches a prefix pattern.\n * A category matches if it starts with all segments of the prefix.\n */\nfunction categoryMatches(\n category: readonly string[],\n prefix: readonly string[],\n): boolean {\n if (prefix.length > category.length) {\n return false;\n }\n\n for (let i = 0; i < prefix.length; i++) {\n if (category[i] !== prefix[i]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Default icons for each log level\n */\nconst defaultIcons: Record<LogLevel, string> = {\n trace: \"🔍\",\n debug: \"🐛\",\n info: \"✨\",\n warning: \"⚡\",\n error: \"❌\",\n fatal: \"💀\",\n};\n\n/**\n * Normalize icon spacing to ensure consistent column alignment.\n *\n * All icons will be padded with spaces to match the width of the widest icon,\n * ensuring consistent prefix alignment across all log levels.\n *\n * @param iconMap The icon mapping to normalize\n * @returns A new icon map with consistent spacing\n */\nfunction normalizeIconSpacing(\n iconMap: Record<LogLevel, string>,\n): Record<LogLevel, string> {\n const entries = Object.entries(iconMap) as Array<[LogLevel, string]>;\n const maxWidth = Math.max(\n ...entries.map(([, icon]) => getDisplayWidth(icon)),\n );\n\n return Object.fromEntries(\n entries.map(([level, icon]) => [\n level,\n icon + \" \".repeat(maxWidth - getDisplayWidth(icon)),\n ]),\n ) as Record<LogLevel, string>;\n}\n\n/**\n * Platform-specific inspect function. Uses Node.js `util.inspect()` which\n * is available in both Deno and Node.js environments. For browser environments,\n * it falls back to {@link JSON.stringify}.\n *\n * @param value The value to inspect.\n * @param options The options for inspecting the value.\n * @returns The string representation of the value.\n */\nconst inspect: (value: unknown, options?: { colors?: boolean }) => string =\n // @ts-ignore: Browser detection\n typeof document !== \"undefined\" ||\n // @ts-ignore: React Native detection\n typeof navigator !== \"undefined\" && navigator.product === \"ReactNative\"\n ? (v) => JSON.stringify(v)\n : (v, opts) =>\n nodeInspect(v, {\n maxArrayLength: 10,\n maxStringLength: 80,\n compact: true,\n ...opts,\n });\n\n/**\n * Configuration options for the pretty formatter.\n *\n * This interface extends the base text formatter options while providing\n * extensive customization options for visual styling, layout control, and\n * development-focused features. It offers granular control over colors,\n * styles, and formatting similar to the ANSI color formatter.\n *\n * @since 1.0.0\n */\nexport interface PrettyFormatterOptions\n extends Omit<TextFormatterOptions, \"category\" | \"value\" | \"format\"> {\n /**\n * Color for timestamp display when timestamps are enabled.\n *\n * Supports true color RGB values, hex colors, or ANSI color names.\n * Set to `null` to disable timestamp coloring.\n *\n * @example\n * ```typescript\n * timestampColor: \"#888888\" // Hex color\n * timestampColor: \"rgb(128,128,128)\" // RGB color\n * timestampColor: \"cyan\" // ANSI color name\n * timestampColor: null // No color\n * ```\n *\n * @default `\"rgb(100,116,139)\"` (slate gray)\n */\n readonly timestampColor?: Color;\n\n /**\n * Visual style applied to timestamp text.\n *\n * Controls text appearance like boldness, dimming, etc.\n * Supports single styles, multiple styles combined, or no styling.\n * Combines with `timestampColor` for full styling control.\n *\n * @example\n * ```typescript\n * timestampStyle: \"dim\" // Single style: dimmed text\n * timestampStyle: \"bold\" // Single style: bold text\n * timestampStyle: [\"bold\", \"underline\"] // Multiple styles: bold + underlined\n * timestampStyle: [\"dim\", \"italic\"] // Multiple styles: dimmed + italic\n * timestampStyle: null // No styling\n * ```\n *\n * @default `\"dim\"`\n */\n readonly timestampStyle?: Style;\n\n /**\n * Custom colors for each log level.\n *\n * Allows fine-grained control over level appearance. Each level can have\n * its own color scheme. Unspecified levels use built-in defaults.\n * Set individual levels to `null` to disable coloring for that level.\n *\n * @example\n * ```typescript\n * levelColors: {\n * info: \"#00ff00\", // Bright green for info\n * error: \"#ff0000\", // Bright red for errors\n * warning: \"orange\", // ANSI orange for warnings\n * debug: null, // No color for debug\n * }\n * ```\n *\n * @default Built-in color scheme (purple trace, blue debug, green info, amber warning, red error, dark red fatal)\n */\n readonly levelColors?: Partial<Record<LogLevel, Color>>;\n\n /**\n * Visual style applied to log level text.\n *\n * Controls the appearance of the level indicator (e.g., \"info\", \"error\").\n * Supports single styles, multiple styles combined, or no styling.\n * Applied in addition to level-specific colors.\n *\n * @example\n * ```typescript\n * levelStyle: \"bold\" // Single style: bold level text\n * levelStyle: \"underline\" // Single style: underlined level text\n * levelStyle: [\"bold\", \"underline\"] // Multiple styles: bold + underlined\n * levelStyle: [\"dim\", \"italic\"] // Multiple styles: dimmed + italic\n * levelStyle: null // No additional styling\n * ```\n *\n * @default `null` (no additional styling)\n */\n readonly levelStyle?: Style;\n\n /**\n * Icon configuration for each log level.\n *\n * Controls the emoji/symbol displayed before each log entry.\n * Provides visual quick-identification of log severity.\n *\n * - `true`: Use built-in emoji set (🔍 trace, 🐛 debug, ✨ info, ⚠️ warning, ❌ error, 💀 fatal)\n * - `false`: Disable all icons for clean text-only output\n * - Object: Custom icon mapping, falls back to defaults for unspecified levels\n *\n * @example\n * ```typescript\n * icons: true // Use default emoji set\n * icons: false // No icons\n * icons: {\n * info: \"ℹ️\", // Custom info icon\n * error: \"🔥\", // Custom error icon\n * warning: \"⚡\", // Custom warning icon\n * }\n * ```\n *\n * @default `true` (use default emoji icons)\n */\n readonly icons?: boolean | Partial<Record<LogLevel, string>>;\n\n /**\n * Character(s) used to separate category hierarchy levels.\n *\n * Categories are hierarchical (e.g., [\"app\", \"auth\", \"jwt\"]) and this\n * separator joins them for display (e.g., \"app.auth.jwt\").\n *\n * @example\n * ```typescript\n * categorySeparator: \"·\" // app·auth·jwt\n * categorySeparator: \".\" // app.auth.jwt\n * categorySeparator: \":\" // app:auth:jwt\n * categorySeparator: \" > \" // app > auth > jwt\n * categorySeparator: \"::\" // app::auth::jwt\n * ```\n *\n * @default `\"·\"` (interpunct)\n */\n readonly categorySeparator?: string;\n\n /**\n * Default color for category display.\n *\n * Used as fallback when no specific color is found in `categoryColorMap`.\n * Controls the visual appearance of the category hierarchy display.\n *\n * @example\n * ```typescript\n * categoryColor: \"#666666\" // Gray categories\n * categoryColor: \"blue\" // Blue categories\n * categoryColor: \"rgb(100,150,200)\" // Light blue categories\n * categoryColor: null // No coloring\n * ```\n *\n * @default `\"rgb(100,116,139)\"` (slate gray)\n */\n readonly categoryColor?: Color;\n\n /**\n * Category-specific color mapping based on prefixes.\n *\n * Maps category prefixes (as arrays) to colors for visual grouping.\n * More specific (longer) prefixes take precedence over shorter ones.\n * If no prefix matches, falls back to the default `categoryColor`.\n *\n * @example\n * ```typescript\n * new Map([\n * [[\"app\", \"auth\"], \"#ff6b6b\"], // app.auth.* -> red\n * [[\"app\", \"db\"], \"#4ecdc4\"], // app.db.* -> teal\n * [[\"app\"], \"#45b7d1\"], // app.* (fallback) -> blue\n * [[\"lib\"], \"#96ceb4\"], // lib.* -> green\n * ])\n * ```\n */\n readonly categoryColorMap?: CategoryColorMap;\n\n /**\n * Visual style applied to category text.\n *\n * Controls the appearance of the category hierarchy display.\n * Supports single styles, multiple styles combined, or no styling.\n * Applied in addition to category colors from `categoryColor` or `categoryColorMap`.\n *\n * @example\n * ```typescript\n * categoryStyle: \"dim\" // Single style: dimmed category text\n * categoryStyle: \"italic\" // Single style: italic category text\n * categoryStyle: [\"dim\", \"italic\"] // Multiple styles: dimmed + italic\n * categoryStyle: [\"bold\", \"underline\"] // Multiple styles: bold + underlined\n * categoryStyle: null // No additional styling\n * ```\n *\n * @default `[\"dim\", \"italic\"]` (dimmed for subtle appearance)\n */\n readonly categoryStyle?: Style;\n\n /**\n * Maximum display width for category names.\n *\n * Controls layout consistency by limiting category width.\n * Long categories are truncated according to `categoryTruncate` strategy.\n *\n * - Number: Fixed character width limit\n * - `\"auto\"`: No width limit, categories display at full length\n *\n * @example\n * ```typescript\n * categoryWidth: 20 // Limit to 20 characters\n * categoryWidth: 30 // Limit to 30 characters\n * categoryWidth: \"auto\" // No limit\n * ```\n *\n * @default `20` (20 character limit)\n */\n readonly categoryWidth?: number | \"auto\";\n\n /**\n * Strategy for truncating long category names.\n *\n * When categories exceed `categoryWidth`, this controls how truncation works.\n * Smart truncation preserves important context while maintaining layout.\n *\n * - `\"middle\"`: Keep first and last parts (e.g., \"app.server…auth.jwt\")\n * - `\"end\"`: Truncate at the end (e.g., \"app.server.middleware…\")\n * - `false`: No truncation (ignores `categoryWidth`)\n *\n * @example\n * ```typescript\n * categoryTruncate: \"middle\" // app.server…jwt (preserves context)\n * categoryTruncate: \"end\" // app.server.midd… (linear truncation)\n * categoryTruncate: false // app.server.middleware.auth.jwt (full)\n * ```\n *\n * @default `\"middle\"` (smart context-preserving truncation)\n */\n readonly categoryTruncate?: TruncationStrategy;\n\n /**\n * Color for log message text content.\n *\n * Controls the visual appearance of the actual log message content.\n * Does not affect structured values, which use syntax highlighting.\n *\n * @example\n * ```typescript\n * messageColor: \"#ffffff\" // White message text\n * messageColor: \"green\" // Green message text\n * messageColor: \"rgb(200,200,200)\" // Light gray message text\n * messageColor: null // No coloring\n * ```\n *\n * @default `\"rgb(148,163,184)\"` (light slate gray)\n */\n readonly messageColor?: Color;\n\n /**\n * Visual style applied to log message text.\n *\n * Controls the appearance of the log message content.\n * Supports single styles, multiple styles combined, or no styling.\n * Applied in addition to `messageColor`.\n *\n * @example\n * ```typescript\n * messageStyle: \"dim\" // Single style: dimmed message text\n * messageStyle: \"italic\" // Single style: italic message text\n * messageStyle: [\"dim\", \"italic\"] // Multiple styles: dimmed + italic\n * messageStyle: [\"bold\", \"underline\"] // Multiple styles: bold + underlined\n * messageStyle: null // No additional styling\n * ```\n *\n * @default `\"dim\"` (dimmed for subtle readability)\n */\n readonly messageStyle?: Style;\n\n /**\n * Global color control for the entire formatter.\n *\n * Master switch to enable/disable all color output.\n * When disabled, produces clean monochrome output suitable for\n * non-color terminals or when colors are not desired.\n *\n * @example\n * ```typescript\n * colors: true // Full color output (default)\n * colors: false // Monochrome output only\n * ```\n *\n * @default `true` (colors enabled)\n */\n readonly colors?: boolean;\n\n /**\n * Column alignment for consistent visual layout.\n *\n * When enabled, ensures all log components (icons, levels, categories)\n * align consistently across multiple log entries, creating a clean\n * tabular appearance.\n *\n * @example\n * ```typescript\n * align: true // Aligned columns (default)\n * align: false // Compact, non-aligned output\n * ```\n *\n * @default `true` (alignment enabled)\n */\n readonly align?: boolean;\n\n /**\n * Configuration for structured value inspection and rendering.\n *\n * Controls how objects, arrays, and other complex values are displayed\n * within log messages. Uses Node.js `util.inspect()` style options.\n *\n * @example\n * ```typescript\n * inspectOptions: {\n * depth: 3, // Show 3 levels of nesting\n * colors: false, // Disable value syntax highlighting\n * compact: true, // Use compact object display\n * }\n * ```\n *\n * @default `{}` (use built-in defaults: depth=unlimited, colors=auto, compact=true)\n */\n readonly inspectOptions?: {\n /**\n * Maximum depth to traverse when inspecting nested objects.\n * @default Infinity (no depth limit)\n */\n readonly depth?: number;\n\n /**\n * Whether to use syntax highlighting colors for inspected values.\n * @default Inherited from global `colors` setting\n */\n readonly colors?: boolean;\n\n /**\n * Whether to use compact formatting for objects and arrays.\n * @default `true` (compact formatting)\n */\n readonly compact?: boolean;\n };\n\n /**\n * Enable word wrapping for long messages.\n *\n * When enabled, long messages will be wrapped at the specified width,\n * with continuation lines aligned to the message column position.\n *\n * - `true`: Auto-detect terminal width when attached to a terminal,\n * fallback to 80 columns when not in a terminal or detection fails\n * - `number`: Use the specified width in columns\n * - `false`: Disable word wrapping\n *\n * @example\n * ```typescript\n * // Auto-detect terminal width (recommended)\n * wordWrap: true\n *\n * // Custom wrap width\n * wordWrap: 120\n *\n * // Disable word wrapping (default)\n * wordWrap: false\n * ```\n *\n * @default `true` (auto-detect terminal width)\n * @since 1.0.0\n */\n readonly wordWrap?: boolean | number;\n}\n\n/**\n * Creates a beautiful console formatter optimized for local development.\n *\n * This formatter provides a Signale-inspired visual design with colorful icons,\n * smart category truncation, dimmed styling, and perfect column alignment.\n * It's specifically designed for development environments that support true colors\n * and Unicode characters.\n *\n * The formatter features:\n * - Emoji icons for each log level (🔍 trace, 🐛 debug, ✨ info, etc.)\n * - True color support with rich color schemes\n * - Intelligent category truncation for long hierarchical categories\n * - Optional timestamp display with multiple formats\n * - Configurable alignment and styling options\n * - Enhanced value rendering with syntax highlighting\n *\n * @param options Configuration options for customizing the formatter behavior.\n * @returns A text formatter function that can be used with LogTape sinks.\n *\n * @example\n * ```typescript\n * import { configure } from \"@logtape/logtape\";\n * import { getConsoleSink } from \"@logtape/logtape/sink\";\n * import { getPrettyFormatter } from \"@logtape/pretty\";\n *\n * await configure({\n * sinks: {\n * console: getConsoleSink({\n * formatter: getPrettyFormatter({\n * timestamp: \"time\",\n * categoryWidth: 25,\n * icons: {\n * info: \"📘\",\n * error: \"🔥\"\n * }\n * })\n * })\n * }\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport function getPrettyFormatter(\n options: PrettyFormatterOptions = {},\n): TextFormatter {\n // Extract options with defaults\n const {\n timestamp = \"none\",\n timestampColor = \"rgb(100,116,139)\",\n timestampStyle = \"dim\",\n level: levelFormat = \"full\",\n levelColors = {},\n levelStyle = \"underline\",\n icons = true,\n categorySeparator = \"·\",\n categoryColor = \"rgb(100,116,139)\",\n categoryColorMap = new Map(),\n categoryStyle = [\"dim\", \"italic\"],\n categoryWidth = 20,\n categoryTruncate = \"middle\",\n messageColor = \"rgb(148,163,184)\",\n messageStyle = \"dim\",\n colors: useColors = true,\n align = true,\n inspectOptions = {},\n wordWrap = true,\n } = options;\n\n // Resolve icons\n const baseIconMap: Record<LogLevel, string> = icons === false\n ? { trace: \"\", debug: \"\", info: \"\", warning: \"\", error: \"\", fatal: \"\" }\n : icons === true\n ? defaultIcons\n : { ...defaultIcons, ...(icons as Partial<Record<LogLevel, string>>) };\n\n // Normalize icon spacing for consistent alignment\n const iconMap = normalizeIconSpacing(baseIconMap);\n\n // Resolve level colors with defaults\n const resolvedLevelColors: Record<LogLevel, Color> = {\n trace: defaultColors.trace,\n debug: defaultColors.debug,\n info: defaultColors.info,\n warning: defaultColors.warning,\n error: defaultColors.error,\n fatal: defaultColors.fatal,\n ...levelColors,\n };\n\n // Level formatter function with optimized mappings\n const levelMappings: Record<string, Record<LogLevel, string>> = {\n \"ABBR\": {\n trace: \"TRC\",\n debug: \"DBG\",\n info: \"INF\",\n warning: \"WRN\",\n error: \"ERR\",\n fatal: \"FTL\",\n },\n \"L\": {\n trace: \"T\",\n debug: \"D\",\n info: \"I\",\n warning: \"W\",\n error: \"E\",\n fatal: \"F\",\n },\n \"abbr\": {\n trace: \"trc\",\n debug: \"dbg\",\n info: \"inf\",\n warning: \"wrn\",\n error: \"err\",\n fatal: \"ftl\",\n },\n \"l\": {\n trace: \"t\",\n debug: \"d\",\n info: \"i\",\n warning: \"w\",\n error: \"e\",\n fatal: \"f\",\n },\n };\n\n const formatLevel = (level: LogLevel): string => {\n if (typeof levelFormat === \"function\") {\n return levelFormat(level);\n }\n\n if (levelFormat === \"FULL\") return level.toUpperCase();\n if (levelFormat === \"full\") return level;\n\n return levelMappings[levelFormat]?.[level] ?? level;\n };\n\n // Timestamp formatters lookup table\n const timestampFormatters: Record<string, (ts: number) => string> = {\n \"date-time-timezone\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(\"T\", \" \").replace(\"Z\", \" +00:00\");\n },\n \"date-time-tz\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(\"T\", \" \").replace(\"Z\", \" +00\");\n },\n \"date-time\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(\"T\", \" \").replace(\"Z\", \"\");\n },\n \"time-timezone\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(/.*T/, \"\").replace(\"Z\", \" +00:00\");\n },\n \"time-tz\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(/.*T/, \"\").replace(\"Z\", \" +00\");\n },\n \"time\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(/.*T/, \"\").replace(\"Z\", \"\");\n },\n \"date\": (ts) => new Date(ts).toISOString().replace(/T.*/, \"\"),\n \"rfc3339\": (ts) => new Date(ts).toISOString(),\n };\n\n // Resolve timestamp formatter\n let timestampFn: ((ts: number) => string | null) | null = null;\n if (timestamp === \"none\" || timestamp === \"disabled\") {\n timestampFn = null;\n } else if (typeof timestamp === \"function\") {\n timestampFn = timestamp;\n } else {\n timestampFn = timestampFormatters[timestamp as string] ?? null;\n }\n\n // Configure word wrap settings\n const wordWrapEnabled = wordWrap !== false;\n let wordWrapWidth: number;\n\n if (typeof wordWrap === \"number\") {\n wordWrapWidth = wordWrap;\n } else if (wordWrap === true) {\n // Auto-detect terminal width\n wordWrapWidth = getOptimalWordWrapWidth(80);\n } else {\n wordWrapWidth = 80; // Default fallback\n }\n\n // Prepare category color patterns for matching\n const categoryPatterns = prepareCategoryPatterns(categoryColorMap);\n\n // Calculate level width based on format\n const allLevels: LogLevel[] = [\n \"trace\",\n \"debug\",\n \"info\",\n \"warning\",\n \"error\",\n \"fatal\",\n ];\n const levelWidth = Math.max(...allLevels.map((l) => formatLevel(l).length));\n\n return (record: LogRecord): string => {\n // Calculate the prefix parts first to determine message column position\n const icon = iconMap[record.level] || \"\";\n const level = formatLevel(record.level);\n const categoryStr = truncateCategory(\n record.category,\n typeof categoryWidth === \"number\" ? categoryWidth : 30,\n categorySeparator,\n categoryTruncate,\n );\n\n // Format message with values - handle color reset/reapply for interpolated values\n let message = \"\";\n const messageColorCode = useColors ? colorToAnsi(messageColor) : \"\";\n const messageStyleCode = useColors ? styleToAnsi(messageStyle) : \"\";\n const messagePrefix = useColors\n ? `${messageStyleCode}${messageColorCode}`\n : \"\";\n\n for (let i = 0; i < record.message.length; i++) {\n if (i % 2 === 0) {\n message += record.message[i];\n } else {\n const value = record.message[i];\n const inspected = inspect(value, {\n colors: useColors,\n ...inspectOptions,\n });\n\n // Handle multiline interpolated values properly\n if (inspected.includes(\"\\n\")) {\n const lines = inspected.split(\"\\n\");\n\n const formattedLines = lines.map((line, index) => {\n if (index === 0) {\n // First line: reset formatting, add the line, then reapply\n if (useColors && (messageColorCode || messageStyleCode)) {\n return `${RESET}${line}${messagePrefix}`;\n } else {\n return line;\n }\n } else {\n // Continuation lines: just apply formatting, let wrapText handle indentation\n if (useColors && (messageColorCode || messageStyleCode)) {\n return `${line}${messagePrefix}`;\n } else {\n return line;\n }\n }\n });\n message += formattedLines.join(\"\\n\");\n } else {\n // Single line - handle normally\n if (useColors && (messageColorCode || messageStyleCode)) {\n message += `${RESET}${inspected}${messagePrefix}`;\n } else {\n message += inspected;\n }\n }\n }\n }\n\n // Parts are already calculated above\n\n // Determine category color (with prefix matching)\n const finalCategoryColor = useColors\n ? (matchCategoryColor(record.category, categoryPatterns) || categoryColor)\n : null;\n\n // Apply colors and styling\n const formattedIcon = icon;\n let formattedLevel = level;\n let formattedCategory = categoryStr;\n let formattedMessage = message;\n let formattedTimestamp = \"\";\n\n if (useColors) {\n // Apply level color and style\n const levelColorCode = colorToAnsi(resolvedLevelColors[record.level]);\n const levelStyleCode = styleToAnsi(levelStyle);\n formattedLevel = `${levelStyleCode}${levelColorCode}${level}${RESET}`;\n\n // Apply category color and style (with prefix matching)\n const categoryColorCode = colorToAnsi(finalCategoryColor);\n const categoryStyleCode = styleToAnsi(categoryStyle);\n formattedCategory =\n `${categoryStyleCode}${categoryColorCode}${categoryStr}${RESET}`;\n\n // Apply message color and style (already handled in message building above)\n formattedMessage = `${messagePrefix}${message}${RESET}`;\n }\n\n // Format timestamp if needed\n if (timestampFn) {\n const ts = timestampFn(record.timestamp);\n if (ts !== null) {\n if (useColors) {\n const timestampColorCode = colorToAnsi(timestampColor);\n const timestampStyleCode = styleToAnsi(timestampStyle);\n formattedTimestamp =\n `${timestampStyleCode}${timestampColorCode}${ts}${RESET} `;\n } else {\n formattedTimestamp = `${ts} `;\n }\n }\n }\n\n // Build the final output with alignment\n if (align) {\n // Calculate padding accounting for ANSI escape sequences\n const levelColorLength = useColors\n ? (colorToAnsi(resolvedLevelColors[record.level]).length +\n styleToAnsi(levelStyle).length + RESET.length)\n : 0;\n const categoryColorLength = useColors\n ? (colorToAnsi(finalCategoryColor).length +\n styleToAnsi(categoryStyle).length + RESET.length)\n : 0;\n\n const paddedLevel = formattedLevel.padEnd(levelWidth + levelColorLength);\n const paddedCategory = formattedCategory.padEnd(\n (typeof categoryWidth === \"number\" ? categoryWidth : 30) +\n categoryColorLength,\n );\n\n let result =\n `${formattedTimestamp}${formattedIcon} ${paddedLevel} ${paddedCategory} ${formattedMessage}`;\n\n // Apply word wrapping if enabled, or if there are multiline interpolated values\n if (wordWrapEnabled || message.includes(\"\\n\")) {\n result = wrapText(\n result,\n wordWrapEnabled ? wordWrapWidth : Infinity,\n message,\n );\n }\n\n return result + \"\\n\";\n } else {\n let result =\n `${formattedTimestamp}${formattedIcon} ${formattedLevel} ${formattedCategory} ${formattedMessage}`;\n\n // Apply word wrapping if enabled, or if there are multiline interpolated values\n if (wordWrapEnabled || message.includes(\"\\n\")) {\n result = wrapText(\n result,\n wordWrapEnabled ? wordWrapWidth : Infinity,\n message,\n );\n }\n\n return result + \"\\n\";\n }\n };\n}\n\n/**\n * A pre-configured beautiful console formatter for local development.\n *\n * This is a ready-to-use instance of the pretty formatter with sensible defaults\n * for most development scenarios. It provides immediate visual enhancement to\n * your logs without requiring any configuration.\n *\n * Features enabled by default:\n * - Emoji icons for all log levels\n * - True color support with rich color schemes\n * - Dimmed text styling for better readability\n * - Smart category truncation (20 characters max)\n * - Perfect column alignment\n * - No timestamp display (cleaner for development)\n *\n * For custom configuration, use {@link getPrettyFormatter} instead.\n *\n * @example\n * ```typescript\n * import { configure } from \"@logtape/logtape\";\n * import { getConsoleSink } from \"@logtape/logtape/sink\";\n * import { prettyFormatter } from \"@logtape/pretty\";\n *\n * await configure({\n * sinks: {\n * console: getConsoleSink({\n * formatter: prettyFormatter\n * })\n * }\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport const prettyFormatter: TextFormatter = getPrettyFormatter();\n"],"mappings":";;;;;;;;;;AAeA,MAAM,QAAQ;AACd,MAAM,MAAM;AAGZ,MAAM,gBAAgB;CACpB,OAAO;CACP,OAAO;CACP,MAAM;CACN,SAAS;CACT,OAAO;CACP,OAAO;CACP,UAAU;CACV,SAAS;CACT,WAAW;AACZ;;;;AAKD,MAAM,SAAS;CACb,OAAO;CACP,MAAM;CACN,KAAK;CACL,QAAQ;CACR,WAAW;CACX,eAAe;AAChB;;;;AAKD,MAAM,aAAa;CACjB,OAAO;CACP,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;AACR;AA4CD,MAAM,cAAc;AACpB,MAAM,cAAc;;;;AAKpB,SAAS,YAAYA,OAAsB;AACzC,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,SAAS,WACX,QAAO,WAAW;CAIpB,MAAM,WAAW,MAAM,MAAM,YAAY;AACzC,KAAI,UAAU;EACZ,MAAM,GAAG,GAAG,GAAG,EAAE,GAAG;AACpB,UAAQ,YAAY,EAAE,GAAG,EAAE,G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AAW;IACb,MAAM,qBAAqB,YAAY,eAAe;IACtD,MAAM,qBAAqB,YAAY,eAAe;AACtD,0BACG,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,GAAG,EAAE,MAAM;GAC3D,MACC,uBAAsB,EAAE,GAAG;EAGhC;AAGD,MAAI,OAAO;GAET,MAAM,mBAAmB,YACpB,YAAY,oBAAoB,OAAO,OAAO,CAAC,SAChD,YAAY,WAAW,CAAC,SAAS,MAAM,SACvC;GACJ,MAAM,sBAAsB,YACvB,YAAY,mBAAmB,CAAC,SACjC,YAAY,cAAc,CAAC,SAAS,MAAM,SAC1C;GAEJ,MAAM,cAAc,eAAe,OAAO,aAAa,iBAAiB;GACxE,MAAM,iBAAiB,kBAAkB,eAC/B,kBAAkB,WAAW,gBAAgB,MACnD,oBACH;GAED,IAAI,UACD,EAAE,mBAAmB,EAAE,cAAc,GAAG,YAAY,GAAG,eAAe,GAAG,iBAAiB;AAG7F,OAAI,mBAAmB,QAAQ,SAAS,KAAK,CAC3C,UAAS,SACP,QACA,kBAAkB,gBAAgB,UAClC,QACD;AAGH,UAAO,SAAS;EACjB,OAAM;GACL,IAAI,UACD,EAAE,mBAAmB,EAAE,cAAc,GAAG,eAAe,GAAG,kBAAkB,GAAG,iBAAiB;AAGnG,OAAI,mBAAmB,QAAQ,SAAS,KAAK,CAC3C,UAAS,SACP,QACA,kBAAkB,gBAAgB,UAClC,QACD;AAGH,UAAO,SAAS;EACjB;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCD,MAAaC,kBAAiC,oBAAoB"}
|
|
1
|
+
{"version":3,"file":"formatter.js","names":["color: Color","style: Style","categoryColorMap: CategoryColorMap","patterns: CategoryPattern[]","category: readonly string[]","prefix: readonly string[]","defaultIcons: Record<LogLevel, string>","iconMap: Record<LogLevel, string>","inspect: (value: unknown, options?: { colors?: boolean }) => string","options: PrettyFormatterOptions","baseIconMap: Record<LogLevel, string>","resolvedLevelColors: Record<LogLevel, Color>","levelMappings: Record<string, Record<LogLevel, string>>","level: LogLevel","timestampFormatters: Record<string, (ts: number) => string>","timestampFn: ((ts: number) => string | null) | null","wordWrapWidth: number","allLevels: LogLevel[]","record: LogRecord","prettyFormatter: TextFormatter"],"sources":["../formatter.ts"],"sourcesContent":["import type {\n LogLevel,\n LogRecord,\n TextFormatter,\n TextFormatterOptions,\n} from \"@logtape/logtape\";\nimport { inspect as nodeInspect } from \"node:util\";\nimport { getOptimalWordWrapWidth } from \"./terminal.ts\";\nimport { truncateCategory, type TruncationStrategy } from \"./truncate.ts\";\nimport { getDisplayWidth } from \"./wcwidth.ts\";\nimport { wrapText } from \"./wordwrap.ts\";\n\n/**\n * ANSI escape codes for styling\n */\nconst RESET = \"\\x1b[0m\";\nconst DIM = \"\\x1b[2m\";\n\n// Default true color values (referenced in JSDoc)\nconst defaultColors = {\n trace: \"rgb(167,139,250)\", // Light purple\n debug: \"rgb(96,165,250)\", // Light blue\n info: \"rgb(52,211,153)\", // Emerald\n warning: \"rgb(251,191,36)\", // Amber\n error: \"rgb(248,113,113)\", // Light red\n fatal: \"rgb(220,38,38)\", // Dark red\n category: \"rgb(100,116,139)\", // Slate\n message: \"rgb(148,163,184)\", // Light slate\n timestamp: \"rgb(100,116,139)\", // Slate\n} as const;\n\n/**\n * ANSI style codes\n */\nconst styles = {\n reset: RESET,\n bold: \"\\x1b[1m\",\n dim: DIM,\n italic: \"\\x1b[3m\",\n underline: \"\\x1b[4m\",\n strikethrough: \"\\x1b[9m\",\n} as const;\n\n/**\n * Standard ANSI colors (16-color)\n */\nconst ansiColors = {\n black: \"\\x1b[30m\",\n red: \"\\x1b[31m\",\n green: \"\\x1b[32m\",\n yellow: \"\\x1b[33m\",\n blue: \"\\x1b[34m\",\n magenta: \"\\x1b[35m\",\n cyan: \"\\x1b[36m\",\n white: \"\\x1b[37m\",\n} as const;\n\n/**\n * Color type definition\n */\nexport type Color =\n | keyof typeof ansiColors\n | `rgb(${number},${number},${number})`\n | `#${string}`\n | null;\n\n/**\n * Category color mapping for prefix-based coloring.\n *\n * Maps category prefixes (as arrays) to colors. The formatter will match\n * categories against these prefixes and use the corresponding color.\n * Longer/more specific prefixes take precedence over shorter ones.\n *\n * @example\n * ```typescript\n * new Map([\n * [[\"app\", \"auth\"], \"#ff6b6b\"], // app.auth.* -> red\n * [[\"app\", \"db\"], \"#4ecdc4\"], // app.db.* -> teal\n * [[\"app\"], \"#45b7d1\"], // app.* (fallback) -> blue\n * [[\"lib\"], \"#96ceb4\"], // lib.* -> green\n * ])\n * ```\n */\nexport type CategoryColorMap = Map<readonly string[], Color>;\n\n/**\n * Internal representation of category prefix patterns\n */\ntype CategoryPattern = {\n prefix: readonly string[];\n color: Color;\n};\n\n/**\n * Style type definition - supports single styles, arrays of styles, or null\n */\nexport type Style = keyof typeof styles | (keyof typeof styles)[] | null;\n\n// Pre-compiled regex patterns for color parsing\nconst RGB_PATTERN = /^rgb\\((\\d+),(\\d+),(\\d+)\\)$/;\nconst HEX_PATTERN = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;\n\n/**\n * Helper function to convert color to ANSI escape code\n */\nfunction colorToAnsi(color: Color): string {\n if (color === null) return \"\";\n if (color in ansiColors) {\n return ansiColors[color as keyof typeof ansiColors];\n }\n\n // Handle rgb() format\n const rgbMatch = color.match(RGB_PATTERN);\n if (rgbMatch) {\n const [, r, g, b] = rgbMatch;\n return `\\x1b[38;2;${r};${g};${b}m`;\n }\n\n // Handle hex format (#rrggbb or #rgb)\n const hexMatch = color.match(HEX_PATTERN);\n if (hexMatch) {\n let hex = hexMatch[1];\n // Convert 3-digit hex to 6-digit\n if (hex.length === 3) {\n hex = hex.split(\"\").map((c) => c + c).join(\"\");\n }\n const r = parseInt(hex.substr(0, 2), 16);\n const g = parseInt(hex.substr(2, 2), 16);\n const b = parseInt(hex.substr(4, 2), 16);\n return `\\x1b[38;2;${r};${g};${b}m`;\n }\n\n return \"\";\n}\n\n/**\n * Helper function to convert style to ANSI escape code\n */\nfunction styleToAnsi(style: Style): string {\n if (style === null) return \"\";\n if (Array.isArray(style)) {\n return style.map((s) => styles[s] || \"\").join(\"\");\n }\n return styles[style] || \"\";\n}\n\n/**\n * Converts a category color map to internal patterns and sorts them by specificity.\n * More specific (longer) prefixes come first for proper matching precedence.\n */\nfunction prepareCategoryPatterns(\n categoryColorMap: CategoryColorMap,\n): CategoryPattern[] {\n const patterns: CategoryPattern[] = [];\n\n for (const [prefix, color] of categoryColorMap) {\n patterns.push({ prefix, color });\n }\n\n // Sort by prefix length (descending) for most-specific-first matching\n return patterns.sort((a, b) => b.prefix.length - a.prefix.length);\n}\n\n/**\n * Matches a category against category color patterns.\n * Returns the color of the first matching pattern, or null if no match.\n */\nfunction matchCategoryColor(\n category: readonly string[],\n patterns: CategoryPattern[],\n): Color {\n for (const pattern of patterns) {\n if (categoryMatches(category, pattern.prefix)) {\n return pattern.color;\n }\n }\n return null;\n}\n\n/**\n * Checks if a category matches a prefix pattern.\n * A category matches if it starts with all segments of the prefix.\n */\nfunction categoryMatches(\n category: readonly string[],\n prefix: readonly string[],\n): boolean {\n if (prefix.length > category.length) {\n return false;\n }\n\n for (let i = 0; i < prefix.length; i++) {\n if (category[i] !== prefix[i]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Default icons for each log level\n */\nconst defaultIcons: Record<LogLevel, string> = {\n trace: \"🔍\",\n debug: \"🐛\",\n info: \"✨\",\n warning: \"⚡\",\n error: \"❌\",\n fatal: \"💀\",\n};\n\n/**\n * Normalize icon spacing to ensure consistent column alignment.\n *\n * All icons will be padded with spaces to match the width of the widest icon,\n * ensuring consistent prefix alignment across all log levels.\n *\n * @param iconMap The icon mapping to normalize\n * @returns A new icon map with consistent spacing\n */\nfunction normalizeIconSpacing(\n iconMap: Record<LogLevel, string>,\n): Record<LogLevel, string> {\n const entries = Object.entries(iconMap) as Array<[LogLevel, string]>;\n const maxWidth = Math.max(\n ...entries.map(([, icon]) => getDisplayWidth(icon)),\n );\n\n return Object.fromEntries(\n entries.map(([level, icon]) => [\n level,\n icon + \" \".repeat(maxWidth - getDisplayWidth(icon)),\n ]),\n ) as Record<LogLevel, string>;\n}\n\n/**\n * Platform-specific inspect function. Uses Node.js `util.inspect()` which\n * is available in both Deno and Node.js environments. For browser environments,\n * it falls back to {@link JSON.stringify}.\n *\n * @param value The value to inspect.\n * @param options The options for inspecting the value.\n * @returns The string representation of the value.\n */\nconst inspect: (value: unknown, options?: { colors?: boolean }) => string =\n // @ts-ignore: Browser detection\n typeof document !== \"undefined\" ||\n // @ts-ignore: React Native detection\n typeof navigator !== \"undefined\" && navigator.product === \"ReactNative\"\n ? (v) => JSON.stringify(v)\n : (v, opts) =>\n nodeInspect(v, {\n maxArrayLength: 10,\n maxStringLength: 80,\n compact: true,\n ...opts,\n });\n\n/**\n * Configuration options for the pretty formatter.\n *\n * This interface extends the base text formatter options while providing\n * extensive customization options for visual styling, layout control, and\n * development-focused features. It offers granular control over colors,\n * styles, and formatting similar to the ANSI color formatter.\n *\n * @since 1.0.0\n */\nexport interface PrettyFormatterOptions\n extends Omit<TextFormatterOptions, \"category\" | \"value\" | \"format\"> {\n /**\n * Color for timestamp display when timestamps are enabled.\n *\n * Supports true color RGB values, hex colors, or ANSI color names.\n * Set to `null` to disable timestamp coloring.\n *\n * @example\n * ```typescript\n * timestampColor: \"#888888\" // Hex color\n * timestampColor: \"rgb(128,128,128)\" // RGB color\n * timestampColor: \"cyan\" // ANSI color name\n * timestampColor: null // No color\n * ```\n *\n * @default `\"rgb(100,116,139)\"` (slate gray)\n */\n readonly timestampColor?: Color;\n\n /**\n * Visual style applied to timestamp text.\n *\n * Controls text appearance like boldness, dimming, etc.\n * Supports single styles, multiple styles combined, or no styling.\n * Combines with `timestampColor` for full styling control.\n *\n * @example\n * ```typescript\n * timestampStyle: \"dim\" // Single style: dimmed text\n * timestampStyle: \"bold\" // Single style: bold text\n * timestampStyle: [\"bold\", \"underline\"] // Multiple styles: bold + underlined\n * timestampStyle: [\"dim\", \"italic\"] // Multiple styles: dimmed + italic\n * timestampStyle: null // No styling\n * ```\n *\n * @default `\"dim\"`\n */\n readonly timestampStyle?: Style;\n\n /**\n * Custom colors for each log level.\n *\n * Allows fine-grained control over level appearance. Each level can have\n * its own color scheme. Unspecified levels use built-in defaults.\n * Set individual levels to `null` to disable coloring for that level.\n *\n * @example\n * ```typescript\n * levelColors: {\n * info: \"#00ff00\", // Bright green for info\n * error: \"#ff0000\", // Bright red for errors\n * warning: \"orange\", // ANSI orange for warnings\n * debug: null, // No color for debug\n * }\n * ```\n *\n * @default Built-in color scheme (purple trace, blue debug, green info, amber warning, red error, dark red fatal)\n */\n readonly levelColors?: Partial<Record<LogLevel, Color>>;\n\n /**\n * Visual style applied to log level text.\n *\n * Controls the appearance of the level indicator (e.g., \"info\", \"error\").\n * Supports single styles, multiple styles combined, or no styling.\n * Applied in addition to level-specific colors.\n *\n * @example\n * ```typescript\n * levelStyle: \"bold\" // Single style: bold level text\n * levelStyle: \"underline\" // Single style: underlined level text\n * levelStyle: [\"bold\", \"underline\"] // Multiple styles: bold + underlined\n * levelStyle: [\"dim\", \"italic\"] // Multiple styles: dimmed + italic\n * levelStyle: null // No additional styling\n * ```\n *\n * @default `\"underline\"`\n */\n readonly levelStyle?: Style;\n\n /**\n * Icon configuration for each log level.\n *\n * Controls the emoji/symbol displayed before each log entry.\n * Provides visual quick-identification of log severity.\n *\n * - `true`: Use built-in emoji set (🔍 trace, 🐛 debug, ✨ info, ⚠️ warning, ❌ error, 💀 fatal)\n * - `false`: Disable all icons for clean text-only output\n * - Object: Custom icon mapping, falls back to defaults for unspecified levels\n *\n * @example\n * ```typescript\n * icons: true // Use default emoji set\n * icons: false // No icons\n * icons: {\n * info: \"ℹ️\", // Custom info icon\n * error: \"🔥\", // Custom error icon\n * warning: \"⚡\", // Custom warning icon\n * }\n * ```\n *\n * @default `true` (use default emoji icons)\n */\n readonly icons?: boolean | Partial<Record<LogLevel, string>>;\n\n /**\n * Character(s) used to separate category hierarchy levels.\n *\n * Categories are hierarchical (e.g., [\"app\", \"auth\", \"jwt\"]) and this\n * separator joins them for display (e.g., \"app.auth.jwt\").\n *\n * @example\n * ```typescript\n * categorySeparator: \"·\" // app·auth·jwt\n * categorySeparator: \".\" // app.auth.jwt\n * categorySeparator: \":\" // app:auth:jwt\n * categorySeparator: \" > \" // app > auth > jwt\n * categorySeparator: \"::\" // app::auth::jwt\n * ```\n *\n * @default `\"·\"` (interpunct)\n */\n readonly categorySeparator?: string;\n\n /**\n * Default color for category display.\n *\n * Used as fallback when no specific color is found in `categoryColorMap`.\n * Controls the visual appearance of the category hierarchy display.\n *\n * @example\n * ```typescript\n * categoryColor: \"#666666\" // Gray categories\n * categoryColor: \"blue\" // Blue categories\n * categoryColor: \"rgb(100,150,200)\" // Light blue categories\n * categoryColor: null // No coloring\n * ```\n *\n * @default `\"rgb(100,116,139)\"` (slate gray)\n */\n readonly categoryColor?: Color;\n\n /**\n * Category-specific color mapping based on prefixes.\n *\n * Maps category prefixes (as arrays) to colors for visual grouping.\n * More specific (longer) prefixes take precedence over shorter ones.\n * If no prefix matches, falls back to the default `categoryColor`.\n *\n * @example\n * ```typescript\n * new Map([\n * [[\"app\", \"auth\"], \"#ff6b6b\"], // app.auth.* -> red\n * [[\"app\", \"db\"], \"#4ecdc4\"], // app.db.* -> teal\n * [[\"app\"], \"#45b7d1\"], // app.* (fallback) -> blue\n * [[\"lib\"], \"#96ceb4\"], // lib.* -> green\n * ])\n * ```\n */\n readonly categoryColorMap?: CategoryColorMap;\n\n /**\n * Visual style applied to category text.\n *\n * Controls the appearance of the category hierarchy display.\n * Supports single styles, multiple styles combined, or no styling.\n * Applied in addition to category colors from `categoryColor` or `categoryColorMap`.\n *\n * @example\n * ```typescript\n * categoryStyle: \"dim\" // Single style: dimmed category text\n * categoryStyle: \"italic\" // Single style: italic category text\n * categoryStyle: [\"dim\", \"italic\"] // Multiple styles: dimmed + italic\n * categoryStyle: [\"bold\", \"underline\"] // Multiple styles: bold + underlined\n * categoryStyle: null // No additional styling\n * ```\n *\n * @default `[\"dim\", \"italic\"]` (dimmed for subtle appearance)\n */\n readonly categoryStyle?: Style;\n\n /**\n * Maximum display width for category names.\n *\n * Controls layout consistency by limiting category width.\n * Long categories are truncated according to `categoryTruncate` strategy.\n *\n * @default `20`\n */\n readonly categoryWidth?: number;\n\n /**\n * Strategy for truncating long category names.\n *\n * When categories exceed `categoryWidth`, this controls how truncation works.\n * Smart truncation preserves important context while maintaining layout.\n *\n * - `\"middle\"`: Keep first and last parts (e.g., \"app.server…auth.jwt\")\n * - `\"end\"`: Truncate at the end (e.g., \"app.server.middleware…\")\n * - `false`: No truncation (ignores `categoryWidth`)\n *\n * @example\n * ```typescript\n * categoryTruncate: \"middle\" // app.server…jwt (preserves context)\n * categoryTruncate: \"end\" // app.server.midd… (linear truncation)\n * categoryTruncate: false // app.server.middleware.auth.jwt (full)\n * ```\n *\n * @default `\"middle\"` (smart context-preserving truncation)\n */\n readonly categoryTruncate?: TruncationStrategy;\n\n /**\n * Color for log message text content.\n *\n * Controls the visual appearance of the actual log message content.\n * Does not affect structured values, which use syntax highlighting.\n *\n * @example\n * ```typescript\n * messageColor: \"#ffffff\" // White message text\n * messageColor: \"green\" // Green message text\n * messageColor: \"rgb(200,200,200)\" // Light gray message text\n * messageColor: null // No coloring\n * ```\n *\n * @default `\"rgb(148,163,184)\"` (light slate gray)\n */\n readonly messageColor?: Color;\n\n /**\n * Visual style applied to log message text.\n *\n * Controls the appearance of the log message content.\n * Supports single styles, multiple styles combined, or no styling.\n * Applied in addition to `messageColor`.\n *\n * @example\n * ```typescript\n * messageStyle: \"dim\" // Single style: dimmed message text\n * messageStyle: \"italic\" // Single style: italic message text\n * messageStyle: [\"dim\", \"italic\"] // Multiple styles: dimmed + italic\n * messageStyle: [\"bold\", \"underline\"] // Multiple styles: bold + underlined\n * messageStyle: null // No additional styling\n * ```\n *\n * @default `\"dim\"` (dimmed for subtle readability)\n */\n readonly messageStyle?: Style;\n\n /**\n * Global color control for the entire formatter.\n *\n * Master switch to enable/disable all color output.\n * When disabled, produces clean monochrome output suitable for\n * non-color terminals or when colors are not desired.\n *\n * @example\n * ```typescript\n * colors: true // Full color output (default)\n * colors: false // Monochrome output only\n * ```\n *\n * @default `true` (colors enabled)\n */\n readonly colors?: boolean;\n\n /**\n * Column alignment for consistent visual layout.\n *\n * When enabled, ensures all log components (icons, levels, categories)\n * align consistently across multiple log entries, creating a clean\n * tabular appearance.\n *\n * @example\n * ```typescript\n * align: true // Aligned columns (default)\n * align: false // Compact, non-aligned output\n * ```\n *\n * @default `true` (alignment enabled)\n */\n readonly align?: boolean;\n\n /**\n * Configuration for structured value inspection and rendering.\n *\n * Controls how objects, arrays, and other complex values are displayed\n * within log messages. Uses Node.js `util.inspect()` style options.\n *\n * @example\n * ```typescript\n * inspectOptions: {\n * depth: 3, // Show 3 levels of nesting\n * colors: false, // Disable value syntax highlighting\n * compact: true, // Use compact object display\n * }\n * ```\n *\n * @default `{}` (use built-in defaults: depth=unlimited, colors=auto, compact=true)\n */\n readonly inspectOptions?: {\n /**\n * Maximum depth to traverse when inspecting nested objects.\n * @default Infinity (no depth limit)\n */\n readonly depth?: number;\n\n /**\n * Whether to use syntax highlighting colors for inspected values.\n * @default Inherited from global `colors` setting\n */\n readonly colors?: boolean;\n\n /**\n * Whether to use compact formatting for objects and arrays.\n * @default `true` (compact formatting)\n */\n readonly compact?: boolean;\n };\n\n /**\n * Enable word wrapping for long messages.\n *\n * When enabled, long messages will be wrapped at the specified width,\n * with continuation lines aligned to the message column position.\n *\n * - `true`: Auto-detect terminal width when attached to a terminal,\n * fallback to 80 columns when not in a terminal or detection fails\n * - `number`: Use the specified width in columns\n * - `false`: Disable word wrapping\n *\n * @example\n * ```typescript\n * // Auto-detect terminal width (recommended)\n * wordWrap: true\n *\n * // Custom wrap width\n * wordWrap: 120\n *\n * // Disable word wrapping (default)\n * wordWrap: false\n * ```\n *\n * @default `true` (auto-detect terminal width)\n * @since 1.0.0\n */\n readonly wordWrap?: boolean | number;\n}\n\n/**\n * Creates a beautiful console formatter optimized for local development.\n *\n * This formatter provides a Signale-inspired visual design with colorful icons,\n * smart category truncation, dimmed styling, and perfect column alignment.\n * It's specifically designed for development environments that support true colors\n * and Unicode characters.\n *\n * The formatter features:\n * - Emoji icons for each log level (🔍 trace, 🐛 debug, ✨ info, etc.)\n * - True color support with rich color schemes\n * - Intelligent category truncation for long hierarchical categories\n * - Optional timestamp display with multiple formats\n * - Configurable alignment and styling options\n * - Enhanced value rendering with syntax highlighting\n *\n * @param options Configuration options for customizing the formatter behavior.\n * @returns A text formatter function that can be used with LogTape sinks.\n *\n * @example\n * ```typescript\n * import { configure } from \"@logtape/logtape\";\n * import { getConsoleSink } from \"@logtape/logtape/sink\";\n * import { getPrettyFormatter } from \"@logtape/pretty\";\n *\n * await configure({\n * sinks: {\n * console: getConsoleSink({\n * formatter: getPrettyFormatter({\n * timestamp: \"time\",\n * categoryWidth: 25,\n * icons: {\n * info: \"📘\",\n * error: \"🔥\"\n * }\n * })\n * })\n * }\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport function getPrettyFormatter(\n options: PrettyFormatterOptions = {},\n): TextFormatter {\n // Extract options with defaults\n const {\n timestamp = \"none\",\n timestampColor = \"rgb(100,116,139)\",\n timestampStyle = \"dim\",\n level: levelFormat = \"full\",\n levelColors = {},\n levelStyle = \"underline\",\n icons = true,\n categorySeparator = \"·\",\n categoryColor = \"rgb(100,116,139)\",\n categoryColorMap = new Map(),\n categoryStyle = [\"dim\", \"italic\"],\n categoryWidth = 20,\n categoryTruncate = \"middle\",\n messageColor = \"rgb(148,163,184)\",\n messageStyle = \"dim\",\n colors: useColors = true,\n align = true,\n inspectOptions = {},\n wordWrap = true,\n } = options;\n\n // Resolve icons\n const baseIconMap: Record<LogLevel, string> = icons === false\n ? { trace: \"\", debug: \"\", info: \"\", warning: \"\", error: \"\", fatal: \"\" }\n : icons === true\n ? defaultIcons\n : { ...defaultIcons, ...(icons as Partial<Record<LogLevel, string>>) };\n\n // Normalize icon spacing for consistent alignment\n const iconMap = normalizeIconSpacing(baseIconMap);\n\n // Resolve level colors with defaults\n const resolvedLevelColors: Record<LogLevel, Color> = {\n trace: defaultColors.trace,\n debug: defaultColors.debug,\n info: defaultColors.info,\n warning: defaultColors.warning,\n error: defaultColors.error,\n fatal: defaultColors.fatal,\n ...levelColors,\n };\n\n // Level formatter function with optimized mappings\n const levelMappings: Record<string, Record<LogLevel, string>> = {\n \"ABBR\": {\n trace: \"TRC\",\n debug: \"DBG\",\n info: \"INF\",\n warning: \"WRN\",\n error: \"ERR\",\n fatal: \"FTL\",\n },\n \"L\": {\n trace: \"T\",\n debug: \"D\",\n info: \"I\",\n warning: \"W\",\n error: \"E\",\n fatal: \"F\",\n },\n \"abbr\": {\n trace: \"trc\",\n debug: \"dbg\",\n info: \"inf\",\n warning: \"wrn\",\n error: \"err\",\n fatal: \"ftl\",\n },\n \"l\": {\n trace: \"t\",\n debug: \"d\",\n info: \"i\",\n warning: \"w\",\n error: \"e\",\n fatal: \"f\",\n },\n };\n\n const formatLevel = (level: LogLevel): string => {\n if (typeof levelFormat === \"function\") {\n return levelFormat(level);\n }\n\n if (levelFormat === \"FULL\") return level.toUpperCase();\n if (levelFormat === \"full\") return level;\n\n return levelMappings[levelFormat]?.[level] ?? level;\n };\n\n // Timestamp formatters lookup table\n const timestampFormatters: Record<string, (ts: number) => string> = {\n \"date-time-timezone\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(\"T\", \" \").replace(\"Z\", \" +00:00\");\n },\n \"date-time-tz\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(\"T\", \" \").replace(\"Z\", \" +00\");\n },\n \"date-time\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(\"T\", \" \").replace(\"Z\", \"\");\n },\n \"time-timezone\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(/.*T/, \"\").replace(\"Z\", \" +00:00\");\n },\n \"time-tz\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(/.*T/, \"\").replace(\"Z\", \" +00\");\n },\n \"time\": (ts) => {\n const iso = new Date(ts).toISOString();\n return iso.replace(/.*T/, \"\").replace(\"Z\", \"\");\n },\n \"date\": (ts) => new Date(ts).toISOString().replace(/T.*/, \"\"),\n \"rfc3339\": (ts) => new Date(ts).toISOString(),\n };\n\n // Resolve timestamp formatter\n let timestampFn: ((ts: number) => string | null) | null = null;\n if (timestamp === \"none\" || timestamp === \"disabled\") {\n timestampFn = null;\n } else if (typeof timestamp === \"function\") {\n timestampFn = timestamp;\n } else {\n timestampFn = timestampFormatters[timestamp as string] ?? null;\n }\n\n // Configure word wrap settings\n const wordWrapEnabled = wordWrap !== false;\n let wordWrapWidth: number;\n\n if (typeof wordWrap === \"number\") {\n wordWrapWidth = wordWrap;\n } else if (wordWrap === true) {\n // Auto-detect terminal width\n wordWrapWidth = getOptimalWordWrapWidth(80);\n } else {\n wordWrapWidth = 80; // Default fallback\n }\n\n // Prepare category color patterns for matching\n const categoryPatterns = prepareCategoryPatterns(categoryColorMap);\n\n // Calculate level width based on format\n const allLevels: LogLevel[] = [\n \"trace\",\n \"debug\",\n \"info\",\n \"warning\",\n \"error\",\n \"fatal\",\n ];\n const levelWidth = Math.max(...allLevels.map((l) => formatLevel(l).length));\n\n return (record: LogRecord): string => {\n // Calculate the prefix parts first to determine message column position\n const icon = iconMap[record.level] || \"\";\n const level = formatLevel(record.level);\n const categoryStr = truncateCategory(\n record.category,\n categoryWidth,\n categorySeparator,\n categoryTruncate,\n );\n\n // Format message with values - handle color reset/reapply for interpolated values\n let message = \"\";\n const messageColorCode = useColors ? colorToAnsi(messageColor) : \"\";\n const messageStyleCode = useColors ? styleToAnsi(messageStyle) : \"\";\n const messagePrefix = useColors\n ? `${messageStyleCode}${messageColorCode}`\n : \"\";\n\n for (let i = 0; i < record.message.length; i++) {\n if (i % 2 === 0) {\n message += record.message[i];\n } else {\n const value = record.message[i];\n const inspected = inspect(value, {\n colors: useColors,\n ...inspectOptions,\n });\n\n // Handle multiline interpolated values properly\n if (inspected.includes(\"\\n\")) {\n const lines = inspected.split(\"\\n\");\n\n const formattedLines = lines.map((line, index) => {\n if (index === 0) {\n // First line: reset formatting, add the line, then reapply\n if (useColors && (messageColorCode || messageStyleCode)) {\n return `${RESET}${line}${messagePrefix}`;\n } else {\n return line;\n }\n } else {\n // Continuation lines: just apply formatting, let wrapText handle indentation\n if (useColors && (messageColorCode || messageStyleCode)) {\n return `${line}${messagePrefix}`;\n } else {\n return line;\n }\n }\n });\n message += formattedLines.join(\"\\n\");\n } else {\n // Single line - handle normally\n if (useColors && (messageColorCode || messageStyleCode)) {\n message += `${RESET}${inspected}${messagePrefix}`;\n } else {\n message += inspected;\n }\n }\n }\n }\n\n // Parts are already calculated above\n\n // Determine category color (with prefix matching)\n const finalCategoryColor = useColors\n ? (matchCategoryColor(record.category, categoryPatterns) || categoryColor)\n : null;\n\n // Apply colors and styling\n const formattedIcon = icon;\n let formattedLevel = level;\n let formattedCategory = categoryStr;\n let formattedMessage = message;\n let formattedTimestamp = \"\";\n\n if (useColors) {\n // Apply level color and style\n const levelColorCode = colorToAnsi(resolvedLevelColors[record.level]);\n const levelStyleCode = styleToAnsi(levelStyle);\n formattedLevel = `${levelStyleCode}${levelColorCode}${level}${RESET}`;\n\n // Apply category color and style (with prefix matching)\n const categoryColorCode = colorToAnsi(finalCategoryColor);\n const categoryStyleCode = styleToAnsi(categoryStyle);\n formattedCategory =\n `${categoryStyleCode}${categoryColorCode}${categoryStr}${RESET}`;\n\n // Apply message color and style (already handled in message building above)\n formattedMessage = `${messagePrefix}${message}${RESET}`;\n }\n\n // Format timestamp if needed\n if (timestampFn) {\n const ts = timestampFn(record.timestamp);\n if (ts !== null) {\n if (useColors) {\n const timestampColorCode = colorToAnsi(timestampColor);\n const timestampStyleCode = styleToAnsi(timestampStyle);\n formattedTimestamp =\n `${timestampStyleCode}${timestampColorCode}${ts}${RESET} `;\n } else {\n formattedTimestamp = `${ts} `;\n }\n }\n }\n\n // Build the final output with alignment\n if (align) {\n // Calculate padding accounting for ANSI escape sequences\n const levelColorLength = useColors\n ? (colorToAnsi(resolvedLevelColors[record.level]).length +\n styleToAnsi(levelStyle).length + RESET.length)\n : 0;\n const categoryColorLength = useColors\n ? (colorToAnsi(finalCategoryColor).length +\n styleToAnsi(categoryStyle).length + RESET.length)\n : 0;\n\n const paddedLevel = formattedLevel.padEnd(levelWidth + levelColorLength);\n const paddedCategory = formattedCategory.padEnd(\n categoryWidth + categoryColorLength,\n );\n\n let result =\n `${formattedTimestamp}${formattedIcon} ${paddedLevel} ${paddedCategory} ${formattedMessage}`;\n\n // Apply word wrapping if enabled, or if there are multiline interpolated values\n if (wordWrapEnabled || message.includes(\"\\n\")) {\n result = wrapText(\n result,\n wordWrapEnabled ? wordWrapWidth : Infinity,\n message,\n );\n }\n\n return result + \"\\n\";\n } else {\n let result =\n `${formattedTimestamp}${formattedIcon} ${formattedLevel} ${formattedCategory} ${formattedMessage}`;\n\n // Apply word wrapping if enabled, or if there are multiline interpolated values\n if (wordWrapEnabled || message.includes(\"\\n\")) {\n result = wrapText(\n result,\n wordWrapEnabled ? wordWrapWidth : Infinity,\n message,\n );\n }\n\n return result + \"\\n\";\n }\n };\n}\n\n/**\n * A pre-configured beautiful console formatter for local development.\n *\n * This is a ready-to-use instance of the pretty formatter with sensible defaults\n * for most development scenarios. It provides immediate visual enhancement to\n * your logs without requiring any configuration.\n *\n * Features enabled by default:\n * - Emoji icons for all log levels\n * - True color support with rich color schemes\n * - Dimmed text styling for better readability\n * - Smart category truncation (20 characters max)\n * - Perfect column alignment\n * - No timestamp display (cleaner for development)\n *\n * For custom configuration, use {@link getPrettyFormatter} instead.\n *\n * @example\n * ```typescript\n * import { configure } from \"@logtape/logtape\";\n * import { getConsoleSink } from \"@logtape/logtape/sink\";\n * import { prettyFormatter } from \"@logtape/pretty\";\n *\n * await configure({\n * sinks: {\n * console: getConsoleSink({\n * formatter: prettyFormatter\n * })\n * }\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport const prettyFormatter: TextFormatter = getPrettyFormatter();\n"],"mappings":";;;;;;;;;;AAeA,MAAM,QAAQ;AACd,MAAM,MAAM;AAGZ,MAAM,gBAAgB;CACpB,OAAO;CACP,OAAO;CACP,MAAM;CACN,SAAS;CACT,OAAO;CACP,OAAO;CACP,UAAU;CACV,SAAS;CACT,WAAW;AACZ;;;;AAKD,MAAM,SAAS;CACb,OAAO;CACP,MAAM;CACN,KAAK;CACL,QAAQ;CACR,WAAW;CACX,eAAe;AAChB;;;;AAKD,MAAM,aAAa;CACjB,OAAO;CACP,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;AACR;AA4CD,MAAM,cAAc;AACpB,MAAM,cAAc;;;;AAKpB,SAAS,YAAYA,OAAsB;AACzC,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,SAAS,WACX,QAAO,WAAW;CAIpB,MAAM,WAAW,MAAM,MAAM,YAAY;AACzC,KAAI,UAAU;EACZ,MAAM,GAAG,GAAG,GAAG,EAAE,GAAG;AACpB,UAAQ,YAAY,EAAE,GAAG,EAAE,GAAG,EAAE;CACjC;CAGD,MAAM,WAAW,MAAM,MAAM,YAAY;AACzC,KAAI,UAAU;EACZ,IAAI,MAAM,SAAS;AAEnB,MAAI,IAAI,WAAW,EACjB,OAAM,IAAI,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,KAAK,GAAG;EAEhD,MAAM,IAAI,SAAS,IAAI,OAAO,GAAG,EAAE,EAAE,GAAG;EACxC,MAAM,IAAI,SAAS,IAAI,OAAO,GAAG,EAAE,EAAE,GAAG;EACxC,MAAM,IAAI,SAAS,IAAI,OAAO,GAAG,EAAE,EAAE,GAAG;AACxC,UAAQ,YAAY,EAAE,GAAG,EAAE,GAAG,EAAE;CACjC;AAED,QAAO;AACR;;;;AAKD,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,EAAE,mBAAmB,EAAE,cAAc,GAAG,YAAY,GAAG,eAAe,GAAG,iBAAiB;AAG7F,OAAI,mBAAmB,QAAQ,SAAS,KAAK,CAC3C,UAAS,SACP,QACA,kBAAkB,gBAAgB,UAClC,QACD;AAGH,UAAO,SAAS;EACjB,OAAM;GACL,IAAI,UACD,EAAE,mBAAmB,EAAE,cAAc,GAAG,eAAe,GAAG,kBAAkB,GAAG,iBAAiB;AAGnG,OAAI,mBAAmB,QAAQ,SAAS,KAAK,CAC3C,UAAS,SACP,QACA,kBAAkB,gBAAgB,UAClC,QACD;AAGH,UAAO,SAAS;EACjB;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCD,MAAaC,kBAAiC,oBAAoB"}
|
package/formatter.ts
CHANGED
|
@@ -345,7 +345,7 @@ export interface PrettyFormatterOptions
|
|
|
345
345
|
* levelStyle: null // No additional styling
|
|
346
346
|
* ```
|
|
347
347
|
*
|
|
348
|
-
* @default `
|
|
348
|
+
* @default `"underline"`
|
|
349
349
|
*/
|
|
350
350
|
readonly levelStyle?: Style;
|
|
351
351
|
|
|
@@ -456,19 +456,9 @@ export interface PrettyFormatterOptions
|
|
|
456
456
|
* Controls layout consistency by limiting category width.
|
|
457
457
|
* Long categories are truncated according to `categoryTruncate` strategy.
|
|
458
458
|
*
|
|
459
|
-
*
|
|
460
|
-
* - `"auto"`: No width limit, categories display at full length
|
|
461
|
-
*
|
|
462
|
-
* @example
|
|
463
|
-
* ```typescript
|
|
464
|
-
* categoryWidth: 20 // Limit to 20 characters
|
|
465
|
-
* categoryWidth: 30 // Limit to 30 characters
|
|
466
|
-
* categoryWidth: "auto" // No limit
|
|
467
|
-
* ```
|
|
468
|
-
*
|
|
469
|
-
* @default `20` (20 character limit)
|
|
459
|
+
* @default `20`
|
|
470
460
|
*/
|
|
471
|
-
readonly categoryWidth?: number
|
|
461
|
+
readonly categoryWidth?: number;
|
|
472
462
|
|
|
473
463
|
/**
|
|
474
464
|
* Strategy for truncating long category names.
|
|
@@ -839,7 +829,7 @@ export function getPrettyFormatter(
|
|
|
839
829
|
const level = formatLevel(record.level);
|
|
840
830
|
const categoryStr = truncateCategory(
|
|
841
831
|
record.category,
|
|
842
|
-
|
|
832
|
+
categoryWidth,
|
|
843
833
|
categorySeparator,
|
|
844
834
|
categoryTruncate,
|
|
845
835
|
);
|
|
@@ -954,8 +944,7 @@ export function getPrettyFormatter(
|
|
|
954
944
|
|
|
955
945
|
const paddedLevel = formattedLevel.padEnd(levelWidth + levelColorLength);
|
|
956
946
|
const paddedCategory = formattedCategory.padEnd(
|
|
957
|
-
|
|
958
|
-
categoryColorLength,
|
|
947
|
+
categoryWidth + categoryColorLength,
|
|
959
948
|
);
|
|
960
949
|
|
|
961
950
|
let result =
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logtape/pretty",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.234+3fd3473b",
|
|
4
4
|
"description": "Beautiful text formatter for LogTape—perfect for local development",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logging",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"./package.json": "./package.json"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@logtape/logtape": "1.0.0-dev.
|
|
50
|
+
"@logtape/logtape": "1.0.0-dev.234+3fd3473b"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@alinea/suite": "^0.6.3",
|