Skip to main content

Reference: Developing and Debugging a Custom Protocol Action

Issue:

If a user is developing a custom protocol action, what are some best practices to test and debug the code?

Solution:

Users are able to view errors and tracebacks by tailing the ESP logs (see this article for more details about how to narrow down which logs: Reference: How to Search Logs).

Refer to the two files attached (example_pa_error.txt and pa_notification_error.txt) as an example of a Protocol Action Execution error and the corresponding entry from the l7.esp.log file.

Users may also try to write a custom log while debugging (refer to the logging.txt file attached and the associated notes below):

  • Create a FileHandler named file_handler with a log level of DEBUG and a file name of 'esp.log'

  • Create a StreamHandler named stream_handler to output log messages to the console, and add both handlers to the logger

  • Create a formatter and adds to both handlers to specify how the log messages should be formatted

  • Ability to output messages at different log levels, which will be written to the file specified by file_handler

  • An absolute path for the log file can also be specified by replacing 'esp.log' with the absolute path where the logs are desired to be written, otherwise the log file will be written in the current working directory

file_handler = logging.FileHandler('/path/to/my/log/file.log')

file_handler.setLevel(logging.DEBUG)