Fix thread-safety issue in logging.