From f026b3a5c2d46fcfef36879dcd49813a7ed88a77 Mon Sep 17 00:00:00 2001 From: Mauricio Villegas <5780272+mauvilsa@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:50:53 +0100 Subject: [PATCH 1/2] Drop unmaintained logmatic --- .circleci/config.yml | 7 ++++++- .pre-commit-config.yaml | 4 ++-- reconplogger.py | 40 +++++++++++++++++++++++++++++++++++++++- setup.cfg | 9 +++++---- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f5f89c1..dadac06 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -29,6 +29,10 @@ jobs: root: . paths: - ./coverage_*.xml + test-py313: + <<: *test-py38 + docker: + - image: cimg/python:3.13 test-py312: <<: *test-py38 docker: @@ -57,7 +61,7 @@ jobs: command: | curl -Os https://uploader.codecov.io/latest/linux/codecov chmod +x codecov - for py in 3.8 3.9 3.10 3.11 3.12; do + for py in 3.8 3.9 3.10 3.11 3.12 3.13; do ./codecov \ --nonZero \ --token $CODECOV_TOKEN_RECONPLOGGER \ @@ -107,6 +111,7 @@ workflows: <<: *buildreq - codecov: requires: + - test-py313 - test-py312 - test-py311 - test-py310 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3de846e..ddb3f1d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,12 +15,12 @@ repos: exclude: .bumpversion.cfg - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.13 + rev: v0.8.4 hooks: - id: ruff args: ["--fix"] diff --git a/reconplogger.py b/reconplogger.py index dafe1f4..755f4c6 100644 --- a/reconplogger.py +++ b/reconplogger.py @@ -1,7 +1,9 @@ +import datetime import os import yaml import logging import logging.config +import pythonjsonlogger from contextlib import contextmanager from contextvars import ContextVar from importlib.util import find_spec @@ -47,7 +49,7 @@ def _request_patch(slf, *args, **kwargs): }, "json": { "format": reconplogger_format.replace("asctime", "timestamp"), - "class": "logmatic.JsonFormatter", + "class": "reconplogger.JsonFormatter", }, }, "handlers": { @@ -496,3 +498,39 @@ def rlogger(self, logger: Optional[Union[bool, logging.Logger]]): self._rlogger = logger_setup() else: self._rlogger = logger + + +class JsonFormatter(pythonjsonlogger.json.JsonFormatter): + """JSON formatter from https://github.com/logmatic/logmatic-python/ + + The MIT License (MIT) + Copyright (c) 2017 Logmatic.io + """ + + def __init__( + self, + fmt="%(asctime) %(name) %(processName) %(filename) %(funcName) %(levelname) %(lineno) %(module) %(threadName) %(message)", + datefmt="%Y-%m-%dT%H:%M:%SZ%z", + style="%", + extra={}, + *args, + **kwargs, + ): + self._extra = extra + pythonjsonlogger.json.JsonFormatter.__init__( + self, fmt=fmt, datefmt=datefmt, *args, **kwargs + ) + + def process_log_record(self, log_record): + # Enforce the presence of a timestamp + if "asctime" in log_record: + log_record["timestamp"] = log_record["asctime"] + else: + log_record["timestamp"] = datetime.datetime.now( + datetime.timezone.utc + ).strftime("%Y-%m-%dT%H:%M:%S.%fZ%z") + + if self._extra is not None: + for key, value in self._extra.items(): + log_record[key] = value + return super().process_log_record(log_record) diff --git a/setup.cfg b/setup.cfg index 987542d..5a048d5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,7 +5,7 @@ py_modules = test_suite = reconplogger_tests python_requires = >=3.8 install_requires = - logmatic-python>=0.1.7 + python-json-logger>=3.2.1 PyYAML>=3.13 @@ -56,11 +56,12 @@ classifiers = Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 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 Intended Audience :: Developers License :: OSI Approved :: MIT License Operating System :: POSIX :: Linux @@ -76,7 +77,7 @@ build_dir = sphinx/_build [tox:tox] -envlist = py{38,39,310,311,312},no-extras +envlist = py{38,39,310,311,312,313},no-extras [testenv] From 29928163358a9c22d8d640b7629e94a5d915aac0 Mon Sep 17 00:00:00 2001 From: Mauricio Villegas <5780272+mauvilsa@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:53:24 +0100 Subject: [PATCH 2/2] Fix circleci config --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index dadac06..8ec5730 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -101,6 +101,8 @@ workflows: only: /^v\d+\.\d+\.\d+.*$/ - test-py38: <<: *buildreq + - test-py313: + <<: *buildreq - test-py312: <<: *buildreq - test-py311: