1- import { inspect , type InspectOptions } from "#util" ;
21import {
3- getLogLevels ,
4- type LogLevel ,
5- type LogRecord ,
6- type TextFormatter ,
7- type TextFormatterOptions ,
2+ getLogLevels ,
3+ type LogLevel ,
4+ type LogRecord ,
5+ type TextFormatter ,
6+ type TextFormatterOptions ,
87} from "@logtape/logtape" ;
8+ import { inspect , type InspectOptions } from "#util" ;
99import { getOptimalWordWrapWidth } from "./terminal.ts" ;
1010import { truncateCategory , type TruncationStrategy } from "./truncate.ts" ;
1111import { getDisplayWidth , stripAnsi } from "./wcwidth.ts" ;
@@ -477,10 +477,11 @@ export interface PrettyFormatterOptions
477477 */
478478 readonly messageColor ?: Color ;
479479 /**
480- * Visual style applied to save some horizontal space
480+ * Controls whether the message starts on a new line below the category.
481481 *
482- * Controls whether the message will start after the category, or whether
483- * it will wrap below the categories, where the categories appear as a heading
482+ * When `true`, the log message will be displayed on a new line below
483+ * the timestamp, level, and category, which can help save horizontal space
484+ * in narrow terminals or when dealing with long category names.
484485 *
485486 * @default false
486487 */
@@ -832,8 +833,9 @@ export function getPrettyFormatter(
832833 const messageColorCode = useColors ? colorToAnsi ( messageColor ) : "" ;
833834 const messageStyleCode = useColors ? styleToAnsi ( messageStyle ) : "" ;
834835 const messageStart = messageNewLine ? "\n" : "" ;
835- const messageNewLineIdentation = 4
836- const messageNewLineIdentationProperties = messageNewLine ? messageNewLineIdentation + 2 :undefined
836+ // When message is on a new line, use consistent indentation
837+ const messageIndent = 4 ; // Standard indentation for new line messages
838+ const propertyIndent = messageNewLine ? messageIndent + 2 : undefined ;
837839 const messagePrefix = useColors
838840 ? `${ messageStyleCode } ${ messageColorCode } `
839841 : "" ;
@@ -951,7 +953,7 @@ export function getPrettyFormatter(
951953 `${ formattedTimestamp } ${ formattedIcon } ${ paddedLevel } ${ paddedCategory } ` ,
952954 ) ,
953955 )
954- : messageNewLineIdentation ;
956+ : messageIndent ;
955957
956958 // Apply word wrapping if enabled, or if there are multiline interpolated values
957959 if ( wordWrapEnabled || message . includes ( "\n" ) ) {
@@ -969,7 +971,7 @@ export function getPrettyFormatter(
969971 wordWrapEnabled ? wordWrapWidth : Infinity ,
970972 useColors ,
971973 inspectOptions ,
972- messageNewLineIdentationProperties
974+ propertyIndent ,
973975 ) ;
974976 }
975977
@@ -983,7 +985,7 @@ export function getPrettyFormatter(
983985 `${ formattedTimestamp } ${ formattedIcon } ${ formattedLevel } ${ formattedCategory } ` ,
984986 ) ,
985987 )
986- : messageNewLineIdentation ;
988+ : messageIndent ;
987989
988990 // Apply word wrapping if enabled, or if there are multiline interpolated values
989991 if ( wordWrapEnabled || message . includes ( "\n" ) ) {
@@ -1001,7 +1003,7 @@ export function getPrettyFormatter(
10011003 wordWrapEnabled ? wordWrapWidth : Infinity ,
10021004 useColors ,
10031005 inspectOptions ,
1004- messageNewLineIdentationProperties
1006+ propertyIndent ,
10051007 ) ;
10061008 }
10071009
@@ -1016,12 +1018,12 @@ function formatProperties(
10161018 maxWidth : number ,
10171019 useColors : boolean ,
10181020 inspectOptions : InspectOptions ,
1019- messageNewLineIdentationProperties ?: number
1021+ propertyIndent ?: number ,
10201022) : string {
10211023 let result = "" ;
10221024 for ( const prop in record . properties ) {
10231025 const propValue = record . properties [ prop ] ;
1024- const pad = messageNewLineIdentationProperties ?? indentWidth - getDisplayWidth ( prop ) ;
1026+ const pad = propertyIndent ?? indentWidth - getDisplayWidth ( prop ) - 2 ;
10251027 result += "\n" + wrapText (
10261028 `${ " " . repeat ( pad ) } ${ useColors ? DIM : "" } ${ prop } :${
10271029 useColors ? RESET : ""
0 commit comments