Modified the log function to accept errors