I'd like to log some debug stuff to a mobile app over BLE, when in a connection, using the NRF_LOG library and the Nordic UART service. I have this working just fine without NRF_LOG, just using printf() calls for the log statements and then re-wiring printf() as follows:
-
When in a BLE connection, take the first 20 characters of the string and write them over BLE using ble_nus_string_send().
-
Always pass everything to SEGGER_RTT_Write() as well, whether we're in a BLE connection or not.
I'd now like to do the same using NRF_LOG for consistency, as well as getting the log statements in the SDK sources out the same way. At first glance the NRF_LOG library claims to support multiple backends, so I thought I'd write a new backend that just does the BLE stuff. It would send log statements over BLE when in a connection, and do nothing with them when not.
But there doesn't seem to be any way to configure multiple backends at once. Can there be only one nrf_log_backend_init() function linked in at once?
I note that he UART and Segger RTT backends were NOT written as separate backends at all - they're just one backend with the calls all mashed into one implementation.
The SDK docs say "The NRF_LOG_HANDLERS_SET macro can be used to change handlers on the fly." I think this still isn't what I want. I don't want to change the handler, I want to add an additional handler. Would also like to avoid wrapping the default backend handler in my handler and making a further mess of it.
Can this be done?