Search code examples
pythonamazon-web-servicesstreamproducer-consumeramazon-kinesis

How can I debug KCL(python) in python script?


I use KCL library for python consumer, but I don't know how can I get data and etc in python script?

It works via MultiLangDaemon and based on java. I have a python script which works above java (I use samples in the library and use sample_kclpy_app.py) and when I start java (which was generated by python) I'm not able to get data or print data.

How can I debug it via python script? I tried to start sample_kclpy_app.py parallel and nothing happened.


Solution

  • The Kinesis Client Library communicates between Java and Python via STDIN / STDOUT, so instead of using print statements, debugging can be performed via a Python logging object directed to a file. For example, within sample_kclpy_app.py:

    Add to the import section:

    import logging
    

    Add to the RecordProcessor init method:

    logging.basicConfig(filename='test.log',
            format='%(asctime)s %(levelname)-8s %(message)s',
            datefmt='%Y-%m-%d %H:%M:%S',
            level=logging.DEBUG)
    

    Add to the process_record method (for a simple logging example):

    logging.debug('Data: %s', data.decode('utf8'))
    

    See https://docs.python.org/3/library/logging.html for more details on the logging module.