Log currently executing task over UART whenever it changes?

I’m writing code for an STM32 microcontroller and I compile using GCC (STM32CubeIDE). I think it would be useful to output the currently executing task over a (4 MBaud) UART every time the currently executing task changes. Does anybody know where I should place my call to UARTtransmit(bytesToTransmit)? Also, how would I obtain an identifier of the currently executing task to give as the bytesToTransmit argument to my UARTtransmit(bytesToTransmit) function? I would imagine the easiest would be to simply transmit the 4-byte address of struct tskTaskControlBlock object for the currently executing task, or?

You can override traceTASK_SWITCHED_IN and traceTASK_SWITCHED_OUT macros.