add these 2 statement
[quote:8yop55n7]BasicConfigurator.configure();
Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");
[/quote:8yop55n7]
Sir, i put 2 statements as per following code:
Issue:Still no logging in log file...
package com.qtpselenium.suiteA;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
public class CustomListener extends TestListenerAdapter implements IInvokedMethodListener{
Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");
@Override
public void onTestFailure(ITestResult tr)
{
BasicConfigurator.configure();
//TestBase.APP_LOGS.debug("Failure");
APPLICATION_LOGS.debug("Failure");
}
@Override
public void onTestSkipped(ITestResult tr)
{BasicConfigurator.configure();
//TestBase.APP_LOGS.debug("TestSkipped");
APPLICATION_LOGS.debug("TestSkipped");
}
@Override
public void onTestSuccess(ITestResult tr)
{BasicConfigurator.configure();
//TestBase.APP_LOGS.debug("Succes");
System.out.println("SUCCCCCCCCCCCCCCCCCCCCESSSSSSSSSSSSSSSSSSSSSSSSSS");
APPLICATION_LOGS.debug("SUCCCCCCCCCCCCCCCCCCCCESSSSSSSSSSSSSSSSSSSSSSSSSS");
}
public void afterInvocation(IInvokedMethod method, ITestResult result){
}
public void beforeInvocation(IInvokedMethod method, ITestResult result){
}
}
below is the screen shot of structure of files in a project.
use this code
[code:2g22ypn1] public static void main(String[] args) {
Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");
APPLICATION_LOGS.debug("hello");
APPLICATION_LOGS.debug("We are wrinting in to a log file");
APPLICATION_LOGS.debug("starting the test case xyz test");
}
[/code:2g22ypn1]
use this properties file
[code:2g22ypn1]#Application Logs
log4j.logger.devpinoyLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=5000KB
log4j.appender.dest1.maxBackupIndex=3
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=C:\\testing\\Application.log
#do not append the old file. Create a new log file everytime
log4j.appender.dest1.Append=false
[/code:2g22ypn1]
---------Sir am trying to log data when a test is skipped...Its not working that way sir....
Works sir , if i use it in main by creating a different class like dis:
package com.qtpselenium.suiteA;
import org.apache.log4j.Logger;
public class A {
Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");
public static void main(String[] args) {
// TODO Auto-generated method stub
Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");
APPLICATION_LOGS.debug("hello");
APPLICATION_LOGS.debug("We are wrinting in to a log file");
APPLICATION_LOGS.debug("starting the test case xyz test");
}
}
========================================================
It does not work if class is like this://
package com.qtpselenium.suiteA;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
public class CustomListener extends TestListenerAdapter implements IInvokedMethodListener{
Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");
@Override
public void onTestSkipped(ITestResult tr)
{BasicConfigurator.configure();
//TestBase.APP_LOGS.debug("TestSkipped");
APPLICATION_LOGS.debug("TestSkipped");
Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");
APPLICATION_LOGS.debug("hello");
APPLICATION_LOGS.debug("We are wrinting in to a log file");
APPLICATION_LOGS.debug("starting the test case xyz test");
}
}