Personal tools
You are here: Home Maven Notes Maven2 and Logging
Document Actions

Maven2 and Logging

by MIYACHI Yasuhiko last modified 2007-06-26 09:35

Maven2でLogging(Commons Logging)を利用する方法。

pom.xml

  ...
<dependencies>
...
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<!-- Junitのlog出力をconsoleに表示させるため。 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<disableXmlReport>true</disableXmlReport>
<useFile>false</useFile>
</configuration>
</plugin>
</plugins>
</build>
...

src/test/resources/commons-logging.properties

org.apache.commons.logging.Log = org.apache.commons.logging.impl.SimpleLog

src/test/resources/simplelog.properties

# See: http://jakarta.apache.org/commons/logging/commons-logging-1.1/apidocs/org/apache/commons/logging/impl/SimpleLog.html

# Default logging detail level for all instances of SimpleLog.
#org.apache.commons.logging.simplelog.defaultlog = info

# Logging detail level for a SimpleLog instance named "xxxxx".
#org.apache.commons.logging.simplelog.log.xxxxx =

# Set to true if you want the Log instance name to be included in output messages.
#org.apache.commons.logging.simplelog.showlogname = false

# Set to true if you want the last component of the name to be included in output messages.
#org.apache.commons.logging.simplelog.showShortLogname = true

# Set to true if you want the current date and time to be included in output messages.
#org.apache.commons.logging.simplelog.showdatetime = false

# The date and time format to be used in the output messages.
#org.apache.commons.logging.simplelog.dateTimeFormat = yyyy/MM/dd HH:mm:ss:SSS zzz

 src/test/resourcesにいれておけばmaven packageの時には、packageに含まれない。

src/test/java/example01/HelloTest.java

package example01;

import junit.framework.*;

import org.apache.commons.logging.*;

public class LoggingTest extends TestCase
{
private static final Log log = LogFactory.getLog(LoggingTest.class);

public void testLogging()
{
log.trace("testLogging()");
}
}

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: