Monitor - Configure Colors for line with TAGs


I work with platform IO monitor and I would like to configure colors for each line with special TAGs/REGEX just like that:

For example:

and in monitor line with tag ERROR will in red color.

Best Regards!

Just make your firmware output actual ANSI color codes for the terminal and activate --raw for miniterm to display them (docs)

  printf("\033[1;31m[E] Some error\n\033[0m;");

Awesome. Thank you :slight_smile:

Or even better, if you use the arduino SerialDebug library (which I believe is included in Arduino.h now) you can categorize and colorize your printline statements as debug, info, error etc.
It inherits standard printf() formatting, and it includes the line number from whence it came.

in VSC you must add this to the platform.ini:
build_flags = -DCORE_DEBUG_LEVEL=5

code sample:

int foo = 5;
int bar = 123;
char debug{“SOME DEBUG MESSAGE”};
char warning{“SOME WARNING MESSAGE”};
char verb{“SOME OTHER MESSAGE”};
log_i(“this is info with a variable %i”, foo);
log_e(“this an error with a variable %i”, bar);
log_d(“this a debug message: %s”, debug);
log_w(“this a warning message: %s”, warning);
log_v(“this a verbose message: %s”, verb);

1 Like

Indeed, this exists in the Arduino-ESP32 core.

not aware of any other cores that implement it.

You are correct max, I had not realized it was only implemented in the ESP32 core.
I have found I am able to output colors in putty, but not in VSC terminal. It was working in VSC at first, and then stopped the next day. I have not been able to figure out how to make it work again.
It must be the way the VSC terminal interprets the ansii codes, but I cannot find the setting that controls this.

output from putty

Weird. What is your exact platformio.ini? You must have the filters there for direct (example). Also the terminal program in VSCode must be the powershell and your OS should be Windows 10 (if using Windows, which I see you do). Confirmed not working in Win7 in another thread here (How to customize the display of colored lines in logs?).

1 Like

Thanks Max,
I am using Windows 10 yes.
Ansi color codes are now working after adding to the platformio.ini file
monitor_flags = --raw
terminal colorized


Some lines still show the ansi codes while others display the colors correctly. It seems to be a feature of the platformio terminal, as discussed here with maxgerhardt and others.

The workaround is to add a space before the escape sequence
Thanks to pfeerick for this suggestion.

If you are using arduino debug logging feature in VSC:

  1. ctrl-click on the log_d or log_i part of the log statement, and it will take you to the macro where this is defined.

  2. Look for the 3 lines shown below, and add a space before the backslash character:

  3. recompile, and download to device,

This should help your terminal to decipher the ansi codes properly.

The ANSI color output no longer seems to work. I have mutliple projects that use this terminal feature and all have stopped. I presume it is a PlatformIO upgrade (not) change.
I use it in my code and as part of the ESP32 logging facility.

␛[0;36m[D][main.cpp:193] setup(): ESP32 Arduino ␀

The above is now how it looks. Note the second line I tried the above ’ ’ from the Jan21 comment.

Any ideas on how to get this very useful tool operating again?

It works! You need to add monitor_filters = direct to your platformio.ini.

monitor_raw = yes it is not a way if you’d like to use filters like esp32_exception_decoder, because in this case monitor_filters = will be ignored
PS: if be more precise, the filters will be loaded and you even will see messages from class constructor, but method def rx(self, text) will never be called

Any way, if anyone’d like use colored outputs (include from core) and esp32_exception_decoder filter compatible with colored outputs, may use patched script from PR#1039

The monitor_filters = direct, esp32_exception_decoder should work in this case.