This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Large code size due to supporting NRF_LOG_ENABLED

I have noted that the code size of my project is reduced by more than a factor of two if I set NRF_LOG_ENABLED to 0. It is also reduced significantly if I set the Log Level to INFO versus DEBUG. That is because all of my log statements (in my code) are at DEBUG level.

Now I am trying to figure out why. I assume it must be for the storage of the strings. For example, the strings in a statement like this:

NRF_LOG_ERROR("Error starting scanner. Error code: 0x%02X", err_code);

If so, I guess there is no way to reduce the size of the code with logging.

Parents
  • Hi,

    You are right. All debug log strings that are enabled are part of the application image, so it will consume flash. Therefore a lower log level will give you lower sizes. Note that you do not need to have the same log level for all modules. If you are particular interested in one module you can set a low default log level (say ERROR), and then use DEBUG for a particular module that you are currently looking into. For instance if you only are interested in peer manager logging you can set PM_LOG_LEVEL to 4 (DEBUG), and set NRF_LOG_DEFAULT_LEVEL to 1 (ERROR).

Reply
  • Hi,

    You are right. All debug log strings that are enabled are part of the application image, so it will consume flash. Therefore a lower log level will give you lower sizes. Note that you do not need to have the same log level for all modules. If you are particular interested in one module you can set a low default log level (say ERROR), and then use DEBUG for a particular module that you are currently looking into. For instance if you only are interested in peer manager logging you can set PM_LOG_LEVEL to 4 (DEBUG), and set NRF_LOG_DEFAULT_LEVEL to 1 (ERROR).

Children
No Data
Related