go函数中的调试模式

I have function which search patterns in string. If pattern is found function log it to file, else do nothing.

func find(patterns_list, line) {
    foreach pattern in patterns_list {
        if pattern in line {
            log to file
        }
    }
}

I want to add debug mode to my function. If variable debug is set to true, then function print every pattern while checking.

func find(patterns_list, line, debug) {
    foreach pattern in patterns_list {
        if debug is true {
            print pattern
        }
        if pattern in line {
            log to file
        }
    }
}

How to do this without overhead related to condition (debug is true). This piece of code will be slowing function every time.

I know, I can clone function and check condition before running: find() -> normal mode find_debug() -> debug mode

But how to do it without above solution ?

</div>