Writing Messages to Log Files
Writing messages to a log can help you when you debug your Python UDxs and want to output additional information about an error condition.
To write a message to the vertica log file, use the server_interface.log()
function:
def processBlock(self, server_interface, arg_reader, res_writer): server_interface.log("Python UDx - Adding 2 ints!") while(True): first_int = block_reader.getInt(0) second_int = block_reader.getInt(1) block_writer.setInt(first_int + second_int) server_interface.log("Values: first_int is {} second_int is {}".format(first_int, second_int)) block_writer.next() if not block_reader.next(): break
Verticawrites the messages to a log file stored in the catalog directory's UDxlog
subdirectory, which is named UDxFencedProcesses.log
:
$ tail /home/dbadmin/py_db/v_py_db_node0001_catalog/UDxLogs/UDxFencedProcesses.log 07:52:12.862 [Python-v_py_db_node0001-7524:0x206c-40575] 0x7f70eee2f780 PythonExecContext::processBlock 07:52:12.862 [Python-v_py_db_node0001-7524:0x206c-40575] 0x7f70eee2f780 [UserMessage] add2ints - Python UDx - Adding 2 ints! 07:52:12.862 [Python-v_py_db_node0001-7524:0x206c-40575] 0x7f70eee2f780 [UserMessage] add2ints - Values: first_int is 100 second_int is 100
Vertica adds the SQL name of the UDx to the log message. It also adds the string [UserMessage]
to mark the entry as a message added by a call to the server_interface.log()
function. These additions allow you to filter the log to find the messages generated by your UDx.