'Log4j2 Logs are not printed neither on the console or in the RollingFile when executed on Jenkins or in Command line

I pushed my automation framework to Github and integrated it with Jenkins. I used Log4j2 to capture the logs in the runtime. This works perfectly fine when I run in Eclipse but when I try to run the code from Command line or from Jenkins, Logs are not printed either on the console or on the Log file

My log4j2.xml is as following,

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Property name="logDir">logs</Property>
    <RollingFile name="RollingFile" fileName="${logDir}/app.log"
            <Pattern>%d{dd:mm:yyy HH:mm:ss.SSS} %p %c{2} [%t] - %m%n</Pattern>
            <SizeBasedTriggeringPolicy size="20MB" />
    <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout  pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n" />
    <Logger name ="com.trifacta.stepDefinition" level="trace" additivity="true">
        <AppenderRef ref="Console"/>
    <Logger name ="com.trifacta.stepDefinition" level="trace" additivity="true">
        <AppenderRef ref="RollingFile"/>
    <Root level="trace">
        <AppenderRef ref="Console" />
</Loggers> </Configuration>

Class file is as below,

    package com.trifacta.stepDefinition;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;

import com.trifacta.pageObjects.Google;
import com.trifacta.utilities.BaseClass;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;

public class GoogleSearch extends BaseClass {
    Google go;
    Logger log = (Logger) LogManager.getLogger(GoogleSearch.class.getName());

    @Given("^user launches google$")
    public void user_launches_google() {
      log.info("Google is launched successfully");

    @Then("^Enters \"([^\"]*)\" in search bar$")
    public void enters_in_search_bar(String value) {
        go = new Google();
        log.info("Search value is provided");

    @Then("^Clicks enter$")
    public void clicks_enter() throws InterruptedException {
        log.info("Search Results are obtained");

Feature file

Feature: Launch Google

Scenario: Launch Google in browser

Given user launches google
Then Enters "Selenium" in search bar
Then Clicks enter


package com.trifacta.pageObjects;

import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import com.trifacta.utilities.BaseClass;

public class Google extends BaseClass {

    @FindBy(xpath = "//input[@class='gLFyf gsfi']")
    WebElement SearchBar;
    public Google() {
        PageFactory.initElements(driver, this);
    public void txtSearchBar(String text) {

    public void hitEnter() {

enter image description here

When I run this in eclipse logs are captured without any error, but when I run this in Jenkins or Command line logs are not captured. Can you please help me in getting this fix?


This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source