Another possibility is that it is not a race condition and that the log is causing a memory allocation which in turn changes the location of subsequent allocations.
Discussion
I.e. it could be a memory safety issue; use after free, buffer overrun, etc. ASan can be helpful in this scenario.