skip to navigation
skip to content

coralogix-logger 1.0.28

Coralogix Logger Python SDK

Table of contents

- Install

- General

- Python integration

- uWSGI

Install

$ pip install coralogix_logger

General

PRIVATE KEY - A unique ID which represents your company. This ID will be sent to your mail once you register to Coralogix.

APPLICATION NAME - The name of your main application. For example, a company named “SuperData” would probably insert the “SuperData” string parameter; or if they want to debug their test environment, they might insert the “SuperData – Test”.

SUBSYSTEM NAME - Your application probably has multiple subsystems. For example: Backend servers, Middleware, Frontend servers etc. In order to help you examine the data you need, inserting the subsystem parameter is vital.

Python integration

import logging
from coralogix.coralogix_logger import CoralogixLogger

PRIVATE_KEY = "[YOUR_PRIVATE_KEY_HERE]"
APP_NAME = "[YOUR_APPLICATION_NAME]"
SUB_SYSTEM = "[YOUR_SUBSYTEM_NAME]"

# Get an instance of Python standard logger.
logger = logging.getLogger("Python Logger")

# Get a new instance of Coralogix logger.
coralogix_handler = CoralogixLogger(PRIVATE_KEY, APP_NAME, SUB_SYSTEM)

# Add coralogix logger as a handler to the standard Python logger.
logger.addHandler(coralogix_handler)

# Send message
logger.info("Hello World!")

Configuration Under uWSGI

  • By default uWSGI does not enable threading support within the Python interpreter core. This means it is not possible to create background threads from Python code. As the Coralogix logger relies on being able to create background threads (for sending logs), this option is required.

You can enable threading either by passing –enable-threads to uWSGI command line:

$ uwsgi wsgi.ini --enable-threads

Another option is to enable threads in your wsgi.ini file:

wsgi.ini:
...
enable-threads = true
...
  • If you are using multiple processes/workers and you don’t use “lazy-apps = true” then you must wait for the process to finish the fork before you can send logs with Coralogix logger. You can configure the logger during initialization process, but you must wait for the fork to complete before you can actually send your logs. You can use uWSGI @postfork decorator to be sure when it’s safe to use Coralogx logger:
import uwsgi
from uwsgidecorators import *

@postfork
def on_worker_ready():
    #It is now safe to send logs with Coralogix logger
 
File Type Py Version Uploaded on Size
coralogix_logger-1.0.28-py2.py3-none-any.whl (md5) Python Wheel py2.py3 2017-08-23 11KB
coralogix_logger-1.0.28.tar.gz (md5) Source 2017-08-23 8KB