first attempt to fix this piece a code!
(at least logging should work properly now)