Registry / observability / cmreshandler

cmreshandler

JSON →
library1.0.0pypypiunverified

CMRESHandler is a Python library that provides an Elasticsearch logging appender compatible with the standard `logging` library. It enables logging application events to Elasticsearch in JSON format, supporting various authentication types (Basic, Kerberos, AWS Signed) and flexible index naming frequencies (daily, weekly, monthly, yearly). The library is currently at version 1.0.0, released in 2017. Although functional, the project appears to be unmaintained, with a community fork existing due to its lack of active development.

pip install CMRESHandler
INSTALL
IMPORT
SIG · CMRESHANDLER
C
cmreshandler
observabilitypythonv1.0.0
Install
3.2s avg
Import
Disk
34MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 35.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.2s · import 0.000s · 36MB
34MB installed
● package 34MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CMRESHandler
from cmreslogging.handlers import CMRESHandler
from cmreslogging import CMRESHandler

This quickstart demonstrates how to configure and use CMRESHandler with basic authentication (if environment variables are set) to send log messages to an Elasticsearch instance. Logs will include additional custom fields and exceptions will be sent with full tracebacks. The `flush_frequency_in_sec` is set to 1 for quick testing, but should be adjusted for production.

import logging import os from cmreslogging.handlers import CMRESHandler # Configure basic logging log = logging.getLogger("PythonTest") log.setLevel(logging.INFO) # Elasticsearch host configuration ES_HOST = os.environ.get('ES_HOST', 'localhost') ES_PORT = int(os.environ.get('ES_PORT', 9200)) ES_INDEX_NAME = os.environ.get('ES_INDEX_NAME', 'python_app_logs') # Optional: Basic Auth details ES_USER = os.environ.get('ES_USER') ES_PASSWORD = os.environ.get('ES_PASSWORD') hosts = [{'host': ES_HOST, 'port': ES_PORT}] auth_type = CMRESHandler.AuthType.NO_AUTH auth_details = None if ES_USER and ES_PASSWORD: auth_type = CMRESHandler.AuthType.BASIC_AUTH auth_details = (ES_USER, ES_PASSWORD) try: handler = CMRESHandler( hosts=hosts, auth_type=auth_type, auth_details=auth_details, es_index_name=ES_INDEX_NAME, es_additional_fields={'App': 'MyAppName', 'Environment': 'Dev'}, # Ensure flush frequency is reasonable for testing flush_frequency_in_sec=1 ) log.addHandler(handler) log.info("This is an info statement that will be logged into Elasticsearch.") log.warning("A warning message from the application.") try: 1 / 0 except ZeroDivisionError: log.exception("An exception occurred, should be logged with traceback.") print("Log messages sent to Elasticsearch (check your ES_INDEX_NAME in Elasticsearch).") # In a real application, you might need a small delay or explicit flush # if the application exits immediately after logging. # For this quickstart, we rely on flush_frequency_in_sec. except Exception as e: print(f"Failed to initialize CMRESHandler or send logs: {e}") print("Ensure Elasticsearch is running and accessible at {ES_HOST}:{ES_PORT}.")
Debug
Known issues
breakingOlder Elasticsearch versions used `_type` in bulk requests. This is deprecated in newer Elasticsearch versions (e.g., 6.x and above) in favor of a single `_doc` type or removing types entirely. This handler might send deprecated `_type` fields, leading to warnings or errors in modern Elasticsearch clusters.
fix
There is no direct fix within CMRESHandler as the project is unmaintained. Consider migrating to a maintained Elasticsearch logging library or forking and modifying the handler's serialization logic to remove the deprecated `_type` field.
affects: <=1.0.0 with Elasticsearch >=6.x
gotchaLogs might not appear immediately in Elasticsearch because CMRESHandler buffers messages and flushes them periodically or when the buffer is full. If an application exits before a flush, buffered logs may be lost.
fix
Set `flush_frequency_in_sec` to a low value (e.g., 1 second) during development or for applications with short lifespans. For critical logs, consider explicitly calling `handler.flush()` before application exit, though this might not be thread-safe depending on implementation details.
affects: All versions
deprecatedThe `threading.Thread.setDaemon` method, potentially used internally by CMRESHandler for its buffer flushing thread, has been deprecated in Python 3.10. Running the library on Python 3.10+ might produce deprecation warnings.
fix
No direct fix for users. This requires a change in the library's source code to set the `daemon` attribute directly during thread initialization. As the project is unmaintained, consider using a different logging handler or forking the library.
affects: All versions with Python >=3.10
breakingThe `RequestsHttpConnection` import path within the `elasticsearch` client library has changed across major versions. Older versions of CMRESHandler might fail to import if the installed `elasticsearch` client library is too new.
fix
Downgrade your `elasticsearch` client library to a version compatible with `cmreshandler` (e.g., `pip install elasticsearch<7.0.0`) or update the `cmreslogging/handlers.py` source code to reflect the current import path (e.g., `from elasticsearch.connection import RequestsHttpConnection`).
affects: All versions with `elasticsearch` client library >= 7.x
Upgrade
Version history
1.0.0latest on PyPI · released Oct 8, 2017
Audit
Dependencies
elasticsearchrequiredCore dependency for connecting to Elasticsearch.
requestsrequiredUsed for HTTP communication with Elasticsearch.
enumoptionalRequired for Python 2; built-in for Python 3.
requests-kerberosoptionalOptional dependency for Kerberos authentication.
requests-aws4authoptionalOptional dependency for AWS IAM user authentication.
Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources