Cleanup logger.py

Rewrite the stuff to be more pythonic:
- encapsulate logic in a class
- cleanup whitespace
- don't use globals

Still a lot of opportunity to cleanup see 9d8f2af713ade5eceba4ca7875d7b41c2b86b27e commit message.