3 Replies Latest reply on Feb 6, 2013 11:17 AM by Tito ..

    Arquillian as7 slf4j debug doesn't work

    Tito .. Newbie

      Hi,

      I am developing a little project and I am testing rest services with Arquillian.

       

      My test class is like this:

       

      @RunWith(Arquillian.class)

      @RunAsClient

      public class CustomerResourceRESTEasyClientTest {

          private static final String RESOURCE_PREFIX = JaxRsActivator.class.getAnnotation(ApplicationPath.class).value().substring(1);

       

       

          @Deployment(testable = false)

          public static WebArchive createDeployment() {

              return ShrinkWrap.create(WebArchive.class, "test.war").addPackages(true, "org.yukka.bloggo")

                      .addAsResource("test-persistence.xml", "META-INF/persistence.xml")

                      .addAsWebInfResource(EmptyAsset.INSTANCE, "log4j.xml");

          }

       

       

          @ArquillianResource

          URL deploymentUrl;

       

          @BeforeClass

          public static void initResteasyClient() {

              RegisterBuiltin.register(ResteasyProviderFactory.getInstance());

          }

       

          @Test

          public void testInsertPost() throws Exception {

              PostRestService client = ProxyFactory.create(PostRestService.class, deploymentUrl.toString() + RESOURCE_PREFIX);

              Post post = new Post("title","content",new Date(System.currentTimeMillis()),new User("username","email"),new Blog(1L));

              Response response = client.insert(post);

              assertEquals(response,Response.ok().build());

          }

       

       

      log4j.xml:

       

      <?xml version="1.0" encoding="UTF-8" ?>

      <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

      <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

       

       

          <appender name="yukkaconsole" class="org.apache.log4j.ConsoleAppender">

              <layout class="org.apache.log4j.PatternLayout">

                  <!-- Print the date in ISO 8601 format -->

                  <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p [%C:%L] - %m%n"/>

              </layout>

          </appender>

          <!--<appender name="AppLogAppender" class="org.apache.log4j.DailyRollingFileAppender">

              <param name="DatePattern" value="'.'yyyy-MM-dd"/>

              <param name="File" value="targe/MyAppLogsFile.log" />

              <param name="Append" value="false"/>

              <layout class="org.apache.log4j.PatternLayout">

                  <param name="ConversionPattern" value="%d [%t] %p - %m%n"/>

              </layout>

          </appender>-->

            <category name="org.yukka.bloggo">

              <priority value="DEBUG"/>

              <appender-ref ref="yukkaconsole"/>

          </category>

            <!--<root>

              <priority value ="DEBUG"/>

              <appender-ref ref="yukkaconsole"/>

          </root>-->

      </log4j:configuration>

       

       

      And I call slf4j logger like this:

       

      [...]

      import org.slf4j.Logger;

      import org.slf4j.LoggerFactory;

      [...]

      private Logger logger = LoggerFactory.getLogger(getClass());

          @EJB

          PostManagerLocal postManager;

       

       

          @Override

          public Response insert(Post post) {

              try{

                  logger.debug("Invoked insert with param: "+post);

                  postManager.create(post);

                  Response response = Response.ok().build();

                  logger.debug("returning response with status: "+response.getStatus());

                  return response;

              }catch (RuntimeException e){

                  logger.error("Error creating post: ");

                  logger.error(e.getLocalizedMessage());

                  Response response = Response.serverError().build();

                  logger.debug("returning response with status: "+response.getStatus());

                  return response;

              }

          }

      [...]

       

       

      The problem is that error calls, writes on the console, while debug calls don't write anything.

      I also tried activating the commented parts of the log4j.xml, the result is the same.

      Is there something wrong in the way I configure logging?

      Is something missing?

      Thanks for any help.

      Bye

        • 1. Re: Arquillian as7 slf4j debug doesn't work
          Vineet Reynolds Apprentice

          I believe the problem lies with this statement in your deployment:

           

          .addAsWebInfResource(EmptyAsset.INSTANCE, "log4j.xml");

           

          That statement adds an empty log4j.xml file (EmptyAsset.INSTANCE) into your WEB-INF directory. You may need to reference the File as an Asset in your addAsWebInfResource call.

          • 2. Re: Arquillian as7 slf4j debug doesn't work
            Tito .. Newbie

            Hi,

            I modified with:

             

            .addAsWebInfResource(new FileAsset(new File("src/test/resources/log4j.xml")), "log4j.xml");

             

            Doesn't work yet

            • 3. Re: Arquillian as7 slf4j debug doesn't work
              Tito .. Newbie

              I found a workaround, that it's not the solution I was looking for, but it works.

              I added this to arquillian.xml:

              <property name="serverConfig">standalone-test.xml</property>

               

              then, I added this to pom.xml:

              <plugin>

                  <artifactId>maven-resources-plugin</artifactId>

                  <version>2.6</version>

                  <executions>

                      <execution>

                          <id>copy-res-test</id>

                          <phase>test-compile</phase>

                          <goals>

                              <goal>copy-resources</goal>

                          </goals>

                          <configuration>

                              <outputDirectory>${basedir}/target/jboss-as-7.1.1.Final/standalone/configuration</outputDirectory>

                              <resources>

                                  <resource>

                                      <directory>src/test/resources</directory>

                                      <includes>

                                          <include>standalone-test.xml</include>

                                      </includes>

                                  </resource>

                              </resources>

                          </configuration>

                      </execution>

                  </executions>

              </plugin>

               

              And, of course, I added in a custom standalone-test.xml the configuration for the log4j category.

              1 of 1 people found this helpful