You could add a third named arg to this function, `log`, for those cases in the code above where you have:

```python
if log:
  print msg
  flush()
```

and then call in the code `log_message(msg, log)`, and you'd use `log_message` everywhere (and save 2 lines everytime).