Printing or logging from UDF

Hi,
For debugging purposes I would like to use a print statement in a UDF (as suggested in another discussion) but I cannot see the output either below the cell executing the UDF or in the job logs. See the code example below. What is the proper way to do this?

udf_code = """
from openeo.udf import XarrayDataCube

def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
    print("test")
    return cube
"""

process = openeo.UDF(code=udf_code, runtime="Python", data={"from_parameter": "x"})
out_cube = in_cube.apply(process=process)
my_job  = out_cube.send_job(title="test")
results = my_job.start_and_wait().get_results()

0:00:00 Job 'j-f6c5c0e454314179b205c5cb6f80efed': send 'start'
0:00:24 Job 'j-f6c5c0e454314179b205c5cb6f80efed': queued (progress N/A)
0:00:29 Job 'j-f6c5c0e454314179b205c5cb6f80efed': queued (progress N/A)
0:00:36 Job 'j-f6c5c0e454314179b205c5cb6f80efed': queued (progress N/A)
0:00:44 Job 'j-f6c5c0e454314179b205c5cb6f80efed': queued (progress N/A)
0:00:54 Job 'j-f6c5c0e454314179b205c5cb6f80efed': queued (progress N/A)
0:01:07 Job 'j-f6c5c0e454314179b205c5cb6f80efed': queued (progress N/A)
0:01:23 Job 'j-f6c5c0e454314179b205c5cb6f80efed': queued (progress N/A)
0:01:42 Job 'j-f6c5c0e454314179b205c5cb6f80efed': running (progress N/A)
0:02:06 Job 'j-f6c5c0e454314179b205c5cb6f80efed': running (progress N/A)
0:02:37 Job 'j-f6c5c0e454314179b205c5cb6f80efed': running (progress N/A)
0:03:14 Job 'j-f6c5c0e454314179b205c5cb6f80efed': running (progress N/A)
0:04:01 Job 'j-f6c5c0e454314179b205c5cb6f80efed': running (progress N/A)
0:04:59 Job 'j-f6c5c0e454314179b205c5cb6f80efed': finished (progress N/A)
print(my_job.logs())
[]
1 Like

Indeed, this feature (logging from UDFs) does not work yet the way we want it at the moment.
We’re still working on connecting all the necessary dots to make that possible for an end user.

Hi Stefaan, would you have any update on the progress of UDF logging?

So far we don’t have anything working for end users.
Now with the summer months we are also a bit short on development capacity to tackle this swiftly

Hi,

I wanted to let know that we have initial support for logging from UDF’s for debugging purposes.

usage example:
UDF code: use the inspect logging function (based on inspect process):

from openeo.udf import XarrayDataCube
from openeo.udf.debug import inspect

def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
    inspect(message="Hello UDF logging")
    inspect(data=[1,2,3], message="hello UDF logging with data")
    array = cube.get_array()
    array.values = 0.0001 * array.values
    return cube

When requesting the job logs, you should be able to see these log entries, for example in a Jupyter notebook using the job.logs() widget:
Screenshot from 2022-09-21 17-22-40

At the moment, not all data types are properly supported in the data argument of inspect, we are working on that. But feel free to already experiment with the current functionality

1 Like