I work with platform IO monitor and I would like to configure colors for each line with special TAGs/REGEX just like that:
tag1=color1
tag2=color2
etc…
For example:
ERROR=red
INFO=green
and in monitor line with tag ERROR will in red color.
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
-DCONFIG_ARDUHAL_LOG_COLORS=1
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);
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.
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?).
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:
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.
Look for the 3 lines shown below, and add a space before the backslash character:
recompile, and download to device,
This should help your terminal to decipher the ansi codes properly.
Hi,
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.
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