Add a sonarcube rule to catch the log overhead
leonardocarreras opened this issue · 0 comments
We were talking after @LennartSchu achieved good results by using a macro in #194:
1. Logger uses macros now. i.e. instead of * `mSLog->info("{}", some_expensive_function())`, we use * `SPDLOG_LOGGER_INFO(mSLog, "{}", some_expensive_function())`
The problem was somehow the following:
in logger calls like logger_call_with_some_level(...,"variable %var", function_calculating_var())
the function that feeds the data function_calculating_var()
can get called even for cases when the log level is not set for that case. That brings nice overheads that he just improved in the PR #194, but it will keep being something that the developer needs to remember.
A possible solution to eliminate this use of loggers calls in code instead of the proposed macro would be a rule in sonar that catches the direct calls to logger function and invites you to use the macro he proposed. There is a chance that people will forget in the long run, so at least a warning is important and maybe we suggest the insertion of the SPDLOG_LOGGER
macro.