Added a lock around the logging