How the log prints exception stack information.

Source: Internet
Author: User

Package Com.doctor.slf4j;import Org.junit.test;import Org.slf4j.logger;import org.slf4j.loggerfactory;/** * How to print exception stack information. * @author Doctor * * @time December 11, 2014 morning 9:49:00 */public class Logthrowablerule {private final Logger log = Loggerfacto Ry.getlogger (GetClass ());/** * This e.tostring () method just gets the exception information, the exception stack does not get */@Testpublic void test_wronglogthrowable () {try { int test = 10/0;} catch (Exception e) {log.error ("error" + e);//main error C.d.s.logthrowablerule-//Errorjava.lan G.arithmeticexception:/By zero}}/** * Get exception stack information for correct log method */@Testpublic void test_rightwaygetinfoforthrowable () {int a = 10 ; int B = 0;try {int test = A/b;} catch (Exception e) {log.error ("error", e);//main error C.d.s.logthrowablerule-//error/ /java.lang.arithmeticexception:/by zero//at com.doctor.slf4j.LogThrowableRule.test_rightWayGetInfoForThrowable (logthrowablerule.java:35) ~[classes/:na]//at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) ~[na:1       .8.0_11]//   ............. String msg = String.Format ("{error: '%s/%s '}", A, b);//string with parameters, using String.formatlog.error (MSG, e);}}

How the log prints exception stack information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.