Fixed ocasional test segfaults

+added thread-safe log macro