Automation QA Testing Course Content

log4J.properties

log4j is used for logging in the automation

log4j is used for logging the information to log files
Five main type of log statements
1)trace
2)debug
3)info
4)error
5)fatal

log.error -->Conditions like element not found or not clicked
log.debug/log.info -->On Selenium WebDriver actions like click(), sendKeys()
log.info -->On Successful actions like page load, other verifications 

log4j.xml file content

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Properties>
        <Property name="basePath">./logs</Property>
    </Properties>
    <Appenders>
        <RollingFile name="File" fileName="${basePath}/app.log" filePattern="${basePath}/app-%d{yyyy-MM-dd-HHmmss}.log">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %c{2} -%msg%n"/>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
                <SizeBasedTriggeringPolicy size="100 KB"/>
            </Policies>
        </RollingFile>
        <Console name="Console">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %c{1} -%msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="trace">
            <AppenderRef ref="File"/>
        </Root>
        <!--<Logger name="com.hybridframework.overview" level="info" additivity="false">
            <AppenderRef ref="File"/>
        </Logger>-->
    </Loggers>
</Configuration>
-------------------------------------------------------------------------------------------------------
log4j.properties
------------------------------------------------------------------------------------------------------------
#Define root logger options
log4j.rootLogger=DEBUG, file, console

#Define rolling file appender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=selenium.log
log4j.appender.file.Append=false
log4j.appender.file.ImmediateFlush=true
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

#Define console appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
#logrj.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

#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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.dest1.File=application.log
log4j.appender.dest1.Append=false

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.