Avoid useless formatting before logging

The formatting function is called even  when there is no log function
provided. It can have a noticeable performance impact in IE7.