AWS Cloudwatch Logback Appender for Spring Boot Applications

Viewed 9938

I'm trying to send Logs directly to Cloudwatch from my Spring Boot Application. The Logback Appender I'm using, of course needs AWS Credentials. Since most developers doesn't have AWS Credentials on their local machines and just want to log into a file according to the the logback-spring.xml configuration. Most tests fail locally, because of missing aws credentials.
Is there a way to initialize the logback appender only for a specific profile?
Here's a snapshot of the logback-spring.xml:

<!--  Configuration for your local environment -->
<springProfile name="${user.name}">
    <root level="DEBUG">
        <appender-ref ref="ROLLING_FILE" />
    </root>
</springProfile>

<appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    ...
</appender>


<!-- Configuration for Development Environment --> 
<springProfile name="dev">
    <root level="DEBUG">
        <appender-ref ref="AWS_LOGS_DEV" />
        <appender-ref ref="ROLLING_FILE" />
    </root>
</springProfile>

<appender name="AWS_LOGS_DEV" class="ca.pjer.logback.AwsLogsAppender">
    <layout>
        <pattern>${FILE_LOG_PATTERN}</pattern>
    </layout>
    <logGroupName>/dev</logGroupName>
    <logStreamName>log_${date}</logStreamName>
</appender>
1 Answers
Related