logger-wrapper


Namelogger-wrapper JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryThe package wraps the built-in Logger package. There are options to track from where the log message was created.
upload_time2023-05-04 08:17:30
maintainer
docs_urlNone
author
requires_python>=3.11
license
keywords logger logging syslog location formating
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LoggerWrapper Package

This package provides wrappers for the built-in logging.Logger class:

## **PseudoSingletonLogger::**

The PseudoSingletonLogger class inherits the logging.Logger and instantiates a singleton for each logger name give.</br>
PsudoSigletonLogger pre-configures some of the common tasks like formating to help a standardize logging format.</br>
If given the optional 'app_name' the name of the application is placed in the header.</br>
If given the 'use_instance' flag a space is allocated for the instance name for the client class to inject during logging.</br>
If given the optional 'name' string the name is used to find the logger by that name, otherwise the 'root' logger is used.</br>
Each unique 'name' creates a new instance.  Setting the name equal to None will use the previously used instance.  Using a previously used name will return that instance.</br>

The PsudoSigletonLogger class has the following methods::

>   *set_default_format(logger_name: str = None, app_name: str = None, use_instance: bool = False):* </br>
>   Sets the default logging format for the given logger_name.  If no logger_name than the default is the last_logger instance used.

>   *get_output_path(logger_name: str = None, handler_type: logging.Handler=None):*</br>
>   Tries to retrieve a list of output targets of the handler that matches the type passed in. If handler_type is None, all the output targets for all the registered handlers are returned.</br>
>   If no logger_name provided than the default is the last_logger instance used.</br>
>
>   *NOTE:* Not fully tested for all handler types.  Tested on StreamHandler, FileHandler, and SyslogHandler</br>

>   *remove_handler(logger_name: str = None, handler_type: logging.Handler=None):*</br>
>   Removes the handlers that matches the type passed in. If the handler_type is None or the handler_type is not registered, none of the handlers will be removed.  If an abstract handler is given, all handler that have inherited will be removed.</br>
>   If no logger_name provided than the default is the last_logger instance used.</br>

>   *version:*</br>
>   The package version.


## **LoggerWrapper::**

The LoggerWrapper class wraps the logging.Logger to pre-configure some of the common tasks like formating.  Provides a quick access to logging by formating the messages to help stardardize the log entries.  This class injects the instance name into the log messages.</br>
If given the optional 'instance_name' string the given name is used, otherwise the instance name is extracted from the stack.  The instance name is inject into the header during logging.</br>
If given the optional 'name' string the name is used to find the logger by that name, otherwise the 'root' logger is used.</br>

The LoggerWrapper class has the following methods::

>   *change_instance_name(self, instance_name: str):*</br>
>   Changes the instance name to use in the log message header.

>   *_log(level, msg, args, exc_info=None, extra=None, stack_info=False, stacklevel: int=1):*</br>
>   Overwrites the logging.Logger._log method to inject the instance name in the log message header.</br>

LoggerWrapper also exposes the PseudoSingletonLogger methods as its own.</br>

## Example Usage ::

```python
import logging
from logging import handlers as hdls
from pathlib import Path

if __name__ == "__main__":
    log_path = Path(".logs", "test.log")
    if not log_path.parent.exists():
        log_path.parent.mkdir(parents=True, exist_ok=True)
    handlers = [logging.StreamHandler(),
                logging.FileHandler(log_path)]
    log1 = LoggerWrapper(app_name="LoggerWrapper Demo",
                         handlers=handlers,
                         meta=True,
                         date_filename=False)

    log2 = LoggerWrapper()
    print(log2.version)

    print(str(log1.get_output_path()))

    for count in range(10):
        if count == 5:
            log1.remove_handler(logging.StreamHandler)
        log1.info("test of " + str(count))
        log2.info("test of " + str(count))

    print(str(log2.get_output_path()))
    print(log1.version)
```

### Console ::

>0.1.0</br>
>['<stderr>', '/home/erol/workspace/logger-wrapper/.logs/test.log']</br>
>2023-05-03 23:15:41,123,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 0</br>
>2023-05-03 23:15:44,484,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 0</br>
>2023-05-03 23:15:48,254,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 1</br>
>2023-05-03 23:15:49,052,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 1</br>
>2023-05-03 23:15:51,307,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 2</br>
>2023-05-03 23:15:51,904,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 2</br>
>2023-05-03 23:15:53,822,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 3</br>
>2023-05-03 23:15:54,505,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 3</br>
>2023-05-03 23:15:56,481,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 4</br>
>2023-05-03 23:15:57,099,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 4</br>
>['/home/erol/workspace/logger-wrapper/.logs/test.log']</br>
>0.1.0</br>

### cat ~/workspace/logger-wrapper/.logs/test.log ::

