Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Write custom messages to CloudWatch Logs

Focus mode
Write custom messages to CloudWatch Logs - Managed Service for Apache Flink

Amazon Managed Service for Apache Flink was previously known as Amazon Kinesis Data Analytics for Apache Flink.

Amazon Managed Service for Apache Flink was previously known as Amazon Kinesis Data Analytics for Apache Flink.

You can write custom messages to your Managed Service for Apache Flink application's CloudWatch log. You do this by using the Apache log4j library or the Simple Logging Facade for Java (SLF4J) library.

Write to CloudWatch logs using Log4J

  1. 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>
  2. Include the object from the library:

    import org.apache.logging.log4j.Logger;
  3. Instantiate the Logger object, passing in your application class:

    private static final Logger log = LogManager.getLogger.getLogger(YourApplicationClass.class);
  4. 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 the INFO 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

  1. 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>
  2. Include the objects from the library:

    import org.slf4j.Logger; import org.slf4j.LoggerFactory;
  3. Instantiate the Logger object, passing in your application class:

    private static final Logger log = LoggerFactory.getLogger(YourApplicationClass.class);
  4. 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 the INFO 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" }
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.