nrt-logging


Namenrt-logging JSON
Version 1.3.5 PyPI version JSON
download
home_pagehttps://github.com/etuzon/python-nrt-logging
SummaryHierarchical logging in yaml format
upload_time2024-04-22 13:46:14
maintainerNone
docs_urlNone
authorEyal Tuzon
requires_python>=3.9
licenseNone
keywords python python3 python-3 logging logger log loggers hierarchical logging-library logging-framework hierarchy yaml nrt nrt-logging
VCS
bugtrack_url
requirements PyYAML schema
Travis-CI No Travis.
coveralls test coverage
            # Hierarchical logging in yaml format.

![PyPI](https://img.shields.io/pypi/v/nrt-logging?color=blueviolet&style=plastic)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/nrt-logging?color=greens&style=plastic)
![PyPI - License](https://img.shields.io/pypi/l/nrt-logging?color=blue&style=plastic)
![PyPI - Downloads](https://img.shields.io/pypi/dd/nrt-logging?style=plastic)
![PyPI - Downloads](https://img.shields.io/pypi/dm/nrt-logging?color=yellow&style=plastic)
[![Coverage Status](https://coveralls.io/repos/github/etuzon/nrt-logging/badge.svg)](https://coveralls.io/github/etuzon/pytohn-nrt-logging)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/etuzon/python-nrt-logging?style=plastic)
![GitHub last commit](https://img.shields.io/github/last-commit/etuzon/python-nrt-logging?style=plastic)
[![DeepSource](https://deepsource.io/gh/etuzon/python-nrt-logging.svg/?label=active+issues&token=3pUgM1IEwZG6Gpuc065dKDxM)](https://deepsource.io/gh/etuzon/python-nrt-logging/?ref=repository-badge)

Hierarchical logging help to group logs that are related to the same code flow.

Log style can be styled in Yaml format or in Line format.

### Examples:

#### Output in YAML style

```Python
from nrt_logging.logger import NrtLogger
from nrt_logging.logger_manager import logger_manager
from nrt_logging.logger_stream_handlers import ManualDepthEnum

NAME_1 = 'TEST1'
NAME_2 = 'TEST2'


class Child:
    __logger: NrtLogger

    def __init__(self):
        self.__logger = logger_manager.get_logger(NAME_1)

    def child_1(self):
        self.__logger.info('Child 1')
        self.child_2()

    def child_2(self):
        self.__logger.info('Child 2')


class Parent:
    MSG_1 = 'MSG_1'
    MSG_2 = 'MSG_2'
    MSG_3 = 'MSG_3'
    INCREASE_MSG = 'INCREASE_MSG'
    DECREASE_MSG = 'DECREASE_MSG'

    __logger: NrtLogger
    __child: Child

    def __init__(self):
        self.__logger = logger_manager.get_logger(NAME_1)
        self.__child = Child()

    def a1(self):
        self.__logger.warn(self.MSG_1)
        self.__child.child_1()

    def a2_manual(self):
        self.__logger.info(self.MSG_2)
        self.__logger.increase_depth()
        self.__logger.info(self.INCREASE_MSG)
        self.__logger.decrease_depth()
        self.__logger.info(self.DECREASE_MSG)
        self.__logger.error(self.MSG_1)
        self.a1()

    def a3_manual(self):
        self.__logger.info(self.MSG_2)
        self.__logger.increase_depth()
        self.__logger.info(self.INCREASE_MSG)
        self.__logger.decrease_depth()
        self.__logger.info(self.DECREASE_MSG)
        self.__logger.error(self.MSG_3)

    def a4_manual(self):
        self.__logger.info(self.MSG_1)
        self.__logger.info(self.INCREASE_MSG, ManualDepthEnum.INCREASE)
        self.__logger.info(self.DECREASE_MSG, ManualDepthEnum.DECREASE)
        self.__logger.error(self.MSG_2)
```

```Python
from examples.demo_classes.demo_classes import NAME_1, Parent
from nrt_logging.logger_manager import logger_manager
from nrt_logging.logger_stream_handlers import \
    ConsoleStreamHandler, LogStyleEnum


def logging_style(log_style: LogStyleEnum):
    sh = ConsoleStreamHandler()
    sh.style = log_style
    logger = logger_manager.get_logger(NAME_1)
    logger.add_stream_handler(sh)
    p = Parent()
    p.a1()


def logging_line_style():
    logging_style(LogStyleEnum.LINE)


def logging_yaml_style():
    logging_style(LogStyleEnum.YAML)


logging_yaml_style()
```

Output
```YAML
---
date: 2022-10-31 17:59:04.653084
log_level: WARN
path: demo_classes.py.Parent
method: a1
line_number: 38
message: MSG_1
children:
  - date: 2022-10-31 17:59:04.655071
    log_level: INFO
    path: demo_classes.py.Child
    method: child_1
    line_number: 16
    message: Child 1
    children:
      - date: 2022-10-31 17:59:04.656137
        log_level: INFO
        path: demo_classes.py.Child
        method: child_2
        line_number: 20
        message: Child 2
```

#### Output in LINE style

```YAML
- log: 2022-10-31 18:16:54.033735 [WARN] [demo_classes.py.Parent.a1:38] MSG_1
  children:
    - log: 2022-10-31 18:16:54.034660 [INFO] [demo_classes.py.Child.child_1:16] Child 1
      children:
        - log: 2022-10-31 18:16:54.036723 [INFO] [demo_classes.py.Child.child_2:20] Child 2
```

```Python
from nrt_logging.log_level import LogLevelEnum
from nrt_logging.logger_manager import logger_manager
from nrt_logging.logger_stream_handlers import \
    ConsoleStreamHandler, LogStyleEnum


sh = ConsoleStreamHandler()
sh.log_level = LogLevelEnum.TRACE
sh.style = LogStyleEnum.LINE
logger = logger_manager.get_logger('NAME_1')
logger.add_stream_handler(sh)

logger.info('main level log')
logger.increase_depth()
logger.info('child 1')
logger.increase_depth()
logger.info('child 1_1')
logger.decrease_depth()
logger.info('child 2')
logger.decrease_depth()
logger.info('continue main level')
```

Output
```YAML
- log: 2022-10-31 18:18:34.520544 [INFO] [manual_hierarchy_line_logging_1.py.<module>:13] main level log
  children:
    - log: 2022-10-31 18:18:34.522606 [INFO] [manual_hierarchy_line_logging_1.py.<module>:15] child 1
      children:
        - log: 2022-10-31 18:18:34.523784 [INFO] [manual_hierarchy_line_logging_1.py.<module>:17] child 1_1
- log: 2022-10-31 18:18:34.524810 [INFO] [manual_hierarchy_line_logging_1.py.<module>:19] child 2
- log: 2022-10-31 18:18:34.525864 [INFO] [manual_hierarchy_line_logging_1.py.<module>:21] continue main level
```

### Config file

log_manager config file in YAML style.<br>
Configure loggers and stream handlers.

parameters are inherited. Parameters that are deeper in YAML file will be taken.

```YAML
log_level: WARN
date_format: '%Y-%m-%d %H:%M:%S'
loggers:
  - name: TEST1
    style: yaml
    log_line_template: '[$log_level$] <$date$> $message$'
    stream_handlers:
      - type: console
        style: line
      - type: file
        file_path: logs/log_test_1.txt
        log_level: DEBUG
        style: line
        date_format: '%Y'
        log_line_template: 'Test1 $date$ $message$'
  - name: TEST2
    style: yaml
    stream_handlers:
      - type: file
        file_path: logs/log_test_2.txt
        log_level: ERROR
        date_format: '%Y'
        log_yaml_elements:
          ['log_level', 'date', 'message']
```

```Python
from nrt_logging.logger_manager import logger_manager


CONFIG_FILE_PATH = './config/config1.yaml'

logger_manager.set_config(file_path=CONFIG_FILE_PATH)
```

Wiki: https://github.com/etuzon/nrt-logging/wiki


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/etuzon/python-nrt-logging",
    "name": "nrt-logging",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "python, python3, python-3, logging, logger, log, loggers, hierarchical, logging-library, logging-framework, hierarchy, yaml, nrt, nrt-logging",
    "author": "Eyal Tuzon",
    "author_email": "Eyal Tuzon <eyal.tuzon.dev@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/41/86/657c297f5d942733499a2933a7be1a26e0f22525a53d478f627f7d8ed9ae/nrt_logging-1.3.5.tar.gz",
    "platform": null,
    "description": "# Hierarchical logging in yaml format.\r\n\r\n![PyPI](https://img.shields.io/pypi/v/nrt-logging?color=blueviolet&style=plastic)\r\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/nrt-logging?color=greens&style=plastic)\r\n![PyPI - License](https://img.shields.io/pypi/l/nrt-logging?color=blue&style=plastic)\r\n![PyPI - Downloads](https://img.shields.io/pypi/dd/nrt-logging?style=plastic)\r\n![PyPI - Downloads](https://img.shields.io/pypi/dm/nrt-logging?color=yellow&style=plastic)\r\n[![Coverage Status](https://coveralls.io/repos/github/etuzon/nrt-logging/badge.svg)](https://coveralls.io/github/etuzon/pytohn-nrt-logging)\r\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/etuzon/python-nrt-logging?style=plastic)\r\n![GitHub last commit](https://img.shields.io/github/last-commit/etuzon/python-nrt-logging?style=plastic)\r\n[![DeepSource](https://deepsource.io/gh/etuzon/python-nrt-logging.svg/?label=active+issues&token=3pUgM1IEwZG6Gpuc065dKDxM)](https://deepsource.io/gh/etuzon/python-nrt-logging/?ref=repository-badge)\r\n\r\nHierarchical logging help to group logs that are related to the same code flow.\r\n\r\nLog style can be styled in Yaml format or in Line format.\r\n\r\n### Examples:\r\n\r\n#### Output in YAML style\r\n\r\n```Python\r\nfrom nrt_logging.logger import NrtLogger\r\nfrom nrt_logging.logger_manager import logger_manager\r\nfrom nrt_logging.logger_stream_handlers import ManualDepthEnum\r\n\r\nNAME_1 = 'TEST1'\r\nNAME_2 = 'TEST2'\r\n\r\n\r\nclass Child:\r\n    __logger: NrtLogger\r\n\r\n    def __init__(self):\r\n        self.__logger = logger_manager.get_logger(NAME_1)\r\n\r\n    def child_1(self):\r\n        self.__logger.info('Child 1')\r\n        self.child_2()\r\n\r\n    def child_2(self):\r\n        self.__logger.info('Child 2')\r\n\r\n\r\nclass Parent:\r\n    MSG_1 = 'MSG_1'\r\n    MSG_2 = 'MSG_2'\r\n    MSG_3 = 'MSG_3'\r\n    INCREASE_MSG = 'INCREASE_MSG'\r\n    DECREASE_MSG = 'DECREASE_MSG'\r\n\r\n    __logger: NrtLogger\r\n    __child: Child\r\n\r\n    def __init__(self):\r\n        self.__logger = logger_manager.get_logger(NAME_1)\r\n        self.__child = Child()\r\n\r\n    def a1(self):\r\n        self.__logger.warn(self.MSG_1)\r\n        self.__child.child_1()\r\n\r\n    def a2_manual(self):\r\n        self.__logger.info(self.MSG_2)\r\n        self.__logger.increase_depth()\r\n        self.__logger.info(self.INCREASE_MSG)\r\n        self.__logger.decrease_depth()\r\n        self.__logger.info(self.DECREASE_MSG)\r\n        self.__logger.error(self.MSG_1)\r\n        self.a1()\r\n\r\n    def a3_manual(self):\r\n        self.__logger.info(self.MSG_2)\r\n        self.__logger.increase_depth()\r\n        self.__logger.info(self.INCREASE_MSG)\r\n        self.__logger.decrease_depth()\r\n        self.__logger.info(self.DECREASE_MSG)\r\n        self.__logger.error(self.MSG_3)\r\n\r\n    def a4_manual(self):\r\n        self.__logger.info(self.MSG_1)\r\n        self.__logger.info(self.INCREASE_MSG, ManualDepthEnum.INCREASE)\r\n        self.__logger.info(self.DECREASE_MSG, ManualDepthEnum.DECREASE)\r\n        self.__logger.error(self.MSG_2)\r\n```\r\n\r\n```Python\r\nfrom examples.demo_classes.demo_classes import NAME_1, Parent\r\nfrom nrt_logging.logger_manager import logger_manager\r\nfrom nrt_logging.logger_stream_handlers import \\\r\n    ConsoleStreamHandler, LogStyleEnum\r\n\r\n\r\ndef logging_style(log_style: LogStyleEnum):\r\n    sh = ConsoleStreamHandler()\r\n    sh.style = log_style\r\n    logger = logger_manager.get_logger(NAME_1)\r\n    logger.add_stream_handler(sh)\r\n    p = Parent()\r\n    p.a1()\r\n\r\n\r\ndef logging_line_style():\r\n    logging_style(LogStyleEnum.LINE)\r\n\r\n\r\ndef logging_yaml_style():\r\n    logging_style(LogStyleEnum.YAML)\r\n\r\n\r\nlogging_yaml_style()\r\n```\r\n\r\nOutput\r\n```YAML\r\n---\r\ndate: 2022-10-31 17:59:04.653084\r\nlog_level: WARN\r\npath: demo_classes.py.Parent\r\nmethod: a1\r\nline_number: 38\r\nmessage: MSG_1\r\nchildren:\r\n  - date: 2022-10-31 17:59:04.655071\r\n    log_level: INFO\r\n    path: demo_classes.py.Child\r\n    method: child_1\r\n    line_number: 16\r\n    message: Child 1\r\n    children:\r\n      - date: 2022-10-31 17:59:04.656137\r\n        log_level: INFO\r\n        path: demo_classes.py.Child\r\n        method: child_2\r\n        line_number: 20\r\n        message: Child 2\r\n```\r\n\r\n#### Output in LINE style\r\n\r\n```YAML\r\n- log: 2022-10-31 18:16:54.033735 [WARN] [demo_classes.py.Parent.a1:38] MSG_1\r\n  children:\r\n    - log: 2022-10-31 18:16:54.034660 [INFO] [demo_classes.py.Child.child_1:16] Child 1\r\n      children:\r\n        - log: 2022-10-31 18:16:54.036723 [INFO] [demo_classes.py.Child.child_2:20] Child 2\r\n```\r\n\r\n```Python\r\nfrom nrt_logging.log_level import LogLevelEnum\r\nfrom nrt_logging.logger_manager import logger_manager\r\nfrom nrt_logging.logger_stream_handlers import \\\r\n    ConsoleStreamHandler, LogStyleEnum\r\n\r\n\r\nsh = ConsoleStreamHandler()\r\nsh.log_level = LogLevelEnum.TRACE\r\nsh.style = LogStyleEnum.LINE\r\nlogger = logger_manager.get_logger('NAME_1')\r\nlogger.add_stream_handler(sh)\r\n\r\nlogger.info('main level log')\r\nlogger.increase_depth()\r\nlogger.info('child 1')\r\nlogger.increase_depth()\r\nlogger.info('child 1_1')\r\nlogger.decrease_depth()\r\nlogger.info('child 2')\r\nlogger.decrease_depth()\r\nlogger.info('continue main level')\r\n```\r\n\r\nOutput\r\n```YAML\r\n- log: 2022-10-31 18:18:34.520544 [INFO] [manual_hierarchy_line_logging_1.py.<module>:13] main level log\r\n  children:\r\n    - log: 2022-10-31 18:18:34.522606 [INFO] [manual_hierarchy_line_logging_1.py.<module>:15] child 1\r\n      children:\r\n        - log: 2022-10-31 18:18:34.523784 [INFO] [manual_hierarchy_line_logging_1.py.<module>:17] child 1_1\r\n- log: 2022-10-31 18:18:34.524810 [INFO] [manual_hierarchy_line_logging_1.py.<module>:19] child 2\r\n- log: 2022-10-31 18:18:34.525864 [INFO] [manual_hierarchy_line_logging_1.py.<module>:21] continue main level\r\n```\r\n\r\n### Config file\r\n\r\nlog_manager config file in YAML style.<br>\r\nConfigure loggers and stream handlers.\r\n\r\nparameters are inherited. Parameters that are deeper in YAML file will be taken.\r\n\r\n```YAML\r\nlog_level: WARN\r\ndate_format: '%Y-%m-%d %H:%M:%S'\r\nloggers:\r\n  - name: TEST1\r\n    style: yaml\r\n    log_line_template: '[$log_level$] <$date$> $message$'\r\n    stream_handlers:\r\n      - type: console\r\n        style: line\r\n      - type: file\r\n        file_path: logs/log_test_1.txt\r\n        log_level: DEBUG\r\n        style: line\r\n        date_format: '%Y'\r\n        log_line_template: 'Test1 $date$ $message$'\r\n  - name: TEST2\r\n    style: yaml\r\n    stream_handlers:\r\n      - type: file\r\n        file_path: logs/log_test_2.txt\r\n        log_level: ERROR\r\n        date_format: '%Y'\r\n        log_yaml_elements:\r\n          ['log_level', 'date', 'message']\r\n```\r\n\r\n```Python\r\nfrom nrt_logging.logger_manager import logger_manager\r\n\r\n\r\nCONFIG_FILE_PATH = './config/config1.yaml'\r\n\r\nlogger_manager.set_config(file_path=CONFIG_FILE_PATH)\r\n```\r\n\r\nWiki: https://github.com/etuzon/nrt-logging/wiki\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Hierarchical logging in yaml format",
    "version": "1.3.5",
    "project_urls": {
        "Bug Tracker": "https://github.com/etuzon/python-nrt-logging/issues",
        "Homepage": "https://github.com/etuzon/python-nrt-logging",
        "documentation": "https://github.com/etuzon/python-nrt-logging/wiki"
    },
    "split_keywords": [
        "python",
        " python3",
        " python-3",
        " logging",
        " logger",
        " log",
        " loggers",
        " hierarchical",
        " logging-library",
        " logging-framework",
        " hierarchy",
        " yaml",
        " nrt",
        " nrt-logging"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed85a2a7ceb63b0dbd7391a339c0a1f2256517207c28820a1546355dcfb9dcfd",
                "md5": "11e2caec6c36181fae7077af6e1baa9c",
                "sha256": "d6359790bc063491e94385008ee1c742ee2b3e8792a42717d4201154e8fc692a"
            },
            "downloads": -1,
            "filename": "nrt_logging-1.3.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "11e2caec6c36181fae7077af6e1baa9c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 19792,
            "upload_time": "2024-04-22T13:46:11",
            "upload_time_iso_8601": "2024-04-22T13:46:11.805046Z",
            "url": "https://files.pythonhosted.org/packages/ed/85/a2a7ceb63b0dbd7391a339c0a1f2256517207c28820a1546355dcfb9dcfd/nrt_logging-1.3.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4186657c297f5d942733499a2933a7be1a26e0f22525a53d478f627f7d8ed9ae",
                "md5": "6114a7ca23017acaa56633f0575ff27f",
                "sha256": "f2c877d7431e973704716c6ef67264a35687de67e8bce3229259430715ec25d8"
            },
            "downloads": -1,
            "filename": "nrt_logging-1.3.5.tar.gz",
            "has_sig": false,
            "md5_digest": "6114a7ca23017acaa56633f0575ff27f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 19081,
            "upload_time": "2024-04-22T13:46:14",
            "upload_time_iso_8601": "2024-04-22T13:46:14.955587Z",
            "url": "https://files.pythonhosted.org/packages/41/86/657c297f5d942733499a2933a7be1a26e0f22525a53d478f627f7d8ed9ae/nrt_logging-1.3.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-22 13:46:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "etuzon",
    "github_project": "python-nrt-logging",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [
        {
            "name": "PyYAML",
            "specs": [
                [
                    ">=",
                    "3.11"
                ]
            ]
        },
        {
            "name": "schema",
            "specs": [
                [
                    ">=",
                    "0.7.5"
                ]
            ]
        }
    ],
    "lcname": "nrt-logging"
}
        
Elapsed time: 0.20847s