Sending logs from Mule application to CloudWatch
2 min readFeb 14, 2024
Add below dependencies to POM.xml
<dependency>
<groupId>com.kdgregory.logging</groupId>
<artifactId>log4j2-aws-appenders</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-logs</artifactId>
<version>1.11.495</version>
</dependency>
Add the required packages, Appenders, and loggers in the log4j.xml
<?xml version="1.0" encoding="utf-8"?>
<Configuration packages="com.mulesoft.ch.logging.appender,com.kdgregory.log4j2.aws" status="debug">
<Appenders>
<CloudWatchAppender name="CLOUDWATCH">
<logGroup>mule</logGroup>
<logStream>mulestream</logStream>
<rotationMode>daily</rotationMode>
<PatternLayout
pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-5p [%t] %c - %m%n" />
</CloudWatchAppender>
</Appenders>
<Loggers>
<AsyncRoot level="INFO">
<AppenderRef ref="CLOUDWATCH" />
</AsyncRoot>
</Loggers>
</Configuration>
logGroup, logStream will be the log group and log stream created in cloudwatch
Steps to create log group and log stream in CloudWatch:
- from console home , click on Cloudwatch.
- select logs >log group
- click create log group, enter log group name.
- now click on log group created and create log stream.
Create IAM access key and secret to access services and download csv to have access key and access secret
pass access key Id , region and secret in run configurations:
Now intiate flow and observe logs in aws cloudwatch