typelog


Nametypelog JSON
Version 0.3.0 PyPI version JSON
download
home_page
SummaryStatic typed structured logging
upload_time2024-02-23 21:35:38
maintainer
docs_urlNone
author
requires_python>=3.8
licenseThe MIT License (MIT) Copyright (c) 2024 dd84ai / https://github.com/darklab8/darklab_py-typelog Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords logging structured typing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Typelog - Static typed structured logging

## Description

This project araised from the need to log backend applications, aws lambdas and other stuff in modern cloud ecosystem. Logging systems today are able easily parsing JSON format out of the box.
Static typing approach brings here consistent way to define key values to final msg, as well as easier following Domain Driven Design, where logs consistently describe what they log. Static typed logging brings easy refactoring to any present logs.

## Features

- Accepts static typed components as optional params
  - it will not accept `any` options
  - has shortcut WithFields, to make clone of the logger with default logging fields
- Easy to turn on/off parameters by environment variables
  - Ability to define different log levels for different created loggers
- Easier turning complex objects into structured logging
  - accepts maps and structs as its params. It will parse them on their own.
[See folder for up to date examples](./examples)

## Alternative Versions

- [Version in golang](https://github.com/darklab8/go-typelog)

## Python specifics

- In order to function with python extra well, recommendation to turn on
  - [strict mypy](<https://careers.wolt.com/en/blog/tech/professional-grade-mypy-configuration>)
  - or pyright in one of [its mods](<https://github.com/microsoft/pyright/blob/main/docs/configuration.md>)
- [Published at pypi](https://pypi.org/project/typelog/)

## How to use

install with `pip install typelog`

examples/types.py
```py
from dataclasses import dataclass
from typing import NewType

TaskID = NewType("TaskID", int)


@dataclass(frozen=True)
class Task:
    smth: str
    b: int
```

examples/logtypes.py
```py
from typing import Any, Dict

from typelog import LogType

from . import types


def TaskID(value: types.TaskID) -> LogType:
    def wrapper(params: Dict[str, Any]) -> None:
        params["task_id"] = str(value)

    return wrapper


def Task(value: types.Task) -> LogType:
    def wrapper(params: Dict[str, Any]) -> None:
        params.update(value.__dict__)

    return wrapper
```

examples/test_examples.py
```py
import logging
import unittest

import typelog
from typelog import LogConfig, Loggers, get_logger
from typelog.types import LibName, LogLevel, RootLogLevel

from . import logtypes, types

logger = get_logger(__name__)


class TestExamples(unittest.TestCase):
    def setUp(self) -> None:
        Loggers(
            RootLogLevel(logging.DEBUG),
            LogConfig(LibName("examples"), LogLevel(logging.DEBUG)),
            add_time=True,
        ).configure()

    def test_basic(self) -> None:
        logger.warn("Writing something", logtypes.TaskID(types.TaskID(123)))

    def test_another_one(self) -> None:
        task = types.Task(smth="abc", b=4)
        logger.warn("Writing something", logtypes.Task(task))

    def test_with_fields(self) -> None:
        logger2 = logger.with_fields(logtypes.Task(types.Task(smth="aaa", b=1)))
        logger3 = logger.with_fields(
            typelog.String("smth", "asd"), typelog.Int("number", 2)
        )

        logger.info("logger printed")
        logger2.info("logger2 printed")
        logger3.info("logger3 printed")
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "typelog",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "logging,structured,typing",
    "author": "",
    "author_email": "dd84ai <dark.dreamflyer@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fe/ed/625a97be9b68a98e7baf221722853ad1e2d3013fac8e14b2a5b478487ebb/typelog-0.3.0.tar.gz",
    "platform": null,
    "description": "# Typelog - Static typed structured logging\n\n## Description\n\nThis project araised from the need to log backend applications, aws lambdas and other stuff in modern cloud ecosystem. Logging systems today are able easily parsing JSON format out of the box.\nStatic typing approach brings here consistent way to define key values to final msg, as well as easier following Domain Driven Design, where logs consistently describe what they log. Static typed logging brings easy refactoring to any present logs.\n\n## Features\n\n- Accepts static typed components as optional params\n  - it will not accept `any` options\n  - has shortcut WithFields, to make clone of the logger with default logging fields\n- Easy to turn on/off parameters by environment variables\n  - Ability to define different log levels for different created loggers\n- Easier turning complex objects into structured logging\n  - accepts maps and structs as its params. It will parse them on their own.\n[See folder for up to date examples](./examples)\n\n## Alternative Versions\n\n- [Version in golang](https://github.com/darklab8/go-typelog)\n\n## Python specifics\n\n- In order to function with python extra well, recommendation to turn on\n  - [strict mypy](<https://careers.wolt.com/en/blog/tech/professional-grade-mypy-configuration>)\n  - or pyright in one of [its mods](<https://github.com/microsoft/pyright/blob/main/docs/configuration.md>)\n- [Published at pypi](https://pypi.org/project/typelog/)\n\n## How to use\n\ninstall with `pip install typelog`\n\nexamples/types.py\n```py\nfrom dataclasses import dataclass\nfrom typing import NewType\n\nTaskID = NewType(\"TaskID\", int)\n\n\n@dataclass(frozen=True)\nclass Task:\n    smth: str\n    b: int\n```\n\nexamples/logtypes.py\n```py\nfrom typing import Any, Dict\n\nfrom typelog import LogType\n\nfrom . import types\n\n\ndef TaskID(value: types.TaskID) -> LogType:\n    def wrapper(params: Dict[str, Any]) -> None:\n        params[\"task_id\"] = str(value)\n\n    return wrapper\n\n\ndef Task(value: types.Task) -> LogType:\n    def wrapper(params: Dict[str, Any]) -> None:\n        params.update(value.__dict__)\n\n    return wrapper\n```\n\nexamples/test_examples.py\n```py\nimport logging\nimport unittest\n\nimport typelog\nfrom typelog import LogConfig, Loggers, get_logger\nfrom typelog.types import LibName, LogLevel, RootLogLevel\n\nfrom . import logtypes, types\n\nlogger = get_logger(__name__)\n\n\nclass TestExamples(unittest.TestCase):\n    def setUp(self) -> None:\n        Loggers(\n            RootLogLevel(logging.DEBUG),\n            LogConfig(LibName(\"examples\"), LogLevel(logging.DEBUG)),\n            add_time=True,\n        ).configure()\n\n    def test_basic(self) -> None:\n        logger.warn(\"Writing something\", logtypes.TaskID(types.TaskID(123)))\n\n    def test_another_one(self) -> None:\n        task = types.Task(smth=\"abc\", b=4)\n        logger.warn(\"Writing something\", logtypes.Task(task))\n\n    def test_with_fields(self) -> None:\n        logger2 = logger.with_fields(logtypes.Task(types.Task(smth=\"aaa\", b=1)))\n        logger3 = logger.with_fields(\n            typelog.String(\"smth\", \"asd\"), typelog.Int(\"number\", 2)\n        )\n\n        logger.info(\"logger printed\")\n        logger2.info(\"logger2 printed\")\n        logger3.info(\"logger3 printed\")\n```\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2024 dd84ai / https://github.com/darklab8/darklab_py-typelog  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Static typed structured logging",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/darklab8/py-typelog"
    },
    "split_keywords": [
        "logging",
        "structured",
        "typing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4a185bbc1e0a2665477e1d229453ecaf435643681b78a52eff03cf90c9711c9",
                "md5": "df81e4df07d4422dfe5e1338f38fa2fd",
                "sha256": "523a54a663798c3cccd7710ae63db4d6167bcfb8e2ee38f7a2fe8f6adedad0b3"
            },
            "downloads": -1,
            "filename": "typelog-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "df81e4df07d4422dfe5e1338f38fa2fd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7647,
            "upload_time": "2024-02-23T21:35:36",
            "upload_time_iso_8601": "2024-02-23T21:35:36.837883Z",
            "url": "https://files.pythonhosted.org/packages/c4/a1/85bbc1e0a2665477e1d229453ecaf435643681b78a52eff03cf90c9711c9/typelog-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "feed625a97be9b68a98e7baf221722853ad1e2d3013fac8e14b2a5b478487ebb",
                "md5": "30f6fcf2fc8fb11b5b47e979e325b7f5",
                "sha256": "9ecc5f8c07a242a6fffaccb072deefedbd2bea35167b228ed403d8859fc53658"
            },
            "downloads": -1,
            "filename": "typelog-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "30f6fcf2fc8fb11b5b47e979e325b7f5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10565,
            "upload_time": "2024-02-23T21:35:38",
            "upload_time_iso_8601": "2024-02-23T21:35:38.830178Z",
            "url": "https://files.pythonhosted.org/packages/fe/ed/625a97be9b68a98e7baf221722853ad1e2d3013fac8e14b2a5b478487ebb/typelog-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-23 21:35:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "darklab8",
    "github_project": "py-typelog",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "typelog"
}
        
Elapsed time: 0.25199s