apache-flink logging Using a logger in your code


Example

Add the slf4j dependency to your pom.xml:

<properties>
    <slf4j.version>1.7.21</slf4j.version>
</properties>

<!-- ... --> 

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>${slf4j.version}</version>
</dependency>

Create a logger object for use in your class:

private Logger LOGGER = LoggerFactory.getLogger(FlinkApp.class);

In classes that need to be serialized, such as subclasses of RichMapFunction, don't forget to declare LOGGER as transient:

private transient Logger LOG = LoggerFactory.getLogger(MyRichMapper.class);

In your code, use LOGGER as usual. Use placeholders ({}) to format objects and such:

LOGGER.info("my app is starting");
LOGGER.warn("an exception occurred processing {}", record, exception);