Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
> Modern Python logging handler for Grafana Loki

[![PyPI version](https://img.shields.io/pypi/v/python-logging-loki-v2.svg)](https://pypi.org/project/python-logging-loki-v2/)
[![Python](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/)
[![Python](https://img.shields.io/badge/python-3.8.1+-blue.svg)](https://www.python.org/)

## Documented by Grafana: https://github.com/grafana/loki/pull/16397

Expand Down
7 changes: 3 additions & 4 deletions logging_loki/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import copy
import functools
import logging
import time
from logging.config import ConvertingDict
from typing import Any, Dict, List, Optional, Tuple

Expand All @@ -26,7 +25,7 @@ class LokiEmitter(abc.ABC):
label_replace_with = const.label_replace_with
session_class = requests.Session

def __init__(self, url: str, tags: dict | None = None, auth: BasicAuth = None, headers: dict | None = None, verify_ssl: bool = True):
def __init__(self, url: str, tags: Optional[dict] = None, auth: BasicAuth = None, headers: Optional[dict] = None, verify_ssl: bool = True):
"""
Create new Loki emitter.

Expand All @@ -47,7 +46,7 @@ def __init__(self, url: str, tags: dict | None = None, auth: BasicAuth = None, h
#: Verify the host's ssl certificate
self.verify_ssl = verify_ssl

self._session: requests.Session | None = None
self._session: Optional[requests.Session] = None

def __call__(self, record: logging.LogRecord, line: str):
"""Send log record to Loki."""
Expand Down Expand Up @@ -149,7 +148,7 @@ class LokiEmitterV2(LokiEmitterV1):
Enables passing additional headers to requests
"""

def __init__(self, url: str, tags: dict | None = None, auth: BasicAuth = None, headers: dict = None, verify_ssl: bool = True):
def __init__(self, url: str, tags: Optional[dict] = None, auth: BasicAuth = None, headers: Optional[dict] = None, verify_ssl: bool = True):
super().__init__(url, tags, auth, headers, verify_ssl)

def __call__(self, record: logging.LogRecord, line: str):
Expand Down
4 changes: 2 additions & 2 deletions logging_loki/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import warnings
from logging.handlers import QueueHandler, QueueListener
from queue import Queue
from typing import Dict, Type
from typing import Dict, Optional, Type

from logging_loki import const, emitter

Expand All @@ -29,7 +29,7 @@ class LokiHandler(logging.Handler):

emitters: Dict[str, Type[emitter.LokiEmitter]] = {"0": emitter.LokiEmitterV0, "1": emitter.LokiEmitterV1, "2": emitter.LokiEmitterV2}

def __init__(self, url: str, tags: dict | None = None, auth: emitter.BasicAuth | None = None, version: str | None = None, headers: dict | None = None, verify_ssl: bool = True):
def __init__(self, url: str, tags: Optional[dict] = None, auth: Optional[emitter.BasicAuth] = None, version: Optional[str] = None, headers: Optional[dict] = None, verify_ssl: bool = True):
"""
Create new Loki logging handler.

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ build-backend = "setuptools.build_meta"

[tool.ruff]
line-length = 200
# Lowest supported interpreter; keeps pyupgrade rules from
# rewriting code into 3.9+ only syntax.
target-version = "py38"

[tool.ruff.lint]
# Enable flake8-style rules and more
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@
author_email="cryos10@gmail.com",
url="https://github.com/RomanR-dev/python-logging-loki",
packages=setuptools.find_packages(exclude=("tests",)),
python_requires=">=3.11",
python_requires=">=3.8.1,<4.0",
install_requires=["rfc3339>=6.1", "requests"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Logging",
"Topic :: Internet :: WWW/HTTP",
Expand Down
15 changes: 13 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
[tox]
# List of Python versions to test against
envlist = py311,py312,ruff
envlist = py38,py39,py310,py311,py312,py313,ruff
isolated_build = true

[gh-actions]
# Map the CI job's interpreter to the envs it should run, so each matrix
# entry runs its own testenv instead of skipping the rest of the envlist.
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311, ruff
3.12: py312
3.13: py313

[testenv]
setenv =
LC_ALL = en_US.UTF-8
Expand All @@ -19,7 +30,7 @@ commands =
[testenv:ruff]
skip_install = true
# Use whatever python3 is available on your system
basepython = python3.11
basepython = python3
deps = ruff
commands =
# First fix auto-fixable issues
Expand Down