use mutex to avoid merging of trace msgs from different threads