Using logging flag before function-call to log

Dramatically improves performance to avoid log function call