Added logging functionality for both errors and successes.