You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by Jean-Claude Cote <jc...@gmail.com> on 2018/10/12 12:52:23 UTC

configure logback to trace level in junit tests

I'm trying to output trace information in my junit test cases. I'm using
the ClusterFixture

startCluster(ClusterFixture.builder(dirTestWatcher).maxParallelization(1));

I've put my logback.xml in src/test/resources

and feed in these environment variables at the command mvn launch.

mvn --offline clean install -Dlog.path=/tmp/sqlline.log
-Dlog.query.path=/tmp/sqlline_queries.json

But no output files are created. How can I accomplish this?

Thank you
jc

Re: configure logback to trace level in junit tests

Posted by Jean-Claude Cote <jc...@gmail.com>.
Yes I want to debug a junit test case I have. Thanks Paul and Vitalii.

On Fri, Oct 12, 2018 at 2:28 PM Paul Rogers <pa...@yahoo.com.invalid>
wrote:

> Hi JC,
>
> Your are asking how to use logs with unit tests. Let's talk about the two
> ways you might be using logging, because each has a different answer.
>
> In general, a unit test should use JUnit assert calls to verify that
> behavior is as expected. No-one ever looks at output from tests unless a
> test fails. We have some old tests that "test" by dumping stuff to the
> console or a log. But, that is not much of a test at all since we have no
> mechanism to verify that output.
>
> On the other hand, you might want to enable logging for help in debugging.
> For example, I use unit tests to debug my code and enable detailed logging
> when things go wrong.
>
> To do this, you can use the LogFixture class to enable logging for a
> specific test for a particular module. Thanks much to Vitalii for providing
> the links. You can also check out the ExampleTest class for a concrete
> example of how to use the various fixtures.
>
> The main reason for the log fixture is that Maven Surefire runs tests in a
> shared JVM: when using logback.xml, you can't set the log level for one
> test without setting the log level for all tests.
>
> The log fixture works around that by mucking with the LogBack config at
> runtime to turn on logging exactly when you want it, then turn it off again
> afterwards so that other tests run at the original log level.
>
> I hope this helps...
>
> Thanks,
> - Paul
>
>
>
>     On Friday, October 12, 2018, 10:11:44 AM PDT, Vitalii Diravka <
> vitalii@apache.org> wrote:
>
>  Hi Jean-Claude!
>
> You should use logback-test.xml for tests.
> Paul has documented it very well in [1] and [2].
>
> [1]
>
> https://github.com/apache/drill/blob/master/docs/dev/TestLogging.md#default-test-log-levels
> [2]
>
> https://github.com/apache/drill/blob/master/docs/dev/ClusterFixture.md#controlling-logging
>
> On Fri, Oct 12, 2018 at 3:52 PM Jean-Claude Cote <jc...@gmail.com> wrote:
>
> > I'm trying to output trace information in my junit test cases. I'm using
> > the ClusterFixture
> >
> >
> startCluster(ClusterFixture.builder(dirTestWatcher).maxParallelization(1));
> >
> > I've put my logback.xml in src/test/resources
> >
> > and feed in these environment variables at the command mvn launch.
> >
> > mvn --offline clean install -Dlog.path=/tmp/sqlline.log
> > -Dlog.query.path=/tmp/sqlline_queries.json
> >
> > But no output files are created. How can I accomplish this?
> >
> > Thank you
> > jc
> >
>

Re: configure logback to trace level in junit tests

Posted by Paul Rogers <pa...@yahoo.com.INVALID>.
Hi JC,

Your are asking how to use logs with unit tests. Let's talk about the two ways you might be using logging, because each has a different answer.

In general, a unit test should use JUnit assert calls to verify that behavior is as expected. No-one ever looks at output from tests unless a test fails. We have some old tests that "test" by dumping stuff to the console or a log. But, that is not much of a test at all since we have no mechanism to verify that output.

On the other hand, you might want to enable logging for help in debugging. For example, I use unit tests to debug my code and enable detailed logging when things go wrong.

To do this, you can use the LogFixture class to enable logging for a specific test for a particular module. Thanks much to Vitalii for providing the links. You can also check out the ExampleTest class for a concrete example of how to use the various fixtures.

The main reason for the log fixture is that Maven Surefire runs tests in a shared JVM: when using logback.xml, you can't set the log level for one test without setting the log level for all tests.

The log fixture works around that by mucking with the LogBack config at runtime to turn on logging exactly when you want it, then turn it off again afterwards so that other tests run at the original log level.

I hope this helps...

Thanks,
- Paul

 

    On Friday, October 12, 2018, 10:11:44 AM PDT, Vitalii Diravka <vi...@apache.org> wrote:  
 
 Hi Jean-Claude!

You should use logback-test.xml for tests.
Paul has documented it very well in [1] and [2].

[1]
https://github.com/apache/drill/blob/master/docs/dev/TestLogging.md#default-test-log-levels
[2]
https://github.com/apache/drill/blob/master/docs/dev/ClusterFixture.md#controlling-logging

On Fri, Oct 12, 2018 at 3:52 PM Jean-Claude Cote <jc...@gmail.com> wrote:

> I'm trying to output trace information in my junit test cases. I'm using
> the ClusterFixture
>
> startCluster(ClusterFixture.builder(dirTestWatcher).maxParallelization(1));
>
> I've put my logback.xml in src/test/resources
>
> and feed in these environment variables at the command mvn launch.
>
> mvn --offline clean install -Dlog.path=/tmp/sqlline.log
> -Dlog.query.path=/tmp/sqlline_queries.json
>
> But no output files are created. How can I accomplish this?
>
> Thank you
> jc
>
  

Re: configure logback to trace level in junit tests

Posted by Vitalii Diravka <vi...@apache.org>.
Hi Jean-Claude!

You should use logback-test.xml for tests.
Paul has documented it very well in [1] and [2].

[1]
https://github.com/apache/drill/blob/master/docs/dev/TestLogging.md#default-test-log-levels
[2]
https://github.com/apache/drill/blob/master/docs/dev/ClusterFixture.md#controlling-logging

On Fri, Oct 12, 2018 at 3:52 PM Jean-Claude Cote <jc...@gmail.com> wrote:

> I'm trying to output trace information in my junit test cases. I'm using
> the ClusterFixture
>
> startCluster(ClusterFixture.builder(dirTestWatcher).maxParallelization(1));
>
> I've put my logback.xml in src/test/resources
>
> and feed in these environment variables at the command mvn launch.
>
> mvn --offline clean install -Dlog.path=/tmp/sqlline.log
> -Dlog.query.path=/tmp/sqlline_queries.json
>
> But no output files are created. How can I accomplish this?
>
> Thank you
> jc
>