Software Development

How to Trace Program Flow using Log4j2



Do you not hate it to log method with “entry” and “exit” texts? Should you use “start” or “entry”? This article demonstrates how to use Log4j2 API to perform flow tracing without the need to provide texts.

Software Environment

  • Windows 7 Professional SP1
  • Eclipse – Kepler Release
  • Java 1.7 (1.7.0_67 – Windows x86)
  • Apache Log4j 2.0.2

Download Log4j2 and Reference it

  1. Download log4j2 from
  2. Extract the file
  3. Copy the log4j-api-2.0.2.jar and log4j-core-2.0.2.jar to your Eclipse project
  4. Reference the two jar files

Define your log4j2.xml


Define log4j2.xml and place it right under the src folder (visible also via Eclipse workspace)

Sample Usage

Sample Output

Get the Codes


You Might Also Like