Issue
I wanted to put my log in to aws CloudWatch. So I googled it and copied one of them.
But I understand what other thing's do but I can't under stand what springProfile does. What is springProfile and when does it get trigger?
<configuration packagingData="true">
<timestamp key="timestamp" datePattern="yyyy-MM-dd-HH-mm-ssSSS"/>
<springProperty name="AWS_ACCESS_KEY" source="cloud.aws.credentials.accessKey"/>
<springProperty name="AWS_SECRET_KEY" source="cloud.aws.credentials.secretKey"/>
<appender name="aws_cloud_watch_log" class="ca.pjer.logback.AwsLogsAppender">
<layout>
<pattern>[%thread] [%date] [%level] [%file:%line] - %msg%n</pattern>
</layout>
<logGroupName>Kculter-log</logGroupName>
<logStreamUuidPrefix>Kculter-log-</logStreamUuidPrefix>
<logRegion>ap-northeast-2</logRegion>
<maxBatchLogEvents>50</maxBatchLogEvents>
<maxFlushTimeMillis>30000</maxFlushTimeMillis>
<maxBlockTimeMillis>5000</maxBlockTimeMillis>
<retentionTimeDays>2</retentionTimeDays>
<accessKeyId>${AWS_ACCESS_KEY}</accessKeyId>
<secretAccessKey>${AWS_SECRET_KEY}</secretAccessKey>
</appender>
<appender name="application_log" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%thread] [%date] [%level] [%file:%line] - %msg%n</pattern>
</encoder>
</appender>
<springProfile name="(local | development)">
<root level="INFO">
<appender-ref ref="application_log"/>
<appender-ref ref="aws_cloud_watch_log"/>
</root>
</springProfile>
<springProfile name="(stage | production)">
<root level="INFO">
<appender-ref ref="application_log"/>
<appender-ref ref="aws_cloud_watch_log"/>
</root>
<logger name="com.example" level="DEBUG">
<appender-ref ref="aws_cloud_watch_log"/>
</logger>
</springProfile>
</configuration>
Solution
your application will be using that particular appender while logging in a particular spring profile.
example :
<springProfile name="(local | development)"> // only application_log appender will be use if your spring.profile=local
<root level="INFO">
<appender-ref ref="application_log"/>
</root>
</springProfile>
<springProfile name="(stage | production)">// only aws_cloud_watch_log appender will be use if your spring.profile=stage/production & so on.
<root level="INFO">
<appender-ref ref="aws_cloud_watch_log"/>
</root>
<logger name="com.example" level="DEBUG">
<appender-ref ref="aws_cloud_watch_log"/>
</logger>
</springProfile>
hope you get the idea.
Answered By - Souvik Dey
Answer Checked By - Willingham (JavaFixing Volunteer)