Improved logging handling