{"library":"loki-logger-handler","title":"Loki Logger Handler","description":"Loki Logger Handler is a Python logging handler designed for transmitting logs to Grafana Loki. It formats logs in JSON by default, allows custom label definitions, and supports extracting extra keys from log records as labels or structured metadata. The library is currently at version 1.1.2 and appears to be under active development with regular updates addressing compatibility and feature enhancements.","language":"python","status":"active","last_verified":"Mon May 18","install":{"commands":["pip install loki-logger-handler"],"cli":null},"imports":["from loki_logger_handler.loki_logger_handler import LokiLoggerHandler","from loki_logger_handler.loki_logger_handler import LoggerFormatter","from loki_logger_handler.loki_logger_handler import LoguruFormatter"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import logging\nimport os\nfrom loki_logger_handler.loki_logger_handler import LokiLoggerHandler, LoggerFormatter\n\nLOKI_URL = os.environ.get('LOKI_URL', 'http://localhost:3100/loki/api/v1/push')\n\nlogger = logging.getLogger(__name__)\nlogger.setLevel(logging.INFO)\n\n# Configure Loki Handler\nloki_handler = LokiLoggerHandler(\n    url=LOKI_URL,\n    labels={\n        'application': 'my-python-app',\n        'environment': 'dev'\n    },\n    # Optionally, specify keys from 'extra' dict to be used as labels\n    label_keys={'user_id', 'request_id'},\n    # For Loki 3.0+ and structured metadata\n    # enable_structured_loki_metadata=True,\n    # loki_metadata_keys={'metadata_field'}\n)\n\n# Optionally, use a specific formatter (LoggerFormatter is default for standard logging)\nloki_handler.setFormatter(LoggerFormatter())\n\nlogger.addHandler(loki_handler)\n\n# Example logging\nlogger.info('Application started successfully.')\nlogger.warning('Potential issue detected.', extra={'user_id': '12345'})\n\ntry:\n    1 / 0\nexcept ZeroDivisionError:\n    logger.error('A critical error occurred!', exc_info=True, extra={'request_id': 'abc-123'})\n","lang":"python","description":"This quickstart demonstrates how to configure the `LokiLoggerHandler` with Python's standard `logging` module. It sets up a handler to send logs to a Loki instance, including static labels and dynamically extracting `extra` dictionary keys as labels. Ensure the `LOKI_URL` environment variable is set or replace the placeholder.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-18","installed_version":"1.1.2","pypi_latest":"1.1.2","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.5,"avg_import_s":null,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"loki-logger-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"loki-logger-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.4,"import_time_s":null,"mem_mb":null,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"loki-logger-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"loki-logger-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.5,"import_time_s":null,"mem_mb":null,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"loki-logger-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"loki-logger-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.4,"import_time_s":null,"mem_mb":null,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"loki-logger-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"11.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"loki-logger-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.4,"import_time_s":null,"mem_mb":null,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"loki-logger-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"loki-logger-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.7,"import_time_s":null,"mem_mb":null,"disk_size":"18M"}]}}