Logging error instead printing stack trace