github.com/hugorut/terraform@v1.1.3/src/logging/indent.go (about)

     1  package logging
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // Indent adds two spaces to the beginning of each line of the given string,
     8  // with the goal of making the log level filter understand it as a line
     9  // continuation rather than possibly as new log lines.
    10  func Indent(s string) string {
    11  	var b strings.Builder
    12  	for len(s) > 0 {
    13  		end := strings.IndexByte(s, '\n')
    14  		if end == -1 {
    15  			end = len(s) - 1
    16  		}
    17  		var l string
    18  		l, s = s[:end+1], s[end+1:]
    19  		b.WriteString("  ")
    20  		b.WriteString(l)
    21  	}
    22  	return b.String()
    23  }