Which solution do you recommend, the second is simpler ( less code ), but there are drawbacks on using it ?
First: (Set a global debug flag)
The following will achieve what you are looking for:
window.console && console.log('foo');