Final refactor.

Log file, log rotation, message handling.