From 717a32836e6ef1f18f6138f8e6c6939ea301c9cb Mon Sep 17 00:00:00 2001 From: Arun Jose <40291569+arunjose696@users.noreply.github.com> Date: Wed, 10 Apr 2024 18:18:00 +0200 Subject: [PATCH] DOCS-#7144: Add information about logging from user defined function (#7155) Co-authored-by: Iaroslav Igoshev Signed-off-by: arunjose696 --- .../advanced_usage/modin_logging.rst | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/usage_guide/advanced_usage/modin_logging.rst b/docs/usage_guide/advanced_usage/modin_logging.rst index 786874d33ce..8bf7225d105 100644 --- a/docs/usage_guide/advanced_usage/modin_logging.rst +++ b/docs/usage_guide/advanced_usage/modin_logging.rst @@ -53,3 +53,42 @@ Disable Modin logging like so: LogMode.disable() # User code goes here + +Debugging from user defined functions: + +.. warning:: + When attempting to use Modin logging in user defined functions that execute in workers for logging lower-level operators + as in example below, multiple log directories ``.modin/logs/job_**`` would be created for each worker executing the UDF. + +.. code-block:: python + + import modin.pandas as pd + + def udf(x): + from modin.config import LogMode + + LogMode.enable() + + return x + 1 + + modin_df = pd.DataFrame([0, 1, 2, 3]) + print(modin_df.map(udf)) + +So the **recommended** approach would be to use a different logger as in the below snipet +to log from user defined functions that execute on workers. +Below is an an example to log from UDF. For this the logger config has to be specified inside the UDF that would execute on a remote worker. + +.. code-block:: python + + import logging + import modin.pandas as pd + + def udf(x): + logging.basicConfig(filename='modin_udf.log', level=logging.INFO) + logging.info("This log message will be written to modin_udf.log ") + + # User code goes here + return x + 1 + + modin_df = pd.DataFrame([0, 1, 2, 3]) + print(modin_df.map(udf))