简体   繁体   中英

Logging SLF4J to ElasticBeanstalk

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>

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM