In nrf connect for vscode, how to store the project build log in a file

I would like to automatically save the contents of the log that `west` outputs to the terminal for a project build to a .log file;

When I click on `build` under the `action` column of `nrf connect for vscode`, I see that the code that is executed is :

"C:\windows\system32\cmd.exe /d /s /c "west build --build-dir e:/ nordic/nordic-connect-sdk-demo/Peripherals/15_usb/usb_hid_transparent/build e:/nordic/nordic-connect-sdk-demo/Peripherals/15_usb/ usb_hid_transparent --pristine --board nrf52840dk_nrf52840 --no-sysbuild -- -DNCS_TOOLCHAIN_VERSION=NONE -DCACHED_CONF_FILE=e:/nordic/ nordic-connect-sdk-demo/Peripherals/15_usb/usb_hid_transparent/prj.conf"

I would like to be able to add " > build.log 2>&1" at the end of the execution.

This is what it looks like.

"C:\windows\system32\cmd.exe /d /s /c "west build --build-dir e:/nordic/nordic-connect-sdk-demo/Peripherals/15_usb/usb_hid_transparent --pristine --nordic/nordic-connect-sdk-demo/Peripherals/15_usb/usb_hid_transparent transparent/build e:/nordic/nordic-connect-sdk-demo/Peripherals/15_usb/usb_hid_transparent --pristine --board nrf52840dk_nrf52840 --no- sysbuild -- -DNCS_TOOLCHAIN_VERSION=NONE -DCACHED_CONF_FILE=e:/nordic/nordic-connect-sdk-demo/Peripherals/15_usb/usb_hid_transparent/ prj.conf  > build.log 2>&1"

I've tried it, and if I run this code directly from the command line, it produces a `build.log` file that I want;

However, I'd like to be able to change the configuration of `nrf connect for vscode` to generate this `build.log` file every time I click on `build` under the `action` column of `nrf connect for vscode`.

I hope I can get your help. Thank you.

Parents Reply Children
  • Thank you for your patience in replying, I've read it and learnt how to customise the build's task and multiple tasks; however, I still haven't found how to implement the output of the build process log to a file, I hope you can provide further support;

  • Hi,

    Could you show what you have tried so far? What are the results?

    Best regards,
    Dejan

  • I tried the following scenario

    Modify the Action Build pointers in nRF Connect for VScode.
    Add the task in "tasks.json" as follows

    {
        "version": "2.0.0",
        "tasks": [
              {
                  "label": "build test",
                  "command": "${workspaceFolder}/test.cmd",
              }
          ]
      }

    Change the "taskName" of "build" to the name of our task, as follows:

    {
        "nrf-connect.taskBindings": {
            "build": [
                {
                    "taskName": "build test",
                },
            ]
        }
    }

    Here is the contents of my test.cmd:

    SET PATH=C:/ncs/toolchains/cf2149caf2;C:/ncs/toolchains/cf2149caf2\mingw64\bin;C:/ncs/toolchains/cf2149caf2\bin;C:/ncs/toolchains/cf2149caf2\opt\bin;C:/ncs/toolchains/cf2149caf2\opt\bin\Scripts;C:/ncs/toolchains/cf2149caf2\opt\nanopb\generator-bin;C:/ncs/toolchains/cf2149caf2\opt\zephyr-sdk\aarch64-zephyr-elf\bin;C:/ncs/toolchains/cf2149caf2\opt\zephyr-sdk\x86_64-zephyr-elf\bin;C:/ncs/toolchains/cf2149caf2\opt\zephyr-sdk\arm-zephyr-eabi\bin;C:/ncs/toolchains/cf2149caf2\opt\zephyr-sdk\riscv64-zephyr-elf\bin;%PATH%
    SET PYTHONPATH=C:/ncs/toolchains/cf2149caf2\opt\bin;C:/ncs/toolchains/cf2149caf2\opt\bin\Lib;C:/ncs/toolchains/cf2149caf2\opt\bin\Lib\site-packages
    SET ZEPHYR_TOOLCHAIN_VARIANT=zephyr
    SET ZEPHYR_SDK_INSTALL_DIR=C:/ncs/toolchains/cf2149caf2\opt\zephyr-sdk
    SET ZEPHYR_BASE=C:/ncs/v2.6.0\zephyr
    west build --build-dir D:/nordic/ncs_tutorial/code/Peripherals/15_usb/usb_hid_transparent/build D:/nordic/ncs_tutorial/code/Peripherals/15_usb/usb_hid_transparent --pristine --board nrf52840dk_nrf52840 --no-sysbuild -- -DNCS_TOOLCHAIN_VERSION=NONE -DCACHED_CONF_FILE=D:/nordic/ncs_tutorial/code/Peripherals/15_usb/usb_hid_transparent/prj.conf > build.log 2>&1
    

    In this way, I can realize that all the contents of west's logs are output to the build.log file

    However, the cmd file that executes the west command in this way is written manually by me.

    In this way, I wrote the cmd file for executing west commands manually, and I would prefer to replace it with nrf connect for vscode, which uses the "Build: usb_hid_transparent/build (active)" task according to my configuration to save the output log to a file.

  • Hi,

    Could you elaborate and show the difference of what you managed to achieve and what you prefer?

    Best regards,
    Dejan

  • However, the cmd file that executes the west command in this way is written manually by me.

    In this way, I wrote the cmd file for executing west commands manually, and I would prefer to replace it with nrf connect for vscode, which uses the "Build: usb_hid_transparent/build (active)" task according to my configuration to save the output log to a file.

    The difference between what I've realized so far, and what I want is here

Related