Skip to main content

axiom_logger

Python logging handler for the Axiom service (https://axiom.co/)

Installation

pip install axiom-logger

Usage

The handler overwrites the standard python Handler class from the logging module. As such it can be used in the same way as any other handler.

When instanciating the handler, you must pass the following arguments:

  • AXIOM_DATASET: The name of the dataset you want to push logs to
  • AXIOM_API_KEY: The API key for your Axiom account
import logging
import os
from axiom_logger import AxiomHandler

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
ah = AxiomHandler(
    os.environ.get('AXIOM_DATASET', 'test'),
    os.environ.get('AXIOM_API_TOKEN', 'xxxx-api-key-xxxx')
)
ah.setLevel(logging.DEBUG)
# create formatter and add it to the handlers
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ah.setFormatter(formatter)
# add the handlers to logger
logger.addHandler(ah)

Configuration options

The axiom logger provides some configuration options to customize the behaviour of the handler. While instantiating the handler the following additional parameters can be passed

  • api_url: String representing the URL of the Axiom API. Defaults to https://api.axiom.co/v1/datasets
  • mode: Either one of ['elapsed_time' | 'log_count']. Defaults to 'elapsed time'. Customizes the behaviour of the logger to send records every elapsed_time seconds or every log_count records.
  • elapsed_time: Float representing the number of seconds to wait before sending records to Axiom. Defaults to 10.
  • log_count: Integer representing the number of records to wait before sending records to Axiom. Defaults to 5.

To send a log to the Axiom service each time a record is emitted (sync procedure) the following configuration can be used:

AxiomHandler(
    os.environ.get('AXIOM_DATASET', 'test'),
    os.environ.get('AXIOM_API_TOKEN', None),
    mode='log_count',
    log_count=1
)

WARNING: If an async procedure is used an unexpected shutdown of the application may result in the loss of the logs contained in the record pool of the handler.

NOTE: If the procedure used to send logs to Axiom fails for any reason, the handler will issue a system warning stating the error occurred with the Axiom backend, and will also print the log records that failed to be sent.

Django integration

Since the handler is a standard python logging handler, it can be used in any python application. A worth mentioning example is the integration with Django.

To use the handler in a Django application, the following configuration can be used:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'axiom': {
            'class': 'axiom_logger.AxiomHandler',
            'dataset': os.getenv('AXIOM_DATASET', 'dataset-name'),
            'api_token': os.getenv('AXIOM_API_KEY', None)
        }
    },
    'root': {
        'handlers': ['axiom'],
        'level': 'WARNING',
    },
    'loggers': {
        'django': {
            'handlers': ['axiom'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
            'propagate': False,
        },
    },
}

Metadata

Release files for axiom-logger 1.0.3

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

Source distribution (sdist)

Source distribution for axiom-logger 1.0.3
File Size Uploaded
axiom_logger-1.0.3.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for axiom-logger 1.0.3
File Interpreter ABI Platform
axiom_logger-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / axiom_logger-1.0.3.tar.gz

Download URL axiom_logger-1.0.3.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
adfe0efa0d2cad0467065bf65bac7812bca3ab22adcc44da522f222a0cef20c6
BLAKE2b-256 checksum
How to use checksums
a8f6c2d9773ff9a78e107b50360bddef6d4ac2a9f055cd70ddd4da848b85e229
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / axiom_logger-1.0.3-py3-none-any.whl

Download URL axiom_logger-1.0.3-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3ec9a6f8d15fdc4590f4cbbde186173f6a093997334c095b9e3bfeda351ac6c
BLAKE2b-256 checksum
How to use checksums
0c4501a45bda5c6afdde706fc69164e2f79a40c0646754aa6aa318432f203217
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

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