From 4a99cf9e9f86617ce894baac9dd75ab2bec11f20 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Fri, 8 May 2015 14:52:25 +0200 Subject: [PATCH] Small update/fix to properly clean ANSI going to the logfile... --- builtin/provisioners/chef-client/resource_provisioner.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/builtin/provisioners/chef-client/resource_provisioner.go b/builtin/provisioners/chef-client/resource_provisioner.go index e4c410e20..f51804ee3 100644 --- a/builtin/provisioners/chef-client/resource_provisioner.go +++ b/builtin/provisioners/chef-client/resource_provisioner.go @@ -9,6 +9,7 @@ import ( "log" "os" "path" + "regexp" "strings" "text/template" "time" @@ -269,7 +270,13 @@ func (p *Provisioner) Output(output string) { } defer f.Close() + // These steps are needed to remove any ANSI escape codes used to colorize + // the output and to make sure we have proper line endings before writing + // the string to the logfile. + re := regexp.MustCompile(`\x1b\[[0-9;]+m`) + output = re.ReplaceAllString(output, "") output = strings.Replace(output, "\r", "\n", -1) + if _, err := f.WriteString(output); err != nil { log.Printf("Error writing output to logfile %s: %v", logFile, err) }