The locking within logRotate only covers the swap of file handles, but renaming an open log file while it is being written to by another thread is not safe. The locking needs to be modified so that no race conditions exist.
In addition, doing log rotation from a signal handler may be unsafe. It would be better to set a flag in the signal handler, and respond to it from a normal (non-signal) code path. For example, we could rotate the log next time something is logged.
Currently there is a deadlock if the current thread is in the middle of logging.