redirecting printf to ESP_LOGx

OBDave
Posts: 12
Joined: Wed May 08, 2019 10:34 pm

redirecting printf to ESP_LOGx

Postby OBDave » Fri Nov 08, 2019 8:05 pm

Hello - hopefully this is the right place for this question.

It seems the esp-idf Bluetooth library doesn't have much BT/RFCOMM support, so I'm starting to work on a Bluetooth implementation using Blue Kitchen's BTStack. BTStack is a third-party library that supports many hardware platforms, among them the esp32. I've got it working, but their library is rich with informational printf's that would be much better suited for ESP_LOGI() calls. The library is rather, uh, loquacious.

So, one solution would be to go through all of their code and manually change printfs to ESP_LOGI calls, but that's a lot of code to change and I'd have to redo it every time the library gets updated. Or I could try to write a little .h file with a macro redefining printf to an ESP_LOGI wrapper using some VA_ARGS magic. I'd still have to touch every module, but at least it would just be a header file include.

But the cleanest solution would be to somehow hijack the esp32 printf library function, assuming it's not needed elsewhere or by ESP_LOG itself. I'm wondering if anyone has run into this or a similar issue before, and how they solved it.

Ideas?

WiFive
Posts: 2768
Joined: Tue Dec 01, 2015 7:35 am

Re: redirecting printf to ESP_LOGx

Postby WiFive » Sat Nov 09, 2019 5:19 am


OBDave
Posts: 12
Joined: Wed May 08, 2019 10:34 pm

Re: redirecting printf to ESP_LOGx

Postby OBDave » Sat Nov 09, 2019 10:07 am

Dang, perfect. High five, WiFive! Thanks much.

OBDave
Posts: 12
Joined: Wed May 08, 2019 10:34 pm

Re: redirecting printf to ESP_LOGx

Postby OBDave » Sun Nov 10, 2019 12:22 am

Just to follow up (and for anyone who's as lost as me), now that I've tinkered with this I see they don't quite follow the ESP logging convention. They are not routing their calls through ESP_LOGx, so debug levels are not handled in config, like everyone else.

Unless I'm missing something, to change the BTStack log levels, it appears you have to

1) edit .../port/esp32/components/btstack/include/btstack_config.h which resides in the btstack-master, and comment out each #define for the log levels you want to disable. So for example

Code: Select all

#define ENABLE_LOG_ERROR
// #define ENABLE_LOG_INFO
// #define ENABLE_LOG_DEBUG
enables ERROR but disables INFO and DEBUG.

2) re-install BTstack by re-running .../port/esp32/integrate_btstack.py to repopulate the esp-idf tree

3) then you can do your clean and rebuild.

Thanks again,

Dave

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 23 guests