log: make log output atomic

Output messages using a single fprintf to avoid mixed output from multiple threads/processes.