Tuesday, December 29, 2015

Get you current class name in logger log4j using Java

Log4j is very important utility for debugging error in Java code. This low level utility will give the exact class, method and line where error is occurred.

Just declare the below line in Base class which is extended by child class

public final Logger logger = Logger.getLogger(this.getClass().getSimpleName());

Eg:
In my com.aut.AppTest.java
logger.info("this line is to debug java code");

OUTPUT
2015-12-29 16:45:32 INFO  AppTest     - this line is to debug java code

Now if getSimpleName() is replace by getName() the logger will log details of package as well.

No comments:

Post a Comment

Read CSV from S3

 import csv def count_records(csv_file):     record_count = 0     first_line = None     last_line = None     # Open the CSV file and read it...