logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Edmondson, David" <dkedmond...@ucsd.edu>
Subject RE: log4j writes numerous log entries
Date Mon, 03 Apr 2017 23:19:33 GMT

From: Edmondson, David
Sent: Monday, April 03, 2017 3:41 PM
To: 'log4net-user@logging.apache.org' <log4net-user@logging.apache.org>
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...

       @Test(dataProvider="parchmentData")
       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";
        layout.setConversionPattern(conversionPattern);

        //Creates Console Appender
        ConsoleAppender consoleAppender = new ConsoleAppender();
        consoleAppender.setLayout(layout);
        consoleAppender.activateOptions();

        //Creates Daily Rolling File Appender - User configurable to minutely (yyyy-MM-dd-HH-mm)...
        DailyRollingFileAppender rollingFileAppender = new DailyRollingFileAppender();
        rollingFileAppender.setFile("CCRwitheTranscript.log");
        rollingFileAppender.setDatePattern("'.'yyyy-MM-dd-HH'.log'");
        rollingFileAppender.setLayout(layout);
        rollingFileAppender.activateOptions();

        //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
        rootLogger.addAppender(consoleAppender);
        rootLogger.addAppender(rollingFileAppender);

        // creates a custom logger and log messages
        Logger logger = Logger.getLogger(DDT.ParchmentCCRwitheTranscriptExcel.class);
        //logger.setAdditivity(false);
        logger.trace("this is a trace log message");
        logger.debug("this is a debug log message");
        logger.info("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");
        logger.info("-----");

        //Internet Explorer WebDriver
       System.setProperty("webdriver.ie.driver", "C:\\temp\\Selenium\\IEDriverServer.exe");
       WebDriver driver = new InternetExplorerDriver();

       //Console Data Spacer
       logger.info("-----");

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

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

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

       logger.info("Home Page");
       logger.info("Home Page Title Verified - User is able to login successfully!");

       logger.info("Co-Curricular Record with eTranscript Page");

       logger.info("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
       driver.close();

}


       @DataProvider(name="parchmentData")
       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;

}

Regards,

[UCSanDiego_LogoLINIGR_2767]
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
www.ucsd.edu<http://www.ucsd.edu/>


Mime
View raw message