Use a mutex around writing to the SQL log

fcntl locks aren't reflected internally within the process that created them, even if it's a completely different thread is attempting to log the file descriptor