Refactored logger further so errors get logged through it too.