Improved logging functionality