I've done some more digging with mvn dependency:tree. It looks like a jar I'm importing in my pom includes logback-classic, version 1.0.9, at the compile scope. The exceptions I'm getting is likely due to it being an old version of logback-classic. Notably, the logback-classic in the jar I'm pulling in should probably have that scoped to test.
Also, I noticed that nifi-mock includes the logback-classic at version 1.2.3 for you, so it's not really even necessary to include it. I suppose the best development practice here is to logback-classic always at a test scope, knowing the nifi container will have a copy of it. Thanks, Ryan On Wed, Sep 27, 2017 at 12:50 PM, Ryan H <[email protected]> wrote: > *tl;dr:* When using TestRunner, I can only get logging to log to the > console/standard out when logback-classic is present in the test-scope. > > Is it safe to say that NiFi, when using the TestRunner, requires > logback-classic to be present in the test scope in the pom.xml? > > I've got my stuff working now, if there's any documentation on the > logging that I'm missing that might explain this, or the minimum > dependencies required type thing, I'd be interested in seeing, or > contributing some notes if not. > > Thanks, > Ryan > > Some trial/errors: > > I've tried a couple options here: > 1) slf4j-simple in pom.xml and logback-test.xml > RESULTS: No console output. Stacktrace #1 below > > 2) [logback-*core + *slf4j-api] and logback-test.xml > RESULTS: No console output. Stacktrace #1 below > > 3) [logback-*classic*] and logback-test.xml > RESULTS: Console output successful. > > 4) [logback-*classic*] alone > RESULTS: Console output successful. > > 5) Nothing in pom.xml for logging > RESULTS: No console output. Stacktrace #2 below > > Another note: > Throughout all of this, except with logback-classic, I've been seeing this > stacktrace pop-up at this line: > # TestRunner runner = TestRunners.newTestRunner(processor); > > *Stacktrace #1* > Failed to instantiate [ch.qos.logback.classic.LoggerContext] > Reported exception: > java.lang.AbstractMethodError: ch.qos.logback.classic.pattern. > EnsureExceptionHandling.process(Lch/qos/logback/core/ > Context;Lch/qos/logback/core/pattern/Converter;)V > at ch.qos.logback.core.pattern.PatternLayoutBase.start( > PatternLayoutBase.java:86) > ... > at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383) > at org.apache.nifi.util.MockProvenanceReporter.<clinit>( > MockProvenanceReporter.java:36) > at org.apache.nifi.util.SharedSessionState.<init>( > SharedSessionState.java:45) > at org.apache.nifi.util.StandardProcessorTestRunner.<init>( > StandardProcessorTestRunner.java:100) > at org.apache.nifi.util.TestRunners.newTestRunner(TestRunners.java:24) > at org.testing.processors.TestProcessor.testFile(TestProcessor.java:96) > > > *Stacktrace #2* > Failed to instantiate [ch.qos.logback.classic.LoggerContext] > Reported exception: > java.lang.NoSuchMethodError: ch.qos.logback.core.util.loader. > getResourceOccurrenceCount(Ljava/lang/String;Ljava/lang/ > ClassLoader;)Ljava/util/Set; > at ch.qos.logback.classic.util.ContextInitializer.multiplicityWarning( > ContextInitializer.java:158) > ... > at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383) > at org.apache.nifi.util.MockProvenanceReporter.<clinit>( > MockProvenanceReporter.java:36) > at org.apache.nifi.util.SharedSessionState.<init>( > SharedSessionState.java:45) > at org.apache.nifi.util.StandardProcessorTestRunner.<init>( > StandardProcessorTestRunner.java:100) > at org.apache.nifi.util.TestRunners.newTestRunner(TestRunners.java:24) > at org.testing.processors.TestProcessor.testFile(TestProcessor.java:96) > > Is it safe to say that NiFi, when using the TestRunner, requires > logback-classic to be present in the test scope? > > Thanks, > Ryan > > On Wed, Sep 27, 2017 at 11:08 AM, Bryan Bende <[email protected]> wrote: > >> I think another option is to use the simple SLF4J logger.... >> >> <dependency> >> <groupId>org.slf4j</groupId> >> <artifactId>slf4j-simple</artifactId> >> <scope>test</scope> >> </dependency> >> >> Then you probably wouldn't need the logback.xml file since you >> wouldn't be logging through logback at that point. >> >> >> On Wed, Sep 27, 2017 at 10:40 AM, Ryan H <[email protected]> >> wrote: >> > I figured it out... I was missing the logback-test.xml file (now >> included) >> > and in my pom.xml: >> > >> > I had: >> > <dependency> >> > <groupId>ch.qos.logback</groupId> >> > <artifactId>logback-core</artifactId> >> > <scope>test</scope> >> > </dependency> >> > >> > Instead I swapped to: >> > >> > <dependency> >> > <groupId>ch.qos.logback</groupId> >> > <artifactId>logback-classic</artifactId> >> > <scope>test</scope> >> > </dependency> >> > >> > And the logs are outputting now. >> > >> > Ryan >> > >> > >> > On Wed, Sep 27, 2017 at 10:20 AM, Ryan H <[email protected]> >> > wrote: >> >> >> >> Hi Andy, >> >> It's a custom processor I'm writing. I was scratching my head >> >> wondering if that is it, or adding a test dependency for logback has >> >> something to do with it. >> >> >> >> I just copy/pasted this one: >> >> https://github.com/apache/nifi/blob/d838f61291d2582592754a37 >> 314911b701c6891b/nifi-nar-bundles/nifi-framework-bundle/ >> nifi-framework/nifi-web/nifi-web-api/src/test/resources/logback-test.xml >> >> and droped it into my src/test/resources >> >> >> >> No such luck at seeing logs yet in my output yet. >> >> >> >> Ryan >> >> >> >> On Tue, Sep 26, 2017 at 5:59 PM, Andy LoPresto <[email protected]> >> >> wrote: >> >>> >> >>> Ryan, >> >>> >> >>> Which module is this running in? Some modules have a logback.xml file >> >>> defined in /src/test/resources/logback.xml which configures the test >> >>> loggers, while others do not. If this is not configured in your >> module, you >> >>> won’t see the error messages on the console. You can copy an existing >> >>> logback.xml file from one of the other modules (be sure to use one >> from the >> >>> *test* directory, not the *main* directory). >> >>> >> >>> >> >>> Andy LoPresto >> >>> [email protected] >> >>> [email protected] >> >>> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4 BACE 3C6E F65B 2F7D EF69 >> >>> >> >>> On Sep 26, 2017, at 2:51 PM, Ryan H <[email protected]> >> wrote: >> >>> >> >>> Hi, >> >>> I'm curious if there's a way to get the ComponentLog to output to >> >>> StandardOut during a Unit Test. >> >>> >> >>> I see I can access them when I call >> >>> testRunner.getLogger().getErrorMessages(), however, I'd really like >> to see a >> >>> stacktrace if it happens without having to iterate through an array >> to find >> >>> it. >> >>> >> >>> I feel like I'm just missing something obvious here, I'd appreciate >> >>> any advice. >> >>> >> >>> Thanks, >> >>> Ryan >> >>> >> >>> >> >> >> > >> > >
