Conditional logging with minimal cyclomatic complexity

前端 未结 12 1946
情歌与酒
情歌与酒 2020-11-27 10:58

After reading \"What’s your/a good limit for cyclomatic complexity?\", I realize many of my colleagues were quite annoyed with this new QA policy on our project: no more 10

12条回答
  •  孤街浪徒
    2020-11-27 11:19

    As much as I hate macros in C/C++, at work we have #defines for the if part, which if false ignores (does not evaluate) the following expressions, but if true returns a stream into which stuff can be piped using the '<<' operator. Like this:

    LOGGER(LEVEL_INFO) << "A String";
    

    I assume this would eliminate the extra 'complexity' that your tool sees, and also eliminates any calculating of the string, or any expressions to be logged if the level was not reached.

提交回复
热议问题