Details
Description
When running integration tests with logging configured, there is no logging output neither on the console, in configured file nor junit reports.
As I can understand, problem originates from _GrailsTest script, which first includes both _GrailsBootstrap (which includes _GrailsPackage), and after it, _GrailsWar. _GrailsPackage and _GrailsWar both have startLogging target, but the one in _GrailsWar does nothing since it is empty. Unfortunately, it overrides startLogging from _GrailsPackage. All this result with missing logging output.
There is a hacky workaround which will output logging statements to configured appenders, but not in junit reports. To enable it, modification of integrationTestPhasePreparation closure from _GrailsTest is needed. Basically, at the end of it, you can paste code from _GrailsPackage's startLogging target:
import org.apache.log4j.LogManager import org.codehaus.groovy.grails.plugins.logging.Log4jConfig ... integrationTestPhasePreparation = { ... LogManager.resetConfiguration() if (config.log4j instanceof Closure) { profile("configuring log4j") { new Log4jConfig().configure(config.log4j) } } else { // setup default logging new Log4jConfig().configure() } }
I'm not sure if this will mess up something else, but at least I've got logging working.
Issue Links
- is duplicated by
-
GRAILS-7067
grails doing a NOP intercept of my expclicit logging during test-app -unit or test-app -integration
-
Another workaround is to copy the startLogging target from _GrailsPackage.groovy to TestApp.groovy.
I.e. add this code to the end of TestApp.groovy:
target(startLogging:"Bootstraps logging") { LogManager.resetConfiguration() if (config.log4j instanceof Closure) { profile("configuring log4j") { new Log4jConfig().configure(config.log4j) } } else { // setup default logging new Log4jConfig().configure() } }Note that the order of includeTargets statements in TestApp.groovy seems to imply that the _GrailsPackage.groovy script will be loaded last, making its copy of startLogging dominant. However, _GrailsPackage.groovy has guard code that prevents it from being loaded twice, so the includeTargets at the top of RunTest.groovy has no effect.