with in


How to run the example program with in I have installed at \fyicenter\apache-log4j-1.2.17 folder.


A file an example Log4j configuration file in properties format. It can used to run the example program provided in the

Here is the content of located in the \fyicenter\apache-log4j-1.2.17\examples folder.

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# ...

# An example log4j configuration file that outputs both to System.out
# and a file named 'test'.

# The root logger uses the appender called A1. 

# The root logger uses the appenders called A1 and A2. Since no level
# is specified, note the empty string between the comma (",") and the
# equals sign ("="), the level of the root logger remains
# untouched. Log4j always initializes the level for the root logger to
# DEBUG. The root logger is the only logger that has a default
# level. Bu default, all other loggers do not have an assigned level,
# such that they inherit their level instead.

log4j.rootLogger=, A1, A2

# A1 is set to be ConsoleAppender sending its output to System.out

# A1 uses PatternLayout.

# The conversion pattern consists of date in ISO8601 format, level,
# thread name, logger name truncated to its rightmost two components
# and left justified to 17 characters, location information consisting
# of file name (padded to 13 characters) and line number, nested
# diagnostic context, the and the application supplied message

log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n

# Appender A2 writes to the file "test".

# Truncate 'test' if it aleady exists.

# Appender A2 uses the PatternLayout.
log4j.appender.A2.layout.ConversionPattern=%-5r %-5p [%t] %c{2} - %m%n

Let's run the with this configuration file,

\fyicenter>cd \fyicenter\apache-log4j-1.2.17

\fyicenter\apache-log4j-1.2.17>java -version
java version "1.7.0_45"

\fyicenter\apache-log4j-1.2.17>javac -cp .;log4j-1.2.17.jar examples\

\fyicenter\apache-log4j-1.2.17>java -cp .;log4j-1.2.17.jar examples.Sort 
   examples\ 10

10:07:09,344 INFO  [main] examples.Sort     (     
   - Populating an array of 10 elements in reverse order.
10:07:09,348 INFO  [main] examples.SortAlgo (     
   - Entered the sort method.
10:07:09,348 DEBUG [main] SortAlgo.OUTER    ( i=9 
   - in outer loop.
10:07:09,348 DEBUG [main] SortAlgo.INNER    ( i=9 j=0 
   - in inner loop.
10:07:09,349 DEBUG [main] SortAlgo.SWAP     ( i=9 j=0 
   - Swapping intArray[0]=9 and intArray[1]=8

The configuration file also generated a log file called "test" to capture some different log messages:

\fyicenter\apache-log4j-1.2.17> type test
0     INFO  [main] examples.Sort - Populating an array of 
                   10 elements in reverse order.
4     INFO  [main] examples.SortAlgo - Entered the sort method.
4     DEBUG [main] SortAlgo.OUTER - in outer loop.
4     DEBUG [main] SortAlgo.INNER - in inner loop.
5     DEBUG [main] SortAlgo.SWAP - Swapping intArray[0]=9 and intArray[1]=8
5     DEBUG [main] SortAlgo.INNER - in inner loop.


⇒ FAQ for Apache Log4j

⇐ Run Example in

⇑ Using Apache Log4j 1.x in Java Programs

⇑⇑ FAQ for Apache Log4j

2016-06-27, 2206👍, 0💬