Refactor the whole logging infrastructure not to depend on threads sharing streams.