Conditional logging with minimal cyclomatic complexity

前端 未结 12 1909
情歌与酒
情歌与酒 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:20

    In languages supporting lambda expressions or code blocks as parameters, one solution for this would be to give just that to the logging method. That one could evaluate the configuration and only if needed actually call/execute the provided lambda/code block. Did not try it yet, though.

    Theoretically this is possible. I would not like to use it in production due to performance issues i expect with that heavy use of lamdas/code blocks for logging.

    But as always: if in doubt, test it and measure the impact on cpu load and memory.

提交回复
热议问题