0
0
Selenium Javatesting~20 mins

Logging with Log4j in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Log4j2 Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Log4j Basic Configuration Output
Given this Log4j2 configuration snippet, what will be the output when the logger logs an info message?

<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss} %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="info">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>
Selenium Java
Logger logger = LogManager.getLogger("MyLogger");
logger.info("Test message");
AA console output like: "14:30:15 INFO MyLogger - Test message"
BA console output like: "14:30:15 DEBUG MyLogger - Test message"
CNo output because the level is set to WARN
DAn error occurs because the pattern layout is invalid
Attempts:
2 left
💡 Hint
Check the root logger level and the message level.
Troubleshoot
intermediate
2:00remaining
Log4j2 Logger Not Printing Messages
You have this Java code snippet using Log4j2:

Logger logger = LogManager.getLogger(MyClass.class);
logger.debug("Debug message");

The log file remains empty after running the program. What is the most likely cause?
AThe logger level is set higher than DEBUG, so debug messages are ignored
BThe logger name is incorrect and does not match the configuration
CThe log file path is missing in the configuration
DThe logger instance was not created with LogManager
Attempts:
2 left
💡 Hint
Check the configured log level and the message level.
Configuration
advanced
2:30remaining
Log4j2 Rolling File Appender Configuration
Which Log4j2 XML configuration snippet correctly sets up a rolling file appender that rolls over daily and keeps 7 days of logs?
A
&lt;Appenders&gt;
  &lt;RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%i.log.gz"&gt;
    &lt;PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/&gt;
    &lt;Policies&gt;
      &lt;SizeBasedTriggeringPolicy size="10MB"/&gt;
    &lt;/Policies&gt;
    &lt;DefaultRolloverStrategy max="7"/&gt;
  &lt;/RollingFile&gt;
&lt;/Appenders&gt;
B
&lt;Appenders&gt;
  &lt;RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd}.log.gz"&gt;
    &lt;PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/&gt;
    &lt;Policies&gt;
      &lt;TimeBasedTriggeringPolicy interval="1"/&gt;
    &lt;/Policies&gt;
    &lt;DefaultRolloverStrategy max="7"/&gt;
  &lt;/RollingFile&gt;
&lt;/Appenders&gt;
C
&lt;Appenders&gt;
  &lt;File name="File" fileName="logs/app.log"&gt;
    &lt;PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/&gt;
  &lt;/File&gt;
&lt;/Appenders&gt;
D
&lt;Appenders&gt;
  &lt;RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{MM-dd-yyyy}.log"&gt;
    &lt;PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/&gt;
    &lt;Policies&gt;
      &lt;TimeBasedTriggeringPolicy interval="7"/&gt;
    &lt;/Policies&gt;
    &lt;DefaultRolloverStrategy max="30"/&gt;
  &lt;/RollingFile&gt;
&lt;/Appenders&gt;
Attempts:
2 left
💡 Hint
Look for daily rollover and max 7 files retention.
🔀 Workflow
advanced
2:00remaining
Integrating Log4j2 with Selenium Tests
You want to add Log4j2 logging to your Selenium Java tests to log browser actions. Which step is NOT required in the integration workflow?
AAdd Log4j2 dependencies to your project build file (e.g., pom.xml or build.gradle)
BCreate a Log4j2 configuration file (log4j2.xml) in the resources directory
CReplace all Selenium WebDriver calls with Log4j2 API calls
DCreate a Logger instance in your test classes and add logging statements
Attempts:
2 left
💡 Hint
Consider what logging does versus what Selenium does.
Best Practice
expert
3:00remaining
Best Practice for Sensitive Data in Log4j2 Logs
Which is the best practice to avoid logging sensitive data (like passwords) in Log4j2 logs during automated tests?
AStore sensitive data in plain text in logs but encrypt the log files on disk
BLog all data and delete log files manually after tests
CDisable logging completely during tests to avoid sensitive data exposure
DUse a custom log filter to mask or exclude sensitive data before logging
Attempts:
2 left
💡 Hint
Think about controlling what gets logged rather than deleting logs later.