[request] CubeCell too many printfs in libraries & core code

Hi,
I have a request … is it possible to define a global build debug/release so that all the printf are disabled & removed?

I find myself removing all the printf manually (especially for the LoRaWAN lib) most of the time for code releases that are supposed to be “final”

printf is quite expensive and it would be nice if we can remove it completely from release builds by defining a better logging macro or something like that…
:slight_smile:

thanks

1 Like

One way is to create your own ‘myprintf’ output function and always use that to output? you can then simply switch off the printf call within it when you want to release it

Another idea could be to put
#ifdef DEBUG

#endif
around your printf statements and put a statement
#define DEBUG
at the start of your program. printf would then translated only if DEBUG is defined.

Achim

of course I have my own macro for printf in my code … but I see libraries with hardcoded printf (like Lorawan)

I was just wondering if there is an “official” define for printf/serial.printf so that the default libraries can be cleaner and smaller for release…

thanks for your reply

Use your own macro - say call dbprintf. This macro has two parts.

  1. To pass all data from dbprintf to printf
  2. To ignore all data - no printf

Around this macro place a #ifdef debug

Then you #define debug or comment out. If debug is defined the macro passes dbprint to printf. If debug not defined then the macro does not pass dbprintf.

I normally have this macro at the start of all code modules, as when developing some are on or off depending on their state.

Hi all,
I want to clarify my request: I’m NOT talking about local macro in the user code, of course I do that too.
:slight_smile:

my request is about the “official” Heltec libraries, for example the LoraWAN library, which in theory we are not supposed to manually fix all the time (aren’t we?)

looking to the overall repo I see a ton of “printf” or “Serial.print” calls that are “hardcoded” and this makes the code larger (print calls are heavy) and dirty (because we have commands over serial all the time).

if we had only one set of “official” macro, call it HLTC_PRINTF, HLTC_PRINT, HLTC_DBG_PRINT(level, message) used overall the repo it will make the final build smaller in code size and we don;t need to change every library every time we do a “git pull”.

In a “production build” you do not want to have any print at all on your console.

sure we can comment out “Serial.begin()” and you won’t see any log in console, but the code is still “large” in footprint because the calls to Serial.println() are still compiled-in (every library pulled under CubeCell package) and I would like to avoid this (at least from official libraries released by Heltec)

anyhow … it is just a request … I have my own patch to change these call in the library I use.

thanks a lot for your help

2 Likes