Enabling non-LWT logging

Code mostly imported from 1.7 branch, specifically rev.
037abb4024f64af8cd86a3d57668283cefd87598, to reach a state similar as to
the one seen in rev. 186bd73659f277947cf2a95fe71bec27e15d27dc.
Logging embedded in statistics