improve logging efficiency and atomicity

The previous strategy caused two calls to the write(…) system call per logged message. Aside from being inefficient, this had the drawback of being non-atomic. This commit switches to a strategy that causes only one write(…) call per logged message.