Patch by Tomasz Kuchta that refactors the logging code, by introducing a new logging class hierarchy.