Skip to content
Snippets Groups Projects

Add --no-color and --force-color options; set --no-color as default for windows

Open Tomasz Maczukin requested to merge feature/add-no-collor-option into master

Closes #1327 and #1266

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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",
    • Maybe default should be configured here?

    • Author Maintainer

      I didn't thought about this. I'll move the default for windows here.

    • Author Maintainer

      Hmm... It looks like cli.BoolFlag don't gives you the possibility to set a default value. You can use cli.BoolFlag if you want to have a false as the default value or you can use cli.BoolTFlag if you want to have a true 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?

  • Tomasz Maczukin Added 1 commit:

    Added 1 commit:

    • 7b56fdb9 - Restore levelText setting in '--no-color' mode
  • Author Maintainer

    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?

    1. In terminal Linux and Windows
    2. In syslogs and event viewer
  • Author Maintainer

    Yes, I will prepare and post some screen shots at weekend.

  • Reassigned to @tmaczukin

  • Kamil Trzcińśki Milestone changed to %v1.6

    Milestone changed to %v1.6

  • Tomasz Maczukin Milestone changed to %Backlog

    Milestone changed to %Backlog

  • Please register or sign in to reply
    Loading