Skip to content

Set log levels per package with AWS Managed Apache Flink

1

This question is specific to Amazon Managed Flink (1.19). I know how to control logging in most Java apps, but everything I know is failing in this case.

I have a Java application running in Amazon Managed Service for Apache Flink (MSF).

I can configure the global log level in the UI, but I don't see a way to set the log level on individual classes and packages.

I have tried providing my own log4j2.xml or log4j.properties at the root level of my JAR but it appears to be ignored.

All I really want is for 3rd party code to log at WARN but still have my code log at DEBUG, because setting everything at debug produces enormous noise for this I don't care about.

2 Answers
0

Logging is currently controlled by the service and sent with a fixed JSON format to CloudWatch. Logs from Job Manager and all Task Managers are sent to the same CloudWatch stream. The logging level can be set as part of the application configuration, to DEBUG, INFO, WARN, or ERROR and applies to all loggers . At the moment MSF ignores any logging configuration file or runtime properties set by the application.

The service doesn't natively support package-level log configuration like you would in a standard Java application. The logging level is set at the application level.

[+] https://docs.aws.amazon.com/managed-flink/latest/java/logging.html

AWS
answered 9 months ago
  • I certainly understand the need for AWS to control the format for CloudWatch, but it sure would be nice if they provided a way for the dev to control the levels for individual packages. There's plenty of cases where you need to crank up the level on your code but don't want to see it for 3rd party libs. 25 years of log framework development are centered on that as the most important feature of a log framework, so it's annoying that they've ignored that.

-2

In Amazon Managed Service for Apache Flink, you can set the global log level using the LogLevel parameter when creating or updating an application (via CreateApplication or UpdateApplication actions). The available log levels are ERROR, WARN, INFO, and DEBUG.

However, there are important considerations when working with logging in Managed Service for Apache Flink:

  1. The service doesn't natively support package-level log configuration like you would in a standard Java application. The logging level is set at the application level.

  2. Extensive logging can significantly impact performance. The logging subsystem needs to collect and forward log entries to CloudWatch Logs, and excessive logging can cause your Flink application to fall behind.

  3. The DEBUG log level generates a large amount of traffic and can create backpressure. It should only be used temporarily while actively investigating issues.

For your specific need (having third-party code log at WARN while your code logs at DEBUG), you have a few options:

  1. Set the global log level to WARN and programmatically increase the verbosity for your specific classes using Log4j or SLF4J in your code.

  2. Instead of using the logging system for detailed debugging of your code, consider creating a separate DataStream within your Flink application and use a proper sink to send your debug data to Amazon S3 or CloudWatch. This approach is more aligned with Flink's architecture for high throughput and low latency.

  3. If you must use logging for debugging, keep the global level at WARN for production and only temporarily increase it to DEBUG when actively investigating issues.

Remember that Flink is optimized for high throughput and low latency, but the logging subsystem is not. Logging exceptions and warnings is appropriate, but generating log messages for every processed message is not recommended through the standard logging system.
Sources
Logging in Managed Service for Apache Flink - Managed Service for Apache Flink
Set CloudWatch metrics reporting levels - Managed Service for Apache Flink
Write custom messages to CloudWatch Logs - Managed Service for Apache Flink

answered 9 months ago
  • What do you mean when you say "increase the verbosity for your specific classes using Log4j or SLF4J in your code"? I tried Configurator.setLevel("com.example", Level.DEBUG); Configurator.setLevel("com.example.foo.MyClass", Level.DEBUG); This commands do exactly what I want when running locally but seem to have no effect in Managed Flink environment.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.