Project: Flink (App Definition and Development / Streaming & Messaging)
File: debugging.md

title: "Debugging" weight: 130 type: docs <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> This page describes how to debug in PyFlink. You can log contextual and debug information via `print` or standard Python logging modules in PyFlink jobs in places outside Python UDFs. The logging messages will be printed in the log files of the client during job submission. ```python from pyflink.table import EnvironmentSettings, TableEnvironment envsettings = EnvironmentSettings.instreaming_mode() tableenv = TableEnvironment.create(envsettings) table = tableenv.fromelements([(1, 'Hi'), (2, 'Hello')]) import logging logging.warning(table.get_schema()) print(table.get_schema()) ``` Note: The default logging level at client side is `WARNING` and so only messages with logging level `WARNING` or above will appear in the log files of the client. You can log contextual and debug information via `print` or standard Python logging modules in Python UDFs. The logging messages will be printed in the log files of the `TaskManagers` during job execution. ```python from pyflink.table import DataTypes from pyflink.table.udf import udf import logging @udf(result_type=DataTypes.BIGINT()) def add(i, j): logging.info("debug") print('debug') return i + j ``` Note: The default logging level at server side is `INFO` and so only messages with logging level `INFO` or above will appear in the log files of the `TaskManagers`. If environment variable `FLINKHOME` is set, logs will be written in the log directory under `FLINKHOME`. Otherwise, logs will be placed in the directory of the PyFlink module. You can execute the following command to find the log directory of the PyFlink module: ```bash $ python -c "import pyflink;import os;print(os.path.dirname(os.path.abspath(pyflink.file))+'/log')" ``` You can debug your python functions directly in IDEs such as PyCharm. You can make use of the tool of PyCharm to debug Python UDFs. Create a Python Remote Debug in PyCharm run -> Python Remote Debug -> + -> choose a port (e.g. 6789) Install the `pydevd-pycharm` tool ```bash $ pip install pydevd-pycharm ``` Add the following command in your Python UDF ```python import pydevd_pycharm pydevd_pycharm.settrace('localhost', port=6789, stdoutToServer=True, stderrToServer=True) ``` Start the previously created Python Remote Debug Server Run your Python Code You can enable the profile to analyze performance bottlenecks. ```python tenv.getconfig().set("python.profile.enabled", "true") ``` Then you can see the profile result in