Within the Python node, you have access to four different methods for logging. These methods all perform the same operation, but use a different log level. The methods are as follows:
-
self.logInfo(msg)
-
self.logLow(msg)
-
self.logMedium(msg)
-
self.logHigh(msg)
The severity of the log level with which the message is logged, in comparison to the LogLevel property on the Python node determine whether or not the message is actually written to the log.
These methods and corresponding log levels (as will be reported in the node’s log) are outlined in the following table:
Method | LogLevel | When to use | When written to log? | Example |
---|---|---|---|---|
|
|
Used when logging information unrelated to any errors, just debugging information which may be useful to identify what is going on in the processing logic. The contents of these debug statements may only make sense to the node developer for troubleshooting purposes. |
|
|
|
|
Generally useful if an error occurs, but is handled. |
|
|
|
|
Generally used when an error occurs, but the code is able to make some assumptions & continue. Is possible/likely to lead to an error later. |
|
|
|
|
Used when the node is about to fail. Often, an exception will be raised instead and the message will be in the exception details. Can be used in places where a single error can cause the node to fail, but you want to log all of these errors prior to failing the node. |
|
|
Any exception can be raised from the code within the initialize
, finalize
and pump
methods and the node will handle them, failing the node appropriately.
In general, the easiest mechanism for forcing node failure, and reporting a message back to the node log is to raise a BrainNodeException
. The following example shows where the required field specified in the InputFieldName property does not exist on the metadata:
idx = input.metadata.find(self.inputFieldName)
if idx == -1:
raise braininfo.BrainNodeException, "Specified InputFieldName: %s does not exist on input: %s " % (self.inputFieldName, input.name)