Re: [selenium-users] Logs in Selenium using log4j for each test case

64 views
Skip to first unread message
Message has been deleted

⇜Krishnan Mahadevan⇝

unread,
Sep 9, 2016, 12:52:08 AM9/9/16
to Selenium Users
Pavan,
How is this question related to Selenium ? This is more of a logging related query. So I would suggest that you please post this on a general forum such as StackOverFlow.

Please help keep this forum relevant by posting queries that are ONLY related to Selenium/WebDriver.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Fri, Sep 9, 2016 at 9:19 AM, pavankumar abvg <pavanku...@gmail.com> wrote:
Here is my requirement:

For each test case i want to create a log file. I tried the below approach, but still separate log files are not getting created.
For first run, manual.logs is getting created and all logs are written
For second run, the log file with last executed test case(in first run) is getting created and all logs are written to that file

Here are the steps followed.

    A properties file 'log4j.properties' is created.
    In WebDriverEventListener class, i have given Logger log = Logger.getLogger("devpinoyLogger")
    In BeforeMethod, I am getting method name and updating the log4j.properties file as below

    @BeforeMethod
    public void setUPSuper(char vBrowserType, String vAppURL, Method method){
            try{
                String strTCName = method.getName();
                setLogFileName(strTCName); 
                setDriver(vBrowserType, vAppURL);         
            }catch(Exception e){
                System.out.println("Exception occured : " + e.toString());
            }
         
        }

    public void setLogFileName(String fValue){
            String pValue = "E:\\Java\\Logs\\" + fValue + ".logs";
            try{
                PropertiesConfiguration config = new PropertiesConfiguration("E:\\Java\\src\\log4j.properties");
                config.setProperty("log4j.appender.dest1.File", pValue);
                config.save();
            }catch(Exception e){
                System.out.println(e.toString());
            }
            /*try{         
                FileInputStream fis = new FileInputStream("E:\\Java\\src\\log4j.properties");
                Properties p = new Properties();
                p.load(fis);
                fis.close();
             
                FileOutputStream fos = new FileOutputStream("E:\\Java\\src\\log4j.properties");                     
                p.setProperty("log4j.appender.dest1.File", pValue);
                p.store(fos, null);
                fos.close();
            }catch(Exception e){
                System.out.println(e.toString());
            }*/
        }


#Root logger

log4j.rootLogger=DEBUG,file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=E:\\Java\\Logs\\Selenium.logs
log4j.appender.file.maxFileSize=900KB
log4j.appender.file.maxBackupIndex=5
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c<strong>{1}<\/strong>:%L - %m%n
log4j.appender.file.Append=false

#Application Logs

log4j.logger.devpinoyLogger=DEBUG,dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=900KB
log4j.appender.dest1.maxBackupIndex=6
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd\/MM\/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.File=E:\\Java\\Logs\\Manual.logs
log4j.appender.dest1.Append=false

Thanks,
Pavankumar

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/c38e7d50-49bf-4397-b0bb-f654db9a6f00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pavankumar abvg

unread,
Sep 10, 2016, 9:05:26 PM9/10/16
to Selenium Users
Thanks Krishna for the suggestion. Will do the same.

Reply all
Reply to author
Forward
0 new messages