@@ -1009,6 +1009,10 @@ func (c *common) log(s string) {
1009
1009
if l := len (s ); l > 0 && (string (s [l - 1 ]) != "\n " ) {
1010
1010
s += "\n "
1011
1011
}
1012
+ // Second and subsequent lines are indented 4 spaces. This is in addition to
1013
+ // the indentation provided by outputWriter.
1014
+ s = strings .Replace (s , "\n " , "\n " , - 1 )
1015
+
1012
1016
cs := c .callSite (3 ) // callSite + log + public function
1013
1017
c .newOutputWriter (cs ).Write ([]byte (s ))
1014
1018
}
@@ -1053,12 +1057,12 @@ type outputWriter struct {
1053
1057
// the call site if provided. It inserts indentation spaces for formatting. It
1054
1058
// stores input for later if it is not terminated by a newline.
1055
1059
func (o * outputWriter ) Write (p []byte ) (int , error ) {
1056
- o . b = append (o .b , p ... )
1060
+ s := string ( append (o .b , p ... ) )
1057
1061
1058
1062
o .c .mu .Lock ()
1059
1063
defer o .c .mu .Unlock ()
1060
1064
1061
- lines := strings .Split (string ( o . b ) , "\n " )
1065
+ lines := strings .Split (s , "\n " )
1062
1066
1063
1067
for i , line := range lines {
1064
1068
l := len (lines )
@@ -1072,14 +1076,13 @@ func (o *outputWriter) Write(p []byte) (int, error) {
1072
1076
}
1073
1077
1074
1078
buf := new (strings.Builder )
1075
- // The first line is indented 4 spaces. Subsequent lines are
1076
- // indented 8 spaces unless a line is the final one and
1079
+ // All lines are indented 4 spaces unless a line is the final one and
1077
1080
// is empty.
1078
1081
if i == 0 {
1079
1082
buf .WriteString (" " )
1080
1083
buf .WriteString (o .cs )
1081
1084
} else if i < l - 1 {
1082
- buf .WriteString ("\n " )
1085
+ buf .WriteString ("\n " )
1083
1086
} else {
1084
1087
// The final line must be empty otherwise the loop would have
1085
1088
// terminated earlier.
0 commit comments