The logging in Flink is implemented using the slf4j logging interface. As underlying logging framework, log4j2 is used. We also provide logback configuration files and pass them to the JVM’s as properties. Users willing to use logback instead of log4j2 can just exclude log4j2 (or delete it from the lib/ folder).
Log4j2 is controlled using property files. In Flink’s case, the file is usually called log4j.properties
. We pass the filename and location of this file using the -Dlog4j.configurationFile=
parameter to the JVM.
Flink ships with the following default properties files:
log4j-cli.properties
: Used by the Flink command line client (e.g. flink run
) (not code executed on the cluster)log4j-session.properties
: Used by the Flink command line client when starting a YARN or Kubernetes session (yarn-session.sh
, kubernetes-session.sh
)log4j.properties
: JobManager/Taskmanager logs (both standalone and YARN)Flink ships with the Log4j API bridge, allowing existing applications that work against Log4j1 classes to continue working.
If you have custom Log4j1 properties files or code that relies on Log4j1, please check out the official Log4j compatibility and migration guides.
To use Flink with Log4j1 you must ensure that:
org.apache.logging.log4j:log4j-core
, org.apache.logging.log4j:log4j-slf4j-impl
and org.apache.logging.log4j:log4j-1.2-api
are not on the classpath,log4j:log4j
, org.slf4j:slf4j-log4j12
, org.apache.logging.log4j:log4j-to-slf4j
and org.apache.logging.log4j:log4j-api
are on the classpath.In the IDE this means you have to replace such dependencies defined in your pom, and possibly add exclusions on dependencies that transitively depend on them.
For Flink distributions this means you have to
log4j-core
, log4j-slf4j-impl
and log4j-1.2-api
jars from the lib
directory,log4j
, slf4j-log4j12
and log4j-to-slf4j
jars to the lib
directory,conf
directory with Log4j1-compliant versions.For users and developers alike it is important to control the logging framework.
The configuration of the logging framework is exclusively done by configuration files.
The configuration file either has to be specified by setting the environment property -Dlogback.configurationFile=<file>
or by putting logback.xml
in the classpath.
The conf
directory contains a logback.xml
file which can be modified and is used if Flink is started outside of an IDE and with the provided starting scripts.
The provided logback.xml
has the following form:
In order to control the logging level of org.apache.flink.runtime.jobgraph.JobGraph
, for example, one would have to add the following line to the configuration file.
For further information on configuring logback see LOGback’s manual.
The loggers using slf4j are created by calling
In order to benefit most from slf4j, it is recommended to use its placeholder mechanism. Using placeholders allows to avoid unnecessary string constructions in case that the logging level is set so high that the message would not be logged. The syntax of placeholders is the following:
Placeholders can also be used in conjunction with exceptions which shall be logged.