logback

maven

pom.xml dependencies+=

		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
			<version>0.9.24</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

running code

logback.xml

/file/logback/lgb.png

一般に、src/main/resouce下にlogback.xmlを配置する

/file/logback/lgb2.png

projectのビルドパスにこのフォルダを加えておく必要がある(jarの/にlogback.xmlが来るようにする)

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
    </layout>
  </appender>
  <logger name="tiddsite.tiddsite.App" level="TRACE"/>
  <root level="trace">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

STDOUTの他にもファイルに出力する方法があったり、
TRACEのほかにもINFOレベル以上の出力,ERROR以上の出力と変更ができる

実行した感じはこうなる

03:30:51,647 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
03:30:51,648 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
03:30:51,648 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/home/debianunsmart/workspace/tiddsite/target/classes/logback.xml]
03:30:52,200 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
03:30:52,254 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
03:30:52,267 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
03:30:52,376 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing component [layout] on top of the object stack.
03:30:52,506 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.
03:30:52,506 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.
03:30:52,506 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details
03:30:52,508 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [jp.newsrecorder.net.GetImpl] to TRACE
03:30:52,508 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [jp.newsrecorder.net.GetImpl] to true
03:30:52,508 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [jp.newsrecorder.procedure.ImageImpl] to TRACE
03:30:52,508 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [jp.newsrecorder.procedure.ImageImpl] to true
03:30:52,508 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [jp.newsrecorder.procedure.Base64converter] to TRACE
03:30:52,508 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [jp.newsrecorder.procedure.Base64converter] to true
03:30:52,508 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to TRACE
03:30:52,509 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]

03:30:52.546 [main] TRACE tiddsite.tiddsite.App - Hello

関連記事 maven
実際の事例 http://bazaar.launchpad.net/~ryoji-kodakari/tiddlywikisplitter/ts/files/head:/src/main/resource/

    last modified: 23 July 2011 [ View wiki source Close ]
     
SEARCH DIFFERENCE ATTACHMENT RECENT POST