Maven – Log4j setting for maven with Springframework

In order to enable log4j settings in maven compilation, log4j.properties file should be in the test/resources directory.

Sample unit test class

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:config/test-applicationContext.xml")
public class SimpleTestExampleTest extends AbstractJUnit4SpringContextTests {
    @Before
    public void setUp() throws Exception {
        logger.debug("Executing before");
    }
}

Sample log4j.properties file

log4j.rootLogger=ERROR, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

# An alternative logging format:
# log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1} - %m%n
Advertisements
This entry was posted in Java, Programming and tagged . Bookmark the permalink.

One Response to Maven – Log4j setting for maven with Springframework

  1. Pingback: Maven – Log4j setting for maven with Springframework | Dinesh Ram Kali.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s