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
1
2
3
4
5
6
7
8
@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
1
2
3
4
5
6
7
8
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