python-3.xmicroservicescumulocity

How to debug a not starting up Cumulocity Microservice written in Python?


How to enable log for microservice developped in Python?

I can run hello-microservice without a glitch. However, my own microservice looks not starting up after I uploaded the zip file. I tried to wait for hours, and the same. I have run the docker locally without issue.

A call to any REST end point of the microservice returns,

{"error":"Microservice/Bad gateway","message":"Microservice not available Connection refused : Connection refused: a2c-microservice-scope-xxx-prod.svc.cluster.local/80","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting"} 

I assume for some reason, the microservice I uploaded didn't start up properly. How can I enable any log to find out where goes wrong?


Solution

  • You just need to logg to stdout and then you can access the logs through the user interface in Cumulocity IoT. It is available through the application UI in administration

    LogViewer Cumulocity IoT

    Here a python example how to configure the logging:

    LOG_FORMATTER = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s]  %(message)s")
    
    LOGGER = logging.getLogger()
    LOGGER.setLevel(logging.DEBUG)
    CONSOLE_HANDLER = logging.StreamHandler(sys.stdout)
    CONSOLE_HANDLER.setFormatter(LOG_FORMATTER)
    LOGGER.addHandler(CONSOLE_HANDLER)