Skip to content

Commit

Permalink
Drop unmaintained logmatic (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvilsa authored Dec 20, 2024
1 parent 3de9f08 commit 16754ed
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
9 changes: 8 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
root: .
paths:
- ./coverage_*.xml
test-py313:
<<: *test-py38
docker:
- image: cimg/python:3.13
test-py312:
<<: *test-py38
docker:
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -97,6 +101,8 @@ workflows:
only: /^v\d+\.\d+\.\d+.*$/
- test-py38:
<<: *buildreq
- test-py313:
<<: *buildreq
- test-py312:
<<: *buildreq
- test-py311:
Expand All @@ -107,6 +113,7 @@ workflows:
<<: *buildreq
- codecov:
requires:
- test-py313
- test-py312
- test-py311
- test-py310
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
40 changes: 39 additions & 1 deletion reconplogger.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -47,7 +49,7 @@ def _request_patch(slf, *args, **kwargs):
},
"json": {
"format": reconplogger_format.replace("asctime", "timestamp"),
"class": "logmatic.JsonFormatter",
"class": "reconplogger.JsonFormatter",
},
},
"handlers": {
Expand Down Expand Up @@ -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)
9 changes: 5 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit 16754ed

Please sign in to comment.