Suppose I want to reflect exception in the log.
Should I pass stack trace into log.error() or just Exception’s toString()? Or do something better?
How to obtain stack trace string to pass to logger?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
All modern logging frameworks treat passed
Exceptionobject special:The framework (let it be logback or log4j) will format the stack trace nicely for you. Always log the full stack trace unless you really know what you are doing. Otherwise you can always filter out exceptions from given logger.
Also note that many important exception do not provide meaningful message,
NullPointerExceptionbeing important example.