You can try implementation from MbedOS 6 BLE if also working under MbedOS5, but probably not.
- BLE - API references and tutorials | Mbed OS 6 Documentation section Tracing.
- example of Mbed trace init in main.cpp
- mbed_app.json of the example
- and also in this topic
BR, Jan