Skip to content

Instantly share code, notes, and snippets.

@ufuk
Last active January 5, 2021 09:50
Show Gist options
  • Save ufuk/c8501f8ada41adcd619e8f0a4559f7e5 to your computer and use it in GitHub Desktop.
Save ufuk/c8501f8ada41adcd619e8f0a4559f7e5 to your computer and use it in GitHub Desktop.
Spring Boot & AWS Elastic Beanstalk & AWS Cloudwatch Log Stream friendly logging with newline replacing support to convert root cause's stack trace into single line message. And does these within Spring Boot's default pattern layout.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<appender name="CLOUD_WATCH_FRIENDLY" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m %replace(%rEx{short}){'[\r\n\t]+', '\\n'}%nopex%n</pattern>
</encoder>
</appender>
<springProfile name="!dev &amp; !prod">
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
<springProfile name="dev">
<root level="info">
<appender-ref ref="CLOUD_WATCH_FRIENDLY"/>
</root>
</springProfile>
<springProfile name="prod">
<root level="info">
<appender-ref ref="CLOUD_WATCH_FRIENDLY"/>
</root>
</springProfile>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment