3

When I execute the build script with gradle all the test cases are working fine. But I configured the log4j logging as well and unfortunately it's not displaying in the console.

log4j.properties:

# Log levels
# Uncomment the following line to enable full loggin for every class
#log4j.rootLogger=trace, stdout, R
log4j.rootLogger=info, stdout, R

# Console appender configuration
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout=org.springframework.boot
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

# Rolling File Appender
log4j.appender.R=org.apache.log4j.RollingFileAppender
# Path and file name to store the log file.
log4j.appender.R.File=./logs/applog.log
log4j.appender.R.MaxFileSize=500KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
# Rolling File Appender layout
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d - %c - %p - %m%n

build.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'

version = "1.0"
sourceCompatibility = 1.7

jar {
    manifest {
        attributes 'Implementation-Title': 'com.prokarma.automation.sample', 'Implementation-   
        Version': version   
    }
}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'org.gradle.api.plugins:gradle-cargo-plugin:0.6'
    }
 }

 repositories { 
     mavenCentral() 
 }  

 sourceSets {
     unitTest {
         java.srcDir file('src/test/java')
         resources.srcDir file('src/test/resources')
     }
 }

 task wrapper(type: Wrapper) {
     description = 'Install Gradle wrapper'
     gradleVersion = '1.10'
 }

 dependencies {

     compile 'org.apache.poi:poi:3.5-beta5'
     compile 'org.testng:testng:6.8.5'
     compile 'log4j:log4j:1.2.17'
     compile 'org.seleniumhq.selenium:selenium-server:2.39.0'
     compile 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.39.0'
     compile 'com.googlecode.json-simple:json-simple:1.1'
     compile 'net.sf.json-lib:json-lib:2.4:jdk15'   
     testRuntime 'log4j:log4j:1.2.17'       
}

test { 
    useTestNG() {  
        options.suites("src/test/resources/testng.xml")
    }
}

uploadArchives {
    repositories {
    flatDir {
           dirs 'repos'
    }
}
}

output:

[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks: 
[sts]      clean
[sts]      test
[sts] -----------------------------------------------------
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava
:processTestResources
:testClasses
:test

 BUILD SUCCESSFUL

 Total time: 2.242 secs
 [sts] -----------------------------------------------------
 [sts] Build finished succesfully!
 [sts] Time taken: 0 min, 2 sec
 [sts] -----------------------------------------------------

But log4j logs is not displayed. anyone can u given a solutions for this?

divanov
  • 6,173
  • 3
  • 32
  • 51
saravanakumar
  • 49
  • 3
  • 8

1 Answers1

2

You can set test.testLogging.showStandardStreams to true. This will make the logging output appear both on the command line and in test reports as stated in the Gradle documentation:

// show standard out and standard error of the test JVM(s) on the console testLogging.showStandardStreams = true

Andreas Schmid
  • 1,195
  • 8
  • 13