We need to configure appender to cloudwatch in our log4j2.xml.
We are using ECS cluster with Fargate instance.
Use case is we need to categories logs in different log groups from same application based on business log type. There is way to send logs to different files using multiple loggers but how we can do same for cloud watch.
There are some libraries written for this but do we have some AWS cloudwatch log appender which we can use in our log4j2.xml. Please help
1
votes
1 Answers
0
votes
We use Spring Boot logging default and send output to the console. This should also work for non-Spring Boot. Then using CloudFormation configure logs in the TaskDefinition
and LogGroup
s. You can do similar in the console with the TaskDefinition
and create the CloudWatch logs separately.
Resources:
.
:
TaskDefinition:
.
:
Properties:
.
:
ContainerDefinitions:
- Name:
Image:
.
:
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-region: !Ref 'AWS::Region'
awslogs-group: !Ref LogGroup
awslogs-stream-prefix: ecs
LogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: !Sub ${ServiceName}
AccessLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub ${ServiceName}-api-access-logs
RetentionInDays: 7