Minor fixes to logging

Use own function for logging instead of going directly to console.log.

Use safer check for console availability.

Make first check for determining logging the debug variable. This should short curcuit the statement even before checking for console availability which may be problematic for older browsers where debugging is not normally enabled.