Complete the code to create a Logger instance for the class.
private static final Logger logger = Logger[1](LoggingExample.class);
The Logger.getLogger(ClassName.class) method creates a Logger instance for the given class.
Complete the code to log an info message using Log4j.
logger.[1]("Test started successfully.");
The info method logs informational messages that highlight the progress of the application.
Fix the error in the code to log an error message with an exception.
try { int result = 10 / 0; } catch (ArithmeticException e) { logger.[1]("Division by zero error", e); }
The error method is used to log error messages along with exceptions.
Fill both blanks to configure Log4j to log messages at debug level and above.
BasicConfigurator.[1](); Logger.getRootLogger().setLevel(Level.[2]);
BasicConfigurator.configure() sets up a basic configuration for Log4j.
Level.DEBUG sets the logging level to debug and above.
Fill all three blanks to create a logger, log a warning, and set the logger level to WARN.
Logger [1] = Logger.[2](MyTest.class); [1].warn("This is a warning message."); [1].setLevel(Level.[3]);
First, create a Logger instance named logger using Logger.getLogger().
Then log a warning with warn().
Finally, set the level to Level.WARN to log warnings and above.