Fix issues on Mac OS X platform.
Refactoring log.py.