Fixed logging function