4

How can I route logging from my Java webapp on Tomcat 7 to the logs visible in the ElasticBeanstalk admin console or Eclipse plugin? My application is coded to the SLF4J API and backed with Logback.

I'd really like to not have to SSH in to each box and tail a log file; I'm adding and removing instances all the time, so that'd be a right pain.

My logback.xml looks like this:

<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="org.springframework" level="INFO" />
    <logger name="org.springframework.social" level="INFO" />
    <logger name="org.socialsignin" level="INFO" />

    <root level="ALL">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>
DeejUK
  • 12,891
  • 19
  • 89
  • 169

2 Answers2

2

I use slf4j-jdk14 as a backend and it works fine when deployed to ElasticBeanstalk.

The following will make all other libraries you use log to the same backend:

        <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>log4j-over-slf4j</artifactId>
    </dependency>

Hope this works for you.

tod
  • 81
  • 2
  • What do you mean by log to the same backend, when we get logs from elasticbeanstalk does it contains the sl4j logs as well? If not where are the logs stored? – Anshul Goel Oct 20 '15 at 18:53
0

I would strongly recommend to forward your logs to papertrailapp.com through syslog. Read more about it in jcabi-beanstalk-maven-plugin. There are many benefits of this solution comparing to the one you're using, including: 1) logs are easier to read, 2) logs can be integrated in one place from many servers, 3) other systems can log into the same destination, etc.

yegor256
  • 102,010
  • 123
  • 446
  • 597
  • How well does Papertrail handle strack traces? Syslog-based solutions often end up either creating separate events for each line in a stack trace, or else truncating the stack trace... – ejain Oct 14 '15 at 22:54
  • 1
    @ejain Papertrail creates multiple events, which in the end looks ugly and almost unreadable – yegor256 Oct 15 '15 at 00:18