forked from Mirrors/bubbletea
Add space after prefix if one doesn't exist
This commit is contained in:
parent
ef8a6895a1
commit
479a1ceb35
11
logging.go
11
logging.go
|
@ -3,6 +3,7 @@ package tea
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LogToFile sets up default logging to log to a file. This is helpful as we
|
// 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
|
return nil, err
|
||||||
}
|
}
|
||||||
log.SetOutput(f)
|
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)
|
log.SetPrefix(prefix)
|
||||||
|
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue