sharklog


Namesharklog JSON
Version 0.0.4 PyPI version JSON
download
home_pageNone
SummaryA Python logging helper
upload_time2024-05-23 06:40:10
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT License Copyright (c) 2024 ShiChangshan 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 helper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sharklog

Python logging helper.

[![PyPI License](https://img.shields.io/pypi/l/sharklog.svg)](https://pypi.org/project/sharklog)
[![PyPI Version](https://img.shields.io/pypi/v/sharklog.svg)](https://pypi.org/project/sharklog)

## Quick Start

- Install sharklog:

```bash
python -m pip install sharklog
```

- Use in standalone script:

```python
# standalone.py
from sharklog import logging

logging.init(debug=True)    # init all loggers with level=logging.DEBUG
# or logging.init(level=logging.DEBUG)
logging.debug("debug message")
logging.info("info message")
logging.warning("warning message")
logging.error("error message")
```

If you want to change logging level for a module, you can set it in the module by:

```python
from sharklog import logging
logging.getLogger().setLevel(logging.DEBUG)
```

or set it outside the module by specifying the logger name:

```python
from sharklog import logging
logging.getLogger("module_name").setLevel(logging.DEBUG)
```

The default format of log messages is:

```python
"[%(levelname)s]: %(message)s [%(asctime)s](%(filename)s:%(lineno)d)"
```

## Usage in Package Development

Now I assume your file structure is like this:

```bash
--- parent_package
    |--- __init__.py
    |--- parent_module.py
    |--- logger.py
    |--- sub_package
        |--- __init__.py
        |--- sub_module.py
```

- First, you can add `NullHandler` to the root logger in `parent_package/__init__.py`, which logger named `parent_package`:

```python
# parent/__init__.py
from sharklog import logging

logging.getLogger().addHandler(logging.NullHandler())
```

This is mentioned in the [Python Logging HOWTO](https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library) to identify the logger's default behavior.

- Then, use `logging` in your package, they will be prefixed with the logger name `parent_package.`:

```python
# parent_module.py which is placed under package `parent_package`
from sharklog import logging

logger = logging.getLogger()    # the logger name will be `parent_package.parent_module`

logger.debug("debug message")
logger.info("info message")
logger.warning("warning message")
logger.error("error message")
```

If you already using builtin logging module, you can use sharklog as a drop-in replacement.

Just change ~~`import logging`~~ into `from sharklog import logging`. Then you can use `logging` as usual:

```python
# sub_module.py
from sharklog import logging

# these log messages will be prefixed with the logger name `xxxpackage.xxmodule.module_name`
# here, as an example, the logger name will be `parent_package.sub_package.sub_module`
logging.debug("debug message")
logging.info("info message")
logging.warning("warning message")
logging.error("error message")
```

- Finally, you can set the logging level for the package in the main script which using the package:

```python
# main.py
from sharklog import logging

from parent_package import parent_module
from parent_package.sub_package import sub_module

if __name__ == "__main__":
    logging.init(debug=True)    # init all loggers with level=logging.DEBUG
    # or logging.init(level=logging.DEBUG)
    # logging inside the package will use the level set here
```

Or if you want to change the logging level for a specific module, you can set it in the module by:

```python
from sharklog import logging
logging.getLogger().setLevel(logging.WARNING)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sharklog",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "logging, helper",
    "author": null,
    "author_email": "Shi Changshan <changshanshi@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/57/73/e7cd065011a862ce76158cfffcceae7880d8354dcd49b45d5b78d69df8f4/sharklog-0.0.4.tar.gz",
    "platform": null,
    "description": "# sharklog\n\nPython logging helper.\n\n[![PyPI License](https://img.shields.io/pypi/l/sharklog.svg)](https://pypi.org/project/sharklog)\n[![PyPI Version](https://img.shields.io/pypi/v/sharklog.svg)](https://pypi.org/project/sharklog)\n\n## Quick Start\n\n- Install sharklog:\n\n```bash\npython -m pip install sharklog\n```\n\n- Use in standalone script:\n\n```python\n# standalone.py\nfrom sharklog import logging\n\nlogging.init(debug=True)    # init all loggers with level=logging.DEBUG\n# or logging.init(level=logging.DEBUG)\nlogging.debug(\"debug message\")\nlogging.info(\"info message\")\nlogging.warning(\"warning message\")\nlogging.error(\"error message\")\n```\n\nIf you want to change logging level for a module, you can set it in the module by:\n\n```python\nfrom sharklog import logging\nlogging.getLogger().setLevel(logging.DEBUG)\n```\n\nor set it outside the module by specifying the logger name:\n\n```python\nfrom sharklog import logging\nlogging.getLogger(\"module_name\").setLevel(logging.DEBUG)\n```\n\nThe default format of log messages is:\n\n```python\n\"[%(levelname)s]: %(message)s [%(asctime)s](%(filename)s:%(lineno)d)\"\n```\n\n## Usage in Package Development\n\nNow I assume your file structure is like this:\n\n```bash\n--- parent_package\n    |--- __init__.py\n    |--- parent_module.py\n    |--- logger.py\n    |--- sub_package\n        |--- __init__.py\n        |--- sub_module.py\n```\n\n- First, you can add `NullHandler` to the root logger in `parent_package/__init__.py`, which logger named `parent_package`:\n\n```python\n# parent/__init__.py\nfrom sharklog import logging\n\nlogging.getLogger().addHandler(logging.NullHandler())\n```\n\nThis is mentioned in the [Python Logging HOWTO](https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library) to identify the logger's default behavior.\n\n- Then, use `logging` in your package, they will be prefixed with the logger name `parent_package.`:\n\n```python\n# parent_module.py which is placed under package `parent_package`\nfrom sharklog import logging\n\nlogger = logging.getLogger()    # the logger name will be `parent_package.parent_module`\n\nlogger.debug(\"debug message\")\nlogger.info(\"info message\")\nlogger.warning(\"warning message\")\nlogger.error(\"error message\")\n```\n\nIf you already using builtin logging module, you can use sharklog as a drop-in replacement.\n\nJust change ~~`import logging`~~ into `from sharklog import logging`. Then you can use `logging` as usual:\n\n```python\n# sub_module.py\nfrom sharklog import logging\n\n# these log messages will be prefixed with the logger name `xxxpackage.xxmodule.module_name`\n# here, as an example, the logger name will be `parent_package.sub_package.sub_module`\nlogging.debug(\"debug message\")\nlogging.info(\"info message\")\nlogging.warning(\"warning message\")\nlogging.error(\"error message\")\n```\n\n- Finally, you can set the logging level for the package in the main script which using the package:\n\n```python\n# main.py\nfrom sharklog import logging\n\nfrom parent_package import parent_module\nfrom parent_package.sub_package import sub_module\n\nif __name__ == \"__main__\":\n    logging.init(debug=True)    # init all loggers with level=logging.DEBUG\n    # or logging.init(level=logging.DEBUG)\n    # logging inside the package will use the level set here\n```\n\nOr if you want to change the logging level for a specific module, you can set it in the module by:\n\n```python\nfrom sharklog import logging\nlogging.getLogger().setLevel(logging.WARNING)\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 ShiChangshan  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": "A Python logging helper",
    "version": "0.0.4",
    "project_urls": {
        "Homepage": "https://github.com/Bardreamaster/sharklog"
    },
    "split_keywords": [
        "logging",
        " helper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ea2f635c9b39e404c48397eede2579e5e6726755ea3e2c101febd983ec2e3ab7",
                "md5": "5b96ac4fa6d8246c6fdf0782c61058ab",
                "sha256": "5a32a2a2a4fff4cd2dc113401d4127b3f03d04ec8f2aa99eff9ace56b5ae3b0f"
            },
            "downloads": -1,
            "filename": "sharklog-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5b96ac4fa6d8246c6fdf0782c61058ab",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5671,
            "upload_time": "2024-05-23T06:38:59",
            "upload_time_iso_8601": "2024-05-23T06:38:59.643462Z",
            "url": "https://files.pythonhosted.org/packages/ea/2f/635c9b39e404c48397eede2579e5e6726755ea3e2c101febd983ec2e3ab7/sharklog-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5773e7cd065011a862ce76158cfffcceae7880d8354dcd49b45d5b78d69df8f4",
                "md5": "ac2ab0aa92ca69fc57060ea7a6fff356",
                "sha256": "5dae9c0fb49e57af77f396d0bd044eca25087b9934bbc02c599e6a6c79c56198"
            },
            "downloads": -1,
            "filename": "sharklog-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "ac2ab0aa92ca69fc57060ea7a6fff356",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5198,
            "upload_time": "2024-05-23T06:40:10",
            "upload_time_iso_8601": "2024-05-23T06:40:10.008511Z",
            "url": "https://files.pythonhosted.org/packages/57/73/e7cd065011a862ce76158cfffcceae7880d8354dcd49b45d5b78d69df8f4/sharklog-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-23 06:40:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Bardreamaster",
    "github_project": "sharklog",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sharklog"
}
        
Elapsed time: 0.24469s