0

I'm doing some java maven project based on thucydides-jbehave-archetype.

Smslib dependency is added through maven:

<dependency>
   <groupId>org.smslib</groupId>
   <artifactId>smslib</artifactId>   
   <version>dev-SNAPSHOT</version>
</dependency>
...
<repositories>
   <repository>
      <id>smslib-snapshots</id>
      <name>SMSLib Repository</name>
      <url>http://smslib.org/maven2/snapshots/</url>
   </repository>
</repositories>

Among the pure web tests I plan to do some sms sending/receiving; sms code is placed in src/main/java/projectname/gsm package (for instance, page objects are placed in src/main/java/projectname/pages, steps are placed in src/test/java/projectname.jbehave/). I'd like to enable debug messages for smslib, but not for thucydides. However, there was no location where log4j.properties worked for smslib, and there was one location, that resulted in appearing debug messages for thucydides.

Eljah
  • 4,188
  • 4
  • 41
  • 85

2 Answers2

1

You can dump your log4j.properties file in src/main/resources.

To control the log level, just create an appropriate Log4j configuration file.

...
# Print only messages of level WARN or above in the package com.foo.
log4j.logger.com.foo=WARN
...

For more details, please have a look at the Log4j manual.

rimero
  • 2,383
  • 1
  • 14
  • 8
1

Can your question be rephrased as:

How do I set two different log levels using properties files for log4j - using two separate files for two classes in different packages?

If this is the case, rimero's answer is a start. But instead of dropping the properties files in src/main/sources, you need to drop each file (defining a different log level) in a directory structure reflecting the package name (for example src/main/projectname/page). Then, you can load each properties file separately using

PropertyConfigurator.configure(URL configURL)

There are a couple of ways to get the url of your properties files, see for example:

How to configure log4j with a properties file

Here is a full example:


public class TestPropertiesFile {

private static final String PREFIX = "projectname/pages";
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
        .getLogger("projectname.page.SomeClass");
private static String PROPERTIES_PATH;

static {
    PROPERTIES_PATH = Thread.currentThread().getContextClassLoader()
            .getResource(PREFIX + "/log4j.properties").getPath();
    org.apache.log4j.PropertyConfigurator.configure(PROPERTIES_PATH);

}

public static void test() {
    LOGGER.info("Logging from: " + PROPERTIES_PATH);
}

}

Community
  • 1
  • 1
jvdbogae
  • 1,241
  • 9
  • 15
  • Thank you for your detailed answer! My fault, but the thing I intended to ask is actually "does smslib maven dependency write debug logs at all?". I faced the problem that when I put the Debug-enabled log4j.properties file to the main/resources or test/resources, in both cases i get debug messages from thucydides only; and see none from Smslib. Your answer will help me after I will get both smslib and thucydides debug messages in the same output. I think I should address my question to Smslib user group first! – Eljah Jun 26 '13 at 18:53
  • Also, I'm using two libraries added as maven dependencies with logging encapsulated within them. I'm not planning to implement my own logging at all. Is there a way to modify their logging with no coding, but with maven configuration only? Some logging plugins, or something else. – Eljah Jun 26 '13 at 18:55