Add --no-color and --force-color options; set --no-color as default for windows
Merge request reports
Activity
55 logrus.DebugLevel: helpers.ANSI_BOLD_WHITE, 56 logrus.WarnLevel: helpers.ANSI_YELLOW, 57 logrus.ErrorLevel: helpers.ANSI_BOLD_RED, 58 logrus.FatalLevel: helpers.ANSI_BOLD_RED, 59 logrus.PanicLevel: helpers.ANSI_BOLD_RED, 60 } 61 62 text := map[logrus.Level]string{ 63 logrus.DebugLevel: "", 64 logrus.WarnLevel: "WARNING: ", 65 logrus.ErrorLevel: "ERROR: ", 66 logrus.FatalLevel: "FATAL: ", 67 logrus.PanicLevel: "PANIC: ", 68 } 69 70 if f.DisableColors == true && f.ForceColors != true { 85 Name: "no-color", 86 Usage: "Run in no-color mode", 87 EnvVar: "NO_COLOR", 88 }, 89 cli.BoolFlag{ 90 Name: "force-color", 91 Usage: "Run in force-color mode", 92 EnvVar: "FORCE_COLOR", 93 }, 94 } 95 app.Flags = append(app.Flags, newFlags...) 96 97 appBefore := app.Before 98 app.Before = func(c *cli.Context) error { 99 logrus.SetFormatter(&RunnerTextFormatter{ 100 DisableColors: c.Bool("no-color") || runtime.GOOS == "windows", 72 } 73 74 lvlText = text[level] 75 lvlColor = color[level] 76 resetColor = helpers.ANSI_RESET 77 return 78 } 79 80 func SetRunnerFormatter(app *cli.App) { 75 81 logrus.SetFormatter(&RunnerTextFormatter{}) 82 83 newFlags := []cli.Flag{ 84 cli.BoolFlag{ 85 Name: "no-color", 86 Usage: "Run in no-color mode", 87 EnvVar: "NO_COLOR", Hmm... It looks like
cli.BoolFlag
don't gives you the possibility to set a default value. You can usecli.BoolFlag
if you want to have afalse
as the default value or you can usecli.BoolTFlag
if you want to have atrue
as the default value. Look here and here.And since we want to set the
true
/false
dynamically basing on the used OS then my current solution looks like a clearest one.
Is there reason why we are changing formatter globally? How will this look in log files?
First - we had one, globally set, formatter so I've changed this one :)
Second - if you are using a non-TTY environment - like cmd/PowerShell on Windows (#1266) or with scripting (#1327) - then escape signals will be annoying in both GitLab Runner logs and build logs. Yes, GitLab on build page will handle the colors but if you want to parse build logs, then you fall again into the problem described in the issues.
@tmaczukin Can you post examples how it will look?
- In terminal Linux and Windows
- In syslogs and event viewer
@tmaczukin Update?
Reassigned to @tmaczukin
Milestone changed to %v1.6
Milestone changed to %Backlog