For this homework, you will create a Log4j2 configuration file that produces the correct output to a log file and to the console.
You should NOT modify the LoggerSetup.java
, LoggerSetupTest.java
, or test/resources/debug.txt
files. You should only create a NEW file in the correct location to configure log4j2.
Your search engine will eventually be multithreaded. Debugging can be challenging when we start multithreading code, since threads execute our code in nondeterministic order.
Logging is one of the few ways we have figure out what happened, in which thread, and in what order when multithreading. It is useful to figure out how to configure logging before beginning to multithread the search engine project!
The output that needs to be produced differs by console and file, and by which logger is being used. See below for details.
Only output the logging level (unchanged), message, and short error message (if appropriate) to the console.
Configure the root logger to output INFO
messages and higher to the console the class-specific LoggerSetup
logger to output FATAL
messages to the console.
The expected console output should look like:
Root Logger:
INFO: Ibis
WARN: Wren
ERROR: Eastern Eagle
FATAL: Catching Falcon
Class Logger:
FATAL: Catching Falcon
The log file should be named debug.log
and saved in the current working directory. You can use the example configuration files from lecture as a starting point.
Include the 3 digit sequence number, logging level using 5 left-aligned letters, thread name at file name and line number, a dash, the message, 3 lines from any throwable stack trace (if appropriate), and a newline character (%n
) in the debug.log
file.
Configure the root logger to output ALL
messages to the log file. The class-specific LoggerSetup
logger should not produce any output to the log file.
See the test/resources/debug.txt
file for the expected file output. It is also included below:
[001 TRACE] main at LoggerSetup.java:23 - Turkey
[002 DEBUG] main at LoggerSetup.java:24 - Duck
[003 INFO ] main at LoggerSetup.java:25 - Ibis
[004 WARN ] main at LoggerSetup.java:26 - Wren
[005 ERROR] main at LoggerSetup.java:29 - Eastern java.lang.Exception: Eagle
at edu.usfca.cs272.LoggerSetup.outputMessages(LoggerSetup.java:29)
at edu.usfca.cs272.LoggerSetup.main(LoggerSetup.java:40)
[006 FATAL] main at LoggerSetup.java:30 - Catching java.lang.RuntimeException: Falcon
at edu.usfca.cs272.LoggerSetup.outputMessages(LoggerSetup.java:30)
at edu.usfca.cs272.LoggerSetup.main(LoggerSetup.java:40)
Below are some hints that may help with this homework assignment: