Esp-idf: Add color to build output log (more readable errors and warnings) (IDFGH-1965)

Created on 4 Oct 2019  路  7Comments  路  Source: espressif/esp-idf

Environment

  • Development Kit: ESP32-PICO-Kit
  • Kit version v4
  • Module or chip used: ESP32-PICO-D4
  • IDF version v4.1-dev-256-g9f145ff16
  • Build System: CMake
  • Compiler version xtensa-esp32-elf-gcc (crosstool-NG esp32-2019r1) 8.2.0
  • Operating System: Windows
  • Power Supply: USB

Problem Description

The build process output a lot of text. It is sometimes difficult to spot errors and warnings.

Expected Behavior

It could be great if the output could be colorized (red for errors, orange/yellow for warning etc), to make the build log more readable.

Most helpful comment

Add the parameters onto the environment, by executing:

export EXTRA_CFLAGS=-fdiagnostics-color=always
export GCC_COLORS="error=01;31:warning=01;35:note=01;36:range1=32:range2=34:locus=01:quote=01:path=01;36:fixit-insert=32:fixit-delete=31:diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32:type-diff=01;32"

before my idf.py build command, but still only B&W output. Obviously doing something wrong.

Ps. Putting the some definitive handles here how to enable colour build-output would would surely help a lot of people, as this issue is where people land when searching for coloured build output.

All 7 comments

I've added add_compile_options (-fdiagnostics-color=always) to the main CMakeList.txt file of my project and set an environment variable GCC_COLORS="error=01;31:warning=01;33:note=01;36:caret=01;32:locus=01:quote=01" which give me some colored output. Is there any better way to do this?

There is no official support for this in the sense that you can't pass an argument to idf.py to enable this. You can, however, skip adding add_compile_options (-fdiagnostics-color=always) to every project you work with OR by adding the -fdiagnostics-color=always to the environment variable EXTRA_CFLAGS and EXTRA_CXXFLAGS to have it be "permanent".

You still need to set the GCC_COLORS however for the colors you want the output to be.

You can colorize the log with following code.

static const char *TAG = "TEST_TASK";
ESP_LOG_LEVEL(ESP_LOG_ERROR, TAG, "%d - Red log", 1);
ESP_LOG_LEVEL(ESP_LOG_WARN, TAG, "%d - Yello log", 2);
ESP_LOG_LEVEL(ESP_LOG_INFO, TAG, "%d - Green log", 3);

I found the way from the source code of esp_log.h

@esanai I think @AloyseTech was referring to colorizing the actual output build log, not the runtime logs.

@renzbagaporo You are right. I'm sorry for my misunderstanding.

There is no official support for this in the sense that you can't pass an argument to idf.py to enable this. You can, however, skip adding add_compile_options (-fdiagnostics-color=always) to every project you work with OR by adding the -fdiagnostics-color=always to the environment variable EXTRA_CFLAGS and EXTRA_CXXFLAGS to have it be "permanent".

You still need to set the GCC_COLORS however for the colors you want the output to be.

Or the devs could actually fix this? It works with Make, for heaven's sake.
This issue needs to be reopened.

Add the parameters onto the environment, by executing:

export EXTRA_CFLAGS=-fdiagnostics-color=always
export GCC_COLORS="error=01;31:warning=01;35:note=01;36:range1=32:range2=34:locus=01:quote=01:path=01;36:fixit-insert=32:fixit-delete=31:diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32:type-diff=01;32"

before my idf.py build command, but still only B&W output. Obviously doing something wrong.

Ps. Putting the some definitive handles here how to enable colour build-output would would surely help a lot of people, as this issue is where people land when searching for coloured build output.

Was this page helpful?
0 / 5 - 0 ratings