パスワードを忘れた? アカウント作成
543467 journal

miyachi-yの日記: Maven2 and Logging

日記 by miyachi-y

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());
        }
    }

この議論は賞味期限が切れたので、アーカイブ化されています。 新たにコメントを付けることはできません。
typodupeerror

日本発のオープンソースソフトウェアは42件 -- ある官僚

読み込み中...