RE: log4j writes numerous log entries

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

RE: log4j writes numerous log entries

Edmondson, David


From: Edmondson, David
Sent: Monday, April 03, 2017 3:41 PM
To: '[hidden email]' <[hidden email]>
Subject: log4j writes numerous log entries


To whom it may concern,


I am using Selenium with TestNG to run automated tests and log4j v1.2 to write log files…


TestNG has an @Test and an @DataProvider annotation feature that allows me to pass parameters saved in an Excel file to my test method…


When I only have one row in my Excel worksheet, the test method only runs once and log4j code in the test method writes to my log file properly…


When I have two or more rows in my Excel worksheet, the test method runs multiple times, once for each row in the Excel worksheet…


Unfortunately, on the second run, every log entry is duplicated…

On the third run, every log entry is triplicated…

On the fourth run, every log entry is quadruplicated, and so on…


How do I cause log4j to avoid this issue?


See attached log file…


The material section of java code involved in the issue is below…



       public void CCRwitheTranscript(String recipient, String email, String fileattachment, String fileattachmenttype) throws InterruptedException, FileNotFoundException




       //Console and File Logging using log4j

       //Creates Pattern Layout

        PatternLayout layout = new PatternLayout();

        String conversionPattern = "%d %-7p [%t] %c %x - %m%n";



        //Creates Console Appender

        ConsoleAppender consoleAppender = new ConsoleAppender();




        //Creates Daily Rolling File Appender - User configurable to minutely (yyyy-MM-dd-HH-mm)...

        DailyRollingFileAppender rollingFileAppender = new DailyRollingFileAppender();






        //Configures Root Logger

        Logger rootLogger = Logger.getRootLogger();

        rootLogger.setLevel(Level.INFO);  //The level value (ALL; TRACE; DEBUG; INFO; WARN; ERROR; FATAL) determines which logger messages will be written to the log file




        // creates a custom logger and log messages

        Logger logger = Logger.getLogger(DDT.ParchmentCCRwitheTranscriptExcel.class);


        logger.trace("this is a trace log message");

        logger.debug("this is a debug log message");"this is an information log message");

        logger.warn("this is a warning log message");

        logger.error("this is a error log message");

        logger.fatal("this is a fatal log message");"-----");


        //Internet Explorer WebDriver

       System.setProperty("", "C:\\temp\\Selenium\\IEDriverServer.exe");

       WebDriver driver = new InternetExplorerDriver();


       //Console Data Spacer"-----");


        //Print Current Class Name"Class Name via logger: " + Thread.currentThread().getStackTrace()[1].getClassName());


       //Print Current Method Name"Method Name via logger: " + Thread.currentThread().getStackTrace()[1].getMethodName());


       //Print Browser SessionID"Session ID via logger: " + ((RemoteWebDriver)driver).getSessionId().toString());

"Home Page");"Home Page Title Verified - User is able to login successfully!");

            "Co-Curricular Record with eTranscript Page");

            "Co-Curricular Record with eTranscript Page Title Verified!");


                 logger.error("Checkout button is missing on Shopping Cart Page!");


 logger.error("I Accept checkbox is missing on Consent Page!");              


  logger.error("Confirm button is missing on Review Order Page!");


  logger.error("Home link is missing on Thank You Page!");


       //Close Chrome or IE Browsers







       public Object[][] passData()


              ExcelDataConfig config=new ExcelDataConfig("C:\\Users\\dkedmondson\\workspace\\ParchmentTestData.xlsx");


              //In order to change the sheet where the "Co-Curricular Record with eTranscript" data is located

              String sheetname="CCR with eTranscript";


              int sheet=config.getSheetIndex(sheetname);

              String workbookname=config.getWorkbookName();

              String workbookpath=config.getWorkbookPath();


              int rows=config.getRowCount(sheetname);

              int columns=config.getColumnCount(sheetname);

              int sheets=config.getSheetCount();


              Object[][] data=new Object[rows-1][columns];  //Defining data=new Object[rows-1][columns], in order to save only data rows in the Excel worksheet


              for(int i=1; i<rows; i++)  //Initializing i=1, in order to save only data rows in the Excel worksheet



                     for (int j=0; j<columns; j++)



                     data[i-1][j]=config.getData(sheetname, i, j);  //Saving as data[i-1][j], in order to save only data rows in the Excel worksheet





              return data;







David Edmondson

QA Lead for UCSD, UCPath

ACT Financial & Administrative Systems

University of California - San Diego

Torrey Pines Center South – Room #255

Mail Code - 0929

(858) 822-0517