Skip to main content

Coralogix Logger Python SDK

Project description

http://res.cloudinary.com/coralogix/image/upload/v1482035757/logos_yjmwij.png

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coralogix_logger-1.1.0.tar.gz (8.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page