diff --git a/.travis.yml b/.travis.yml index bfb95b6..5eba495 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ python: - "3.8" - "3.9" - "3.10" + - "3.11" cache: pip: true diff --git a/.vscode/settings.json b/.vscode/settings.json index 89b45c1..d103b16 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,15 +1,87 @@ { - "cSpell.words": [ - "caplog", - "coveragerc", - "freezegun", - "minilog", - "minimalistic", - "mkdocs", - "mypy", - "sinfo", - "USERPROFILE", - "venv", - "verchew" - ] + "files.exclude": { + ".cache/": true, + ".venv/": true, + "*.egg-info": true, + "pip-wheel-metadata/": true, + "**/__pycache__": true, + "**/*.pyc": true, + "**/.ipynb_checkpoints": true, + "**/tmp/": true, + "dist/": true, + "htmlcov/": true, + "prof/": true, + "site/": true, + "geckodriver.log": true + }, + "python.defaultInterpreterPath": ".venv/bin/python", + "editor.formatOnSave": true, + "pylint.args": ["--rcfile=.pylint.ini"], + "cSpell.words": [ + "appex", + "autorefs", + "builtins", + "classproperties", + "codehilite", + "completly", + "cookiecutter", + "coveragerc", + "cygstart", + "cygwin", + "dataclass", + "dataclasses", + "datafile", + "ensurepip", + "findstr", + "fontawesome", + "freezegun", + "gethostname", + "getpid", + "getplugin", + "gitman", + "gitsvn", + "Graphviz", + "iglob", + "imac", + "importlib", + "ioreg", + "iphoto", + "ipython", + "levelname", + "logbreak", + "macbook", + "MDEF", + "mkdocs", + "mkdocstrings", + "mrpossoms", + "mylink", + "mypy", + "noclasses", + "nohup", + "pipx", + "pluginmanager", + "preserialization", + "Preserialized", + "Preserializing", + "psutil", + "repr", + "ruamel", + "rustup", + "scalarstring", + "showfspath", + "startfile", + "tomlkit", + "tput", + "tracebackhide", + "Trilean", + "trufflehog", + "udevadm", + "unparseable", + "USERPROFILE", + "venv", + "verchew", + "verchewrc", + "webfonts", + "YORM" + ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fcf28b..3112711 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes +## 2.3 (2023-12-09) + +- Added automatic formatting for dataclasses. + ## 2.2 (2023-06-29) - Dropped support for Python 3.7. diff --git a/docs/requirements.txt b/docs/requirements.txt index a6044b6..0cce57e 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,3 +1,3 @@ mkdocs==1.2.3 ; python_version >= "3.8" and python_version < "4.0" -pygments==2.9.0 ; python_version >= "3.8" and python_version < "4.0" +pygments==2.15.0 ; python_version >= "3.8" and python_version < "4.0" jinja2==3.0.1 ; python_version >= "3.8" and python_version < "4.0" diff --git a/log/tests/test_utils.py b/log/tests/test_utils.py index 75cd6e1..d181e02 100644 --- a/log/tests/test_utils.py +++ b/log/tests/test_utils.py @@ -1,6 +1,7 @@ -# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned,singleton-comparison +# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned,singleton-comparison,disallowed-name import logging +from dataclasses import dataclass from log.utils import create_logger_record, format_message, parse_name @@ -36,5 +37,15 @@ def it_formats_structures(expect): data = {x: x * 10 for x in range(20)} expect(format_message(data).count("\n")) == 19 + def it_formats_dataclasses(expect): + @dataclass + class Example: + foo: int = 1 + bar: str = "abc" + + example = Example() + + expect(format_message(example)) == "{'bar': 'abc', 'foo': 1}" + def it_preserves_strings(expect): expect(format_message("foobar")) == "foobar" diff --git a/log/utils.py b/log/utils.py index de8b9fc..d790dce 100644 --- a/log/utils.py +++ b/log/utils.py @@ -1,5 +1,6 @@ """Implements the "magic" to create `logging` records for the caller.""" +import dataclasses import inspect import logging from pprint import pformat @@ -63,6 +64,8 @@ def parse_filename(frame_info: Dict) -> str: def format_message(value) -> str: + if dataclasses.is_dataclass(value): + value = dataclasses.asdict(value) if not isinstance(value, str): value = pformat(value) return value diff --git a/pyproject.toml b/pyproject.toml index 068fbee..5418efe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "minilog" -version = "2.2" +version = "2.3" description = "Minimalistic wrapper for Python logging." license = "MIT" @@ -26,6 +26,7 @@ classifiers = [ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Programming Language :: Python", "Topic :: Software Development", "Topic :: System :: Logging",