>2023-05-03 23:15:41,123,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 0</br>
>2023-05-03 23:15:44,484,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 0</br>
>2023-05-03 23:15:48,254,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 1</br>
>2023-05-03 23:15:49,052,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 1</br>
>2023-05-03 23:15:51,307,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 2</br>
>2023-05-03 23:15:51,904,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 2</br>
>2023-05-03 23:15:53,822,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 3</br>
>2023-05-03 23:15:54,505,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 3</br>
>2023-05-03 23:15:56,481,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 4</br>
>2023-05-03 23:15:57,099,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 4</br>
>2023-05-03 23:16:01,619,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 5</br>
>2023-05-03 23:16:02,369,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 5</br>
>2023-05-03 23:16:04,266,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 6</br>
>2023-05-03 23:16:04,763,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 6</br>
>2023-05-03 23:16:06,621,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 7</br>
>2023-05-03 23:16:07,148,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 7</br>
>2023-05-03 23:16:09,007,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 8</br>
>2023-05-03 23:16:09,595,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 8</br>
>2023-05-03 23:16:12,300,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 9</br>
>2023-05-03 23:16:12,301,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 9

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "logger-wrapper",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "logger,logging,syslog,location,formating",
    "author": "",
    "author_email": "Erol Yesin <erol@sandboxzilla.net>",
    "download_url": "https://files.pythonhosted.org/packages/2e/a5/be822f3c87b5a198f8ce854b8573f94ae7a8d6473c20d98afa4f9d881389/logger_wrapper-0.1.0.tar.gz",
    "platform": null,
    "description": "# LoggerWrapper Package\n\nThis package provides wrappers for the built-in logging.Logger class:\n\n## **PseudoSingletonLogger::**\n\nThe PseudoSingletonLogger class inherits the logging.Logger and instantiates a singleton for each logger name give.</br>\nPsudoSigletonLogger pre-configures some of the common tasks like formating to help a standardize logging format.</br>\nIf given the optional 'app_name' the name of the application is placed in the header.</br>\nIf given the 'use_instance' flag a space is allocated for the instance name for the client class to inject during logging.</br>\nIf given the optional 'name' string the name is used to find the logger by that name, otherwise the 'root' logger is used.</br>\nEach unique 'name' creates a new instance.  Setting the name equal to None will use the previously used instance.  Using a previously used name will return that instance.</br>\n\nThe PsudoSigletonLogger class has the following methods::\n\n>   *set_default_format(logger_name: str = None, app_name: str = None, use_instance: bool = False):* </br>\n>   Sets the default logging format for the given logger_name.  If no logger_name than the default is the last_logger instance used.\n\n>   *get_output_path(logger_name: str = None, handler_type: logging.Handler=None):*</br>\n>   Tries to retrieve a list of output targets of the handler that matches the type passed in. If handler_type is None, all the output targets for all the registered handlers are returned.</br>\n>   If no logger_name provided than the default is the last_logger instance used.</br>\n>\n>   *NOTE:* Not fully tested for all handler types.  Tested on StreamHandler, FileHandler, and SyslogHandler</br>\n\n>   *remove_handler(logger_name: str = None, handler_type: logging.Handler=None):*</br>\n>   Removes the handlers that matches the type passed in. If the handler_type is None or the handler_type is not registered, none of the handlers will be removed.  If an abstract handler is given, all handler that have inherited will be removed.</br>\n>   If no logger_name provided than the default is the last_logger instance used.</br>\n\n>   *version:*</br>\n>   The package version.\n\n\n## **LoggerWrapper::**\n\nThe LoggerWrapper class wraps the logging.Logger to pre-configure some of the common tasks like formating.  Provides a quick access to logging by formating the messages to help stardardize the log entries.  This class injects the instance name into the log messages.</br>\nIf given the optional 'instance_name' string the given name is used, otherwise the instance name is extracted from the stack.  The instance name is inject into the header during logging.</br>\nIf given the optional 'name' string the name is used to find the logger by that name, otherwise the 'root' logger is used.</br>\n\nThe LoggerWrapper class has the following methods::\n\n>   *change_instance_name(self, instance_name: str):*</br>\n>   Changes the instance name to use in the log message header.\n\n>   *_log(level, msg, args, exc_info=None, extra=None, stack_info=False, stacklevel: int=1):*</br>\n>   Overwrites the logging.Logger._log method to inject the instance name in the log message header.</br>\n\nLoggerWrapper also exposes the PseudoSingletonLogger methods as its own.</br>\n\n## Example Usage ::\n\n```python\nimport logging\nfrom logging import handlers as hdls\nfrom pathlib import Path\n\nif __name__ == \"__main__\":\n    log_path = Path(\".logs\", \"test.log\")\n    if not log_path.parent.exists():\n        log_path.parent.mkdir(parents=True, exist_ok=True)\n    handlers = [logging.StreamHandler(),\n                logging.FileHandler(log_path)]\n    log1 = LoggerWrapper(app_name=\"LoggerWrapper Demo\",\n                         handlers=handlers,\n                         meta=True,\n                         date_filename=False)\n\n    log2 = LoggerWrapper()\n    print(log2.version)\n\n    print(str(log1.get_output_path()))\n\n    for count in range(10):\n        if count == 5:\n            log1.remove_handler(logging.StreamHandler)\n        log1.info(\"test of \" + str(count))\n        log2.info(\"test of \" + str(count))\n\n    print(str(log2.get_output_path()))\n    print(log1.version)\n```\n\n### Console ::\n\n>0.1.0</br>\n>['<stderr>', '/home/erol/workspace/logger-wrapper/.logs/test.log']</br>\n>2023-05-03 23:15:41,123,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 0</br>\n>2023-05-03 23:15:44,484,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 0</br>\n>2023-05-03 23:15:48,254,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 1</br>\n>2023-05-03 23:15:49,052,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 1</br>\n>2023-05-03 23:15:51,307,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 2</br>\n>2023-05-03 23:15:51,904,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 2</br>\n>2023-05-03 23:15:53,822,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 3</br>\n>2023-05-03 23:15:54,505,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 3</br>\n>2023-05-03 23:15:56,481,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 4</br>\n>2023-05-03 23:15:57,099,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 4</br>\n>['/home/erol/workspace/logger-wrapper/.logs/test.log']</br>\n>0.1.0</br>\n\n### cat ~/workspace/logger-wrapper/.logs/test.log ::\n\n>2023-05-03 23:15:41,123,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 0</br>\n>2023-05-03 23:15:44,484,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 0</br>\n>2023-05-03 23:15:48,254,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 1</br>\n>2023-05-03 23:15:49,052,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 1</br>\n>2023-05-03 23:15:51,307,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 2</br>\n>2023-05-03 23:15:51,904,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 2</br>\n>2023-05-03 23:15:53,822,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 3</br>\n>2023-05-03 23:15:54,505,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 3</br>\n>2023-05-03 23:15:56,481,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 4</br>\n>2023-05-03 23:15:57,099,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 4</br>\n>2023-05-03 23:16:01,619,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 5</br>\n>2023-05-03 23:16:02,369,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 5</br>\n>2023-05-03 23:16:04,266,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 6</br>\n>2023-05-03 23:16:04,763,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 6</br>\n>2023-05-03 23:16:06,621,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 7</br>\n>2023-05-03 23:16:07,148,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 7</br>\n>2023-05-03 23:16:09,007,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 8</br>\n>2023-05-03 23:16:09,595,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 8</br>\n>2023-05-03 23:16:12,300,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log1:logger_wrapper:<module>:408],test of 9</br>\n>2023-05-03 23:16:12,301,LoggerWrapper Demo,[INFO:pid=3356970:MainThread:log2:logger_wrapper:<module>:409],test of 9\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "The package wraps the built-in Logger package.  There are options to track from where the log message was created.",
    "version": "0.1.0",
    "project_urls": {
        "Bug Tracker": "https://https://github.com/sandboxzilla/logger-wrapper/issues",
        "Download": "https://github.com/erolyesin/logger-wrapper/archive/refs/tags/v0.1.0.tar.gz",
        "Homepage": "https://github.com/sandboxzilla/logger-wrapper"
    },
    "split_keywords": [
        "logger",
        "logging",
        "syslog",
        "location",
        "formating"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a69a15c41da8a0eb180c54165148b8b8ddfb1ef72b12e2fafa83e5333ca80489",
                "md5": "76db16e8e9b8b4c471c785080a73a25e",
                "sha256": "ca8b87a20300bed4dbb8fb802a2c5886eb424e68535f0ba88076857c0c800c83"
            },
            "downloads": -1,
            "filename": "logger_wrapper-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "76db16e8e9b8b4c471c785080a73a25e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 9638,
            "upload_time": "2023-05-04T08:17:28",
            "upload_time_iso_8601": "2023-05-04T08:17:28.713989Z",
            "url": "https://files.pythonhosted.org/packages/a6/9a/15c41da8a0eb180c54165148b8b8ddfb1ef72b12e2fafa83e5333ca80489/logger_wrapper-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2ea5be822f3c87b5a198f8ce854b8573f94ae7a8d6473c20d98afa4f9d881389",
                "md5": "3572ab9e9484528c62277c711fe07f2c",
                "sha256": "9e22cb406d814e7f4272e527fb8ce1622c4d8a334d72e9038b7a50d5b2998948"
            },
            "downloads": -1,
            "filename": "logger_wrapper-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3572ab9e9484528c62277c711fe07f2c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 11019,
            "upload_time": "2023-05-04T08:17:30",
            "upload_time_iso_8601": "2023-05-04T08:17:30.753443Z",
            "url": "https://files.pythonhosted.org/packages/2e/a5/be822f3c87b5a198f8ce854b8573f94ae7a8d6473c20d98afa4f9d881389/logger_wrapper-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-04 08:17:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "erolyesin",
    "github_project": "logger-wrapper",
    "github_not_found": true,
    "lcname": "logger-wrapper"
}
        
Elapsed time: 1.08622s