treewide: fix flushing of messages to logs in some cases

... by setting FILE* properties and replace the explicit flushes.
Explicit flushing couldn't be well done e.g. for lua's error() function.
In particular, we had problems with journald not getting logs timely.
32 jobs for log-flushing
in 27 minutes and 19 seconds and was queued for 4 seconds