Configure Python Logging
  • 1 Minute to read
  • Dark
    Light
  • PDF

Configure Python Logging

  • Dark
    Light
  • PDF

Article summary

To configure your Python application, an Application Programming Interface (API) can be used to send Errors and Logs to Retrace. The step-by-step process is presented below and for more information, visit this Stackify API for Python Github page: https://github.com/stackify/stackify-api-python.

Installation and Configuration

Python Logging Integration

Python logging can be setup to extend an existing logger by adding a handler.

Install stackify-api-python module:

pip install stackify-api-python

Adjust your application to use the StackifyHandler:

import logging
import stackify
logger = logging.getLogger()
stackify_handler = stackify.StackifyHandler(application="Python Application", environment="Production", api_key="***")
logger.addHandler(stackify_handler)
logger.warning('Something happened')

Standard API

Python logging can use the Stackify logger directly if no existing logger is present in your application.

Install stackify-api-python module:

pip install stackify-api-python

Adjust your appliation to use the Stackify logger directly:

import stackify
logger = stackify.getLogger(application="Python Application", environment="Production", api_key="***")
logger.warning('Something happened')

Troubleshooting

If there are problems, you can enable internal logging of the stackify-api-python project.

import logging
logging.getLogger('stackify').setLevel(logging.DEBUG)

Was this article helpful?

What's Next