From 479a1ceb3542c02919c3c4d4d8fb072985318fde Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 1 Feb 2021 15:19:50 -0500 Subject: [PATCH] Add space after prefix if one doesn't exist --- logging.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/logging.go b/logging.go index 6ec90c3..abd8e23 100644 --- a/logging.go +++ b/logging.go @@ -3,6 +3,7 @@ package tea import ( "log" "os" + "unicode" ) // LogToFile sets up default logging to log to a file. This is helpful as we @@ -23,6 +24,16 @@ func LogToFile(path string, prefix string) (*os.File, error) { return nil, err } log.SetOutput(f) + + // Add a space after the prefix if a prefix is being specified and it + // doesn't already have a trailing space. + if len(prefix) > 0 { + finalChar := prefix[len(prefix)-1] + if unicode.IsSpace(rune(finalChar)) { + prefix += " " + } + } log.SetPrefix(prefix) + return f, nil }