Import and tweaks from https://code.google.com/p/log4go/