Elastic Beanstalk + logback

beanstalkでtomcatデプロイ。で、ログを出したいだけなのに 何かといろいろ調べなければならなかった。


pom.xmlに依存を加える
<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.5</version>
		</dependency>
	    <dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-jdk14</artifactId>
			<version>1.7.5</version>
		</dependency>
	    <dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jcl-over-slf4j</artifactId>
			<version>1.7.5</version>
		</dependency>
	    <dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>log4j-over-slf4j</artifactId>
			<version>1.7.5</version>
		</dependency>
		<dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>0.9.15</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>0.9.15</version>
        </dependency>

このままだと、何かが重複している警告がでるが、今はとりあえず無視

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/gen/workspace2/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jrs/WEB-INF/lib/logback-classic-0.9.15.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/gen/workspace2/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jrs/WEB-INF/lib/slf4j-jdk14-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.selector.DefaultContextSelector]
SLF4J: The requested version 1.5.6 by your slf4j binding is not compatible with [1.6, 1.7]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.

src/main/resources以下にlogback.xmlというファイル名で設定ファイルを作る
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<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>
  
  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>aaa.log</file>
    <Encoding>UTF-8</Encoding>
    <layout class="ch.qos.logback.classic.PatternLayout">
      <param name="Pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n" />
    </layout>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <FileNamePattern>aaa.log.%d{yyyy-MM-dd}.gz</FileNamePattern>
      <MaxHistory>30</MaxHistory>
    </rollingPolicy>
  </appender>
  
  <logger name="jp">
    <level value="DEBUG" />
    <appender-ref ref="FILE" />
  </logger>
   
  <root level="debug">
    <appender-ref ref="FILE" />
  </root>
</configuration>
logをtail

デプロイされたec2インスタンスsshでログインして、ログを見ることができる

tail -f /usr/share/tomcat7/aaa.log

beanstalkのWEB管理画面のログにはどうやって出すんだろう。。

それっぽい情報はあるが、めんどい。。
jcabi-beanstalk-maven-plugin - Using syslogd at Amazon Elastic Beanstalk