SmartRedis icon indicating copy to clipboard operation
SmartRedis copied to clipboard

Refactor logging string creation

Open billschereriii opened this issue 1 year ago • 1 comments

Description

We have extensive logic in some places in the SmartRedis library for creating message strings. It would be good to refactor this logic in some way to skip creation of the strings when they won't be used, such as when the logging level is not detailed enough to emit them.

    message = "Retrieved value \"";
    message += cfg_val == NULL ? "<NULL>" : cfg_val;
    message += "\"";
    if ((NULL == cfg_val) && !no_default)
        message += ". Using default value of " + std::to_string(default_value);
    log_data("SmartRedis Library", LLDebug, message);

Justification

There is a risk of performance and memory overhead with the way that these strings are created today.

Implementation Strategy

One strategy might be to have an override of std::string that accepts a log level and skips added data unless the log level is fine enough

billschereriii avatar Apr 28 '23 01:04 billschereriii

From backlog, variadic approach could be used.

mellis13 avatar May 05 '23 16:05 mellis13