Create Service Log Driver

Create Service Log Driver

  1. During the development of a Spring Boot application, we need logging for debugging the application. Therefore, we will use CloudWatch Log Groups.

  2. To create a log group, first initialize an AwsLogDriver object within the constructor:

   AwsLogDriver logDriver = new AwsLogDriver(AwsLogDriverProps.builder()
       .build());

Architect

  1. Initialize a LogGroup object within the AwsLogDriver:
.logGroup(new LogGroup(this, "LogGroup",
       LogGroupProps.builder()
           .build()))

Architect

  1. Next, we need to add the necessary properties for the LogGroup:
    • Set the log group name to ProductsService:
      .logGroupName("ProductsService")
      
    • Configure the log group to be deleted when the Stack is deleted:
      .removalPolicy(RemovalPolicy.DESTROY)
      
    • Finally, specify how long AWS should retain these logs. Let’s retain them for one month:
      .retention(RetentionDays.ONE_MONTH)
      

Architect

  1. Finally, we need to set a prefix for our log files:
   .streamPrefix("ProductsService")

Architect