Monitor_filters = log2file does not produce a log file

I’m using VSCode and PlatformIO
The filter worked some time ago. I now wanted to produce a log file. Unfortunately, no file is created, neither in the project root nor in the logs directory nor anywhere else.

platformio.ini

[env]
platform = espressif32
board = esp32-s3-devkitc-1-n16r8v
framework = arduino

monitor_speed = 115200
monitor_filters = log2file, esp32_exception_decoder

build_flags = 
	-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG


[env:blink]
build_src_filter = +<main_blink.cpp> 

source code

#include <Arduino.h>

/**
 * @brief Print system information
 */
void systemInfo() {
    log_d("Total heap: %d", ESP.getHeapSize());
    log_d("Free heap: %d", ESP.getFreeHeap());
    log_d("Total PSRAM: %d", ESP.getPsramSize());
    log_d("Free PSRAM: %d", ESP.getFreePsram());
    log_d("Starting ESP32-radio running on CPU %d at %d MHz.\n", xPortGetCoreID(), ESP.getCpuFreqMHz());
}

// test RGB LED

// https://github.com/espressif/arduino-esp32/blob/114965010529c004ce914fea773095274ea2ce4d/libraries/ESP32/examples/GPIO/BlinkRGB/BlinkRGB.ino#L25-L37

void setup() {
    systemInfo();
    // No need to initialize the RGB LED
    Serial.begin(115200);
    delay(500);
#ifdef RGB_BUILTIN
    log_i("RGB_BUILTIN");
#else
    Serial.println("no RGB_BUILTIN");
#endif
}

// the loop function runs over and over again forever
void loop() {
#ifdef RGB_BUILTIN
    log_i("White LED");
    digitalWrite(RGB_BUILTIN, HIGH); // Turn the RGB LED white
    delay(1000);
    digitalWrite(RGB_BUILTIN, LOW); // Turn the RGB LED off
    delay(1000);

    log_i("Collored LED");
    rgbLedWrite(RGB_BUILTIN, RGB_BRIGHTNESS, 0, 0); // Red
    delay(1000);
    rgbLedWrite(RGB_BUILTIN, 0, RGB_BRIGHTNESS, 0); // Green
    delay(1000);
    rgbLedWrite(RGB_BUILTIN, 0, 0, RGB_BRIGHTNESS); // Blue
    delay(1000);
    rgbLedWrite(RGB_BUILTIN, 0, 0, 0); // Off / black
    delay(1000);
#endif
}

Serial Monitor Output

=========== Before Setup Start ===========
Chip Info:
------------------------------------------
  Model             : ESP32-S3
  Package           : 0
  Revision          : 0.01
  Cores             : 2
  CPU Frequency     : 240 MHz
  XTAL Frequency    : 40 MHz
  Features Bitfield : 0x00000012
  Embedded Flash    : No
  Embedded PSRAM    : No
  2.4GHz WiFi       : Yes
  Classic BT        : No
  BT Low Energy     : Yes
  IEEE 802.15.4     : No
------------------------------------------
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   387444 B ( 378.4 KB)
  Free Bytes        :   350232 B ( 342.0 KB)
  Allocated Bytes   :    32132 B (  31.4 KB)
  Minimum Free Bytes:   346428 B ( 338.3 KB)
  Largest Free Block:   278516 B ( 272.0 KB)
------------------------------------------
SPIRAM Memory Info:
------------------------------------------
  Total Size        :  8388608 B (8192.0 KB)
  Free Bytes        :  8385672 B (8189.1 KB)
  Allocated Bytes   :      576 B (   0.6 KB)
  Minimum Free Bytes:  8385672 B (8189.1 KB)
  Largest Free Block:  8257524 B (8064.0 KB)
  Bus Mode          : OPI
------------------------------------------
Flash Info:
------------------------------------------
  Chip Size         : 16777216 B (16 MB)
  Block Size        :    65536 B (  64.0 KB)
  Sector Size       :     4096 B (   4.0 KB)
  Page Size         :      256 B (   0.2 KB)
  Bus Speed         : 80 MHz
  Bus Mode          : QIO
------------------------------------------
Partitions Info:
------------------------------------------
                nvs : addr: 0x00009000, size:    20.0 KB, type: DATA, subtype: NVS
            otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
               app0 : addr: 0x00010000, size:  6400.0 KB, type:  APP, subtype: OTA_0
               app1 : addr: 0x00650000, size:  6400.0 KB, type:  APP, subtype: OTA_1
             spiffs : addr: 0x00C90000, size:  3456.0 KB, type: DATA, subtype: SPIFFS
           coredump : addr: 0x00FF0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
------------------------------------------
Software Info:
------------------------------------------
  Compile Date/Time : Feb  4 2025 16:26:42
  ESP-IDF Version   : v5.3.2-282-gcfea4f7c98-dirty
  Arduino Version   : 3.1.1
------------------------------------------
Board Info:
------------------------------------------
  Arduino Board     : Espressif ESP32-S3-DevKitC-1-N16R8V (16 MB QD, 8MB PSRAM)
  Arduino Variant   : esp32s3
  Core Debug Level  : 4
  Arduino Runs Core : 1
  Arduino Events on : 1
  Arduino USB Mode  : 1
  CDC On Boot       : 1
============ Before Setup End ============
[  2361][D][main_blink.cpp:8] systemInfo(): Total heap: 387444
[  2362][D][main_blink.cpp:9] systemInfo(): Free heap: 350144
[  2362][D][main_blink.cpp:10] systemInfo(): Total PSRAM: 8388608
[  2367][D][main_blink.cpp:11] systemInfo(): Free PSRAM: 8385672
[  2373][D][main_blink.cpp:12] systemInfo(): Starting ESP32-radio running on CPU 1 at 240 MHz.

[  2381][I][esp32-hal-periman.c:141] perimanSetPinBus(): Pin 19 already has type USB_DM (45) with bus 0x3fc98834
[  2391][I][esp32-hal-periman.c:141] perimanSetPinBus(): Pin 20 already has type USB_DP (46) with bus 0x3fc98834
[  2901][I][main_blink.cpp:25] setup(): RGB_BUILTIN
=========== After Setup Start ============
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   387444 B ( 378.4 KB)
  Free Bytes        :   350144 B ( 341.9 KB)
  Allocated Bytes   :    32188 B (  31.4 KB)
  Minimum Free Bytes:   346428 B ( 338.3 KB)
  Largest Free Block:   278516 B ( 272.0 KB)
------------------------------------------
SPIRAM Memory Info:
------------------------------------------
  Total Size        :  8388608 B (8192.0 KB)
  Free Bytes        :  8385672 B (8189.1 KB)
  Allocated Bytes   :      576 B (   0.6 KB)
  Minimum Free Bytes:  8385672 B (8189.1 KB)
  Largest Free Block:  8257524 B (8064.0 KB)
------------------------------------------
GPIO Info:
------------------------------------------
  GPIO : BUS_TYPE[bus/unit][chan]
  --------------------------------------  
    19 : USB_DM
    20 : USB_DP
    43 : UART_TX[0]
    44 : UART_RX[0]
============ After Setup End =============
[  2999][I][main_blink.cpp:34] loop(): White LED
[  5001][I][main_blink.cpp:40] loop(): Collored LED
[  9001][I][main_blink.cpp:34] loop(): White LED
[ 11001][I][main_blink.cpp:40] loop(): Collored LED
[ 15001][I][main_blink.cpp:34] loop(): White LED

That’s strange… works without issues:

Can you create a fresh new simple test-project and try again?

Oh wait…

board = esp32-s3-devkitc-1-n16r8v

Please also share the content of your esp32-s3-devkitc-1-n16r8v.json file and let me know which of the USB Ports do you use (native / USB2Serial)

Thank you for the feedback. But I solved the problem. In VSCode I use the SERIAL MONITOR. In the “Additional Settings” there is an icon “Toggle File Logging”. This toggle is responsible for whether a file is written or not.

This is the case if you use the Serial Monitor VS Code plugin.

But this is not the built-in serial monitor of PlatformIO!
Therefore, your monitor settings in platformio.ini have no effect.

Oh, I didn’t know that, good to know, thanks for the info. Where can I find the VSCode screen monitor?

What do you mean by “VSCode screen monitor” ?

There is
a) the builtin PlatformIO Serial monitor image-Icon in the status bar
b) the VS Code Plugin called “Serial Monitor”

If you use a) the monitor settings from platformio.ini applies.

Great, thank you very much. Is there a way to stop the serial monitor but not close it? Closing means that all log lines are lost.

I assume you are now talking about PlatformIO’s built-in serial monitor and not about the VS Code plugin “Serial Monitor”:

No, there isn’t. You have to close it.

But when you’re using the logging functionality aka monitor_filters = log2file, you will have all the lines in your log file!