miyachi-yの日記: Maven2 and Logging
Maven2でLogging(Commons Logging)を利用する方法。
- Projectの構造
example01
|-- pom.xml
`-- src
|-- main
| |-- java
| | `-- example01
| | |-- App.java
| | `-- Hello.java
| `-- resources
`-- test
|-- java
| `-- example01
| |-- AppTest.java
| `-- HelloTest.java
`-- resources
|-- commons-logging.properties
`-- simplelog.properties - pom.xml
<dependencies>
...
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<!-- Junitのlog出力を表示させるため。 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useFile>false</useFile>
</configuration>
</plugin>
</plugins>
</build>
... - commons-logging.properties
org.apache.commons.logging.Log = org.apache.commons.logging.impl.SimpleLog
- simplelog.properties
org.apache.commons.logging.simplelog.defaultlog = trace
#org.apache.commons.logging.simplelog.log.xxxxx = trace
org.apache.commons.logging.simplelog.showlogname = true
#org.apache.commons.logging.simplelog.showShortLogname =
org.apache.commons.logging.simplelog.showdatetime = true
#org.apache.commons.logging.simplelog.dateTimeFormat = - HelloTest.java
package example01;
import junit.framework.*;
import org.apache.commons.logging.*;
public class HelloTest extends TestCase
{
private static final Log log = LogFactory.getLog(HelloTest.class);
public void testGreeting()
{
log.trace("testGreeting()");
Hello hello = new Hello();
hello.setGreeting("hello world.");
assertEquals("hello world.", hello.getGreeting());
}
}
Maven2 and Logging More ログイン