title: How to use log4j more efficiently in selenium webdriver testing framework
body: <p>I am working on a self learning project of selenium webdriver and using log4j for logging purpose.
  There is a test class - contains all the test cases as methods
  There is a page class - contains all the web elements and methods that can be used by test class</p>
  
  <p>How should I work with log4j?
  Test Class:</p>
  
  <pre><code>public class ConfiguringPropertiesFile {
      private WebDriver driver;
      private String baseUrl;
      static Logger log = Logger.getLogger(ConfiguringPropertiesFile.class);
  
  @Before
  public void setUp() throws Exception {
      driver = new FirefoxDriver();
      baseUrl = "https://www.some-website.com/";
  
      // Maximize the browser's window
      driver.manage().window().maximize();
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  }
  
  @Test
  public void test() {
      PropertyConfigurator.configure("log4j.properties");
      driver.get(baseUrl);
      SearchPage.navigateToFlightsTab(driver);
      log.info("Navigate to flights tab");
      SearchPage.fillOriginTextBox(driver, "New York");
      SearchPage.destinationTextBox(driver).sendKeys("Chicago");
      log.info("Enter destination city");
      SearchPage.departureDateTextBox(driver).sendKeys("12/25/2014");
      log.info("Enter departure date");
      SearchPage.returnDateTextBox(driver).sendKeys("12/31/2014");
      log.info("Enter return date");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Page Class:</p>
  
  <pre><code>public class SearchPage {
  public static WebElement element = null;
  static Logger log1 = Logger.getLogger(SearchPage.class);
  
  /**
   * Returns the flight origin text box element
   * @param driver
   * @return
   */
  public static WebElement originTextBox(WebDriver driver) {
      element = driver.findElement(By.id("flight-origin"));
      return element;
  }
  
  public static void fillOriginTextBox(WebDriver driver, String origin) {
      PropertyConfigurator.configure("log4j.properties");
      element = originTextBox(driver);
      element.sendKeys(origin);
      log1.info("Entering the source city as " + origin);
  }
  
  /**
   * Returns the flight destination text box element
   * @param driver
   * @return
   */
  public static WebElement destinationTextBox(WebDriver driver) {
      element = driver.findElement(By.id("flight-destination"));
      return element;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>In this situation, I am initializing log4j in both the classes and then the big issue is I have to call the PropertyConfigurator in each method.</p>
  
  <p>How can I initialize it in better way and do not have to call PropertyConfigurator everytime?</p>