spockframework / spockframework/spock
Unable to log in the 'stop' method of GlobalExtension
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 483
- PR merge metrics
- No merged PRs in 30d
Description
Hi.
Please consider this extension:
import groovy.util.logging.Slf4j
import org.spockframework.runtime.extension.AbstractGlobalExtension
@Slf4j
class LogExtension extends AbstractGlobalExtension {
@Override
void start() {
log.info "I'm always logged"
}
@Override
void stop() {
log.info "I'm logged sometimes"
sleep(1000)
log.info "I'm never logged"
}
}
Problem:
The logging inside the 'stop' method is kind of broken. There seems to be some race condition, since the first log message in 'stop' will sometimes get logged (once in about 3 runs on my local machine), but any subsequent logs will never get logged. In debug inside 'stop', the 'log' instance reads PrivateConfig [loggerConfig=root, config=org.apache.logging.log4j.core.config.NullConfiguration@186eca4d, loggerConfigLevel=OFF, intLevel=0, logger=org.openkilda.functionaltests.extension.LogExtension:OFF in ffaa6af], which is different from what I get in the start or visitSpec methods (it reads a valid config and non-OFF log level). Problem also reproduces if I create the logger directly, without using the @Slf4j transformation.
I'm configuring logger via log4j2.xml config which is located under src/test/resources. All other logs across all my framework do work as expected.
Can somebody please point me to the reason of such behavior? How can I fix this? I want to perform some logging at the end of the test run.
Spock version is 1.2-groovy-2.5, Groovy 2.5.3, log4j-slf4j-impl 2.10.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the LogExtension example using AbstractGlobalExtension.start() and stop(), with the stated Spock, Groovy, and log4j configuration. Trace the global extension shutdown lifecycle and logging configuration teardown; done means logging from stop() consistently uses the configured logger and preserves messages at the end of the test run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100