Writing Messages to the Log File
Writing messages to a log is useful when you are debugging your Java UDxs, or you want to output additional information about an error condition. You can write messages to a log file by calling the ServerInterface.log()
method, passing it a printf()
-style String
value along with any variables referenced in the string. (See the java.util.Formatter class documentation for details of formatting this string value.) An instance of the ServerInterface
class is passed to the main processing method of every SDK class you can override.
The following code fragment demonstrates how you could log the values passed into the Add2ints UDSF example.
@Override public void processBlock(ServerInterface srvInterface, BlockReader argReader, BlockWriter resWriter) throws UdfException, DestroyInvocation { do { // Get the two integer arguments from the BlockReader long a = argReader.getLong(0); long b = argReader.getLong(1); // Log the input values srvInterface.log("Got values a=%d and b=%d", a, b);
The messages are written to a log file stored in the catalog directory's UDxlog
subdirectory named UDxFencedProcessesJava.log
:
$ tail VMart/v_vmart_node0001_catalog/UDxLogs/UDxFencedProcesses.log 2012-12-12 10:23:47.649 [Java-2164] 0x01 UDx side process (Java) started 2012-12-12 10:23:47.871 [Java-2164] 0x0b [UserMessage] add2ints - Got values a=5 and b=6 2012-12-12 10:23:48.598 [Java-2164] 0x0c Exiting UDx side process
The SQL name of the UDx is added to the log message, along with the string [UserMessage]
to mark the entry as a message added by a call to the log()
method. These additions make it easier for you to filter the log to find the messages generated by your UDx.