Guarded all log statements

Added an explicit check of Preferences.ENABLE_LOGGING before every log
statement