{"id":4913,"library":"coralogix-logger","title":"Coralogix Python SDK","description":"The Coralogix Python SDK enables sending logs directly from Python applications to the Coralogix platform. It leverages Python's standard logging library and operates asynchronously using a dedicated thread for log buffering and flushing. The current version is 2.1.1, and the library is actively maintained with regular updates.","status":"active","version":"2.1.1","language":"en","source_language":"en","source_url":"https://github.com/coralogix/python-coralogix-sdk","tags":["logging","observability","logs","coralogix","sdk"],"install":[{"cmd":"pip install coralogix-logger","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Importing from `coralogix.coralogix_logger` is deprecated and will be removed in future versions. Use `coralogix.handlers` instead.","wrong":"from coralogix.coralogix_logger import CoralogixLogger","symbol":"CoralogixLogger","correct":"from coralogix.handlers import CoralogixLogger"}],"quickstart":{"code":"import logging\nimport os\nimport json\nfrom coralogix.handlers import CoralogixLogger\n\nPRIVATE_KEY = os.environ.get('CORALOGIX_PRIVATE_KEY', 'YOUR_PRIVATE_KEY')\nAPP_NAME = os.environ.get('CORALOGIX_APP_NAME', 'my-python-app')\nSUB_SYSTEM = os.environ.get('CORALOGIX_SUB_SYSTEM', 'my-subsystem')\nREGION = os.environ.get('CORALOGIX_REGION', 'EU1') # e.g., 'EU1', 'US1', 'AP1'\n\n# Get an instance of Python standard logger.\nlogger = logging.getLogger(\"Python Logger\")\nlogger.setLevel(logging.DEBUG)\n\n# Get a new instance of Coralogix logger.\n# Region is required as of SDK version 2.1.0\ncoralogix_handler = CoralogixLogger(PRIVATE_KEY, APP_NAME, SUB_SYSTEM, region=REGION)\n\n# Add coralogix logger as a handler to the standard Python logger.\nlogger.addHandler(coralogix_handler)\n\n# Send messages\nlogger.info(\"Hello World from Coralogix Python SDK!\")\nmy_dict = {\"host\": \"localhost\", \"message\": \"This is a structured log.\"}\nlogger.info(json.dumps(my_dict))\n\n# Manually flush logger to ensure logs are sent before application exit\nCoralogixLogger.flush_messages()\nprint(\"Logs sent to Coralogix.\")","lang":"python","description":"This quickstart demonstrates how to initialize the Coralogix logger and send basic log messages. It configures a standard Python logger with the Coralogix handler, setting the necessary API key, application name, subsystem, and region. Environment variables are used for sensitive credentials. Logs are explicitly flushed to ensure delivery."},"warnings":[{"fix":"Initialize `CoralogixLogger` with the `region` parameter (e.g., `region=\"EU1\"`) or set the `CORALOGIX_REGION` environment variable.","message":"As of SDK version 2.1.0, it is required to specify your Coralogix region during initialization. Failing to do so will result in logs not being sent to the correct regional endpoint.","severity":"breaking","affected_versions":">=2.1.0"},{"fix":"Update your imports to `from coralogix.handlers import CoralogixLogger`.","message":"Importing `CoralogixLogger` directly from `coralogix.coralogix_logger` is deprecated and will be removed in future versions.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Add `enable-threads = true` to your `wsgi.ini` file or ensure threading is enabled in your uWSGI configuration.","message":"When using uWSGI, threading support must be explicitly enabled, as the Coralogix logger relies on a background thread for sending logs.","severity":"gotcha","affected_versions":"All"},{"fix":"Call `CoralogixLogger.flush_messages()` before your application exits to ensure all buffered logs are sent.","message":"Logs might not be sent immediately upon calling logging methods due to the asynchronous nature of the SDK. For scripts or applications that exit quickly, ensure logs are flushed manually.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}