Skip to main content

Overview

Spectrum is a application that helps developers filter and sift through logs while developing or debugging locally. It accepts logging information via a REST API, syslog, or can be set to tail local files. All of these logging sources are then easily shown or hidden depending on the current needs of the developer.

This Python package makes it trivially easy to push logs from Python and/or Django into Spectrum.

Python

Installing Python support for Spectrum is as easy as:

$ pip install spectrum-python

Setting up a logging handler is also equally easy:

import logging
from spectrum.handlers import Spectrum

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

spectrum = Spectrum('my-logging-sublevel')
logger.addHandler(spectrum)

for i in range(5):
    logger.info("This would be sent as INFO.my-logging-sublevel")
    logger.warn("This would be sent as WARNING.my-logging-sublevel")
    logger.debug("This would be sent as DEBUG.my-logging-sublevel")

Options

url

IP and PORT of the REST API to use. Defaults to ‘http://0.0.0.0:9000’. You must override this to the proper Spectrum port associated to your stream if using more than one REST API Stream

sublevel

Optional sub-level to use for this handler. Defaults to ‘<untitled>’ in the Spectrum UI if not given.

Django

To direct all logging from your Django project to Spectrum, you can use the predefined FIRE_HOSE logging configuration in your settings:

# settings.py

from spectrum.django import FIRE_HOSE
LOGGING = FIRE_HOSE

If you use celery, you’ll have one more setting to add:

CELERYD_HIJACK_ROOT_LOGGER = False

You can also use the fire_hose convenience method to quickly modify any of the pre-built logging configuration dict:

from spectrum.django import fire_hose


LOGGING = fire_hose()

LOGGING = fire_hose(log_db=False)

LOGGING = fire_hose(levels=(
    ('my.overly.verbose.module', 'WARNING'),
    ('some.other.module', 'CRITICAL'),
)

LOGGING = fire_hose(handler_kwargs={'url': '127.0.0.1:12345'})

If you prefer a more granular approach, you can configure specific handlers:

# settings.py

LOGGING = {
    ...
    'filters': {
        'request_id': {
            '()': 'spectrum.filters.RequestIdFilter'
        }
    },
    'handlers': {
        'myloggername': {
            'level': 'DEBUG',
            'class': 'spectrum.handlers.RestSpectrum',
            'sublevel': 'myloggername',
            'filters': ['request_id']
        }
    }
}

Make sure you include the request_id filter to filter out spectrum’s own requests from the other. Otherwise, Spectrum’s requests will be logged by Python, and those logs will in turn generate their own Spectrum request, causing and infinite recursion.

Release files for spectrum-python 0.9.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spectrum-python 0.9.8
File Size Uploaded
spectrum-python-0.9.8.tar.gz 7.5 kB Details

Release files / spectrum-python-0.9.8.tar.gz

Download URL spectrum-python-0.9.8.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6858ac46b2a11533e247d3636435779fbb0bf69bcb1c3f88cb524101548ac2dd
BLAKE2b-256 checksum
How to use checksums
b2eb4d32e1e06fc76f40606533a4397076fa329b229b63d157ae5a5e7619a800
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.9.8 This release

1 release file

0.9.6

1 release file

0.9.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page