Amazon Managed Service for Apache Flink was previously known as Amazon Kinesis Data Analytics for Apache Flink.
Write custom messages to CloudWatch Logs
You can write custom messages to your Managed Service for Apache Flink application's CloudWatch log. You do this by
using the Apache log4j
Simple Logging Facade for Java (SLF4J)
Write to CloudWatch logs using Log4J
-
Add the following dependencies to your application's
pom.xml
file:<dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.6.1</version> </dependency>
-
Include the object from the library:
import org.apache.logging.log4j.Logger;
-
Instantiate the
Logger
object, passing in your application class:private static final Logger log = LogManager.getLogger.getLogger(
YourApplicationClass
.class); -
Write to the log using
log.info
. A large number of messages are written to the application log. To make your custom messages easier to filter, use theINFO
application log level.log.info("This message will be written to the application's CloudWatch log");
The application writes a record to the log with a message similar to the following:
{ "locationInformation": "com.amazonaws.services.managed-flink.StreamingJob.main(StreamingJob.java:95)", "logger": "com.amazonaws.services.managed-flink.StreamingJob", "message": "This message will be written to the application's CloudWatch log", "threadName": "Flink-DispatcherRestEndpoint-thread-2", "applicationARN": "arn:aws:kinesisanalyticsus-east-1:123456789012:application/test", "applicationVersionId": "1", "messageSchemaVersion": "1", "messageType": "INFO" }
Write to CloudWatch logs using SLF4J
-
Add the following dependency to your application's
pom.xml
file:<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.7</version> <scope>runtime</scope> </dependency>
-
Include the objects from the library:
import org.slf4j.Logger; import org.slf4j.LoggerFactory;
-
Instantiate the
Logger
object, passing in your application class:private static final Logger log = LoggerFactory.getLogger(
YourApplicationClass
.class); -
Write to the log using
log.info
. A large number of messages are written to the application log. To make your custom messages easier to filter, use theINFO
application log level.log.info("This message will be written to the application's CloudWatch log");
The application writes a record to the log with a message similar to the following:
{ "locationInformation": "com.amazonaws.services.managed-flink.StreamingJob.main(StreamingJob.java:95)", "logger": "com.amazonaws.services.managed-flink.StreamingJob", "message": "This message will be written to the application's CloudWatch log", "threadName": "Flink-DispatcherRestEndpoint-thread-2", "applicationARN": "arn:aws:kinesisanalyticsus-east-1:123456789012:application/test", "applicationVersionId": "1", "messageSchemaVersion": "1", "messageType": "INFO" }