iilog-pckg


Nameiilog-pckg JSON
Version 0.0.4 PyPI version JSON
download
home_pagehttps://github.com/kyasuda516/iilog-pckg
Summaryiilog: alternative library to logging
upload_time2023-07-01 12:40:51
maintainer
docs_urlNone
authorKanta Yasuda
requires_python>=3.8
licenseMIT license
keywords iilog iilog-pckg logging logger log
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">

![iilog_logo](https://github.com/kyasuda516/iilog-pckg/assets/127583471/a16a4431-83fb-479a-8609-785c2c66d7a1)

[![Python](https://img.shields.io/pypi/pyversions/iilog-pckg)](https://www.python.org/)
[![PyPI](https://img.shields.io/pypi/v/iilog-pckg?color=blue)](https://pypi.org/project/iilog-pckg/)
[![LICENSE](https://img.shields.io/pypi/l/iilog-pckg?color=blue)](https://github.com/kyasuda516/iilog/blob/master/LICENSE)

</div>

<div align="center">

## iilog is an alternative library to `logging`

</div>

iilog provides a little more comfortable logging experience.
It is my ([@kyasuda516](https://github.com/kyasuda516)) own reconfiguration of Python's stdlib [`logging`](https://docs.python.org/3/library/logging.html).

<br>

# Features

- A solution for those who feel slightly dissatisfied with the usability of the built-in logging library.
- Logger instances can be created in a way that is very similar to using the [`logging.basicConfig`](https://docs.python.org/3/library/logging.html#logging.basicConfig) function.
- The usage of accessing the root logger is designed to be as invisible as possible.

<br>

# Installation

You can install iilog with

```shell
python -m pip install iilog-pckg
```

Otherwise, you can install directly from the github repo using

```shell
python -m pip install git+https://github.com/kyasuda516/iilog-pckg.git
```

<br>

# Example Usage

## Simple example

sample.py:
```python
from iilog.loggers import Logger
import iilog

# define loggers
logger1 = Logger(
    filename='myapp.log', filemode='w', encoding='UTF-8')

import sys
logger2 = Logger(
    format=r'%(asctime)s %(levelname)-8s %(name)-15s %(message)s', 
    datefmt=r'%Y-%m-%d %H:%M:%S',
    stream=sys.stdout, level=iilog.env.WARNING)

formatter = iilog.formatters.Formatter(iilog.formatters.BASIC_FORMAT)
handler = iilog.handlers.RotatingFileHandler(
    filename='dev.log', maxBytes=256, backupCount=3)
handler.setFormatter(formatter)
logger3 = Logger(handlers=[handler])

# logging
logger1.warning('Watch out!')
logger1.info('I told you so')

logger2.warning('Watch out!')
logger2.info('I told you so')

logger3.error('An unknown error occured.')
logger3.error('An unknown error occured.')
logger3.error('An unknown error occured.')
logger3.error('An unknown error occured.')
logger3.error('An unknown error occured.')
```

The results are as follows:
```shell
$ python sample.py
2023-07-01 02:03:04 WARNING  iilog.loggers.Logger.i1 Watch out!

$ cat myapp.log
Watch out!
I told you so

$ cat dev.log
ERROR:iilog.loggers.Logger.i2:An unknown error occured.

$ cat dev.log.1
ERROR:iilog.loggers.Logger.i2:An unknown error occured.
ERROR:iilog.loggers.Logger.i2:An unknown error occured.
ERROR:iilog.loggers.Logger.i2:An unknown error occured.
ERROR:iilog.loggers.Logger.i2:An unknown error occured.

```

<details>
<summary>For more details</summary>

The `iilog.loggers.Logger` constructor works in much the same way as the [`logging`](https://docs.python.org/3/library/logging.html) library's [`basicConfig`](https://docs.python.org/3/library/logging.html#logging.basicConfig) function. The following is the description of [`logging.basicConfig()`](https://docs.python.org/3/library/logging.html#logging.basicConfig)'s parameters taken from the official documentation and added with strikethrough decoration according to the unique specification:

- *filename* – Specifies that a [`FileHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.FileHandler) be created, using the specified filename, rather than a [`StreamHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler).
- *filemode* – If *filename* is specified, open the file in this [mode](https://docs.python.org/3/library/functions.html#filemodes). Defaults to `'a'`.
- *format* – Use the specified format string for the handler. Defaults to attributes `levelname`, `name` and `message` separated by colons.
- *datefmt* – Use the specified date/time format, as accepted by [`time.strftime()`](https://docs.python.org/3/library/time.html#time.strftime).
- *style* – If *format* is specified, use this style for the format string. One of `'%'`, `'{'` or `'$'` for [printf-style](https://docs.python.org/3/library/stdtypes.html#old-string-formatting), [`str.format()`](https://docs.python.org/3/library/stdtypes.html#str.format) or [`string.Template`](https://docs.python.org/3/library/string.html#string.Template) respectively. Defaults to `'%'`.
- *level* – Set the ~~root~~ logger level to the specified [level](https://docs.python.org/3/library/logging.html#levels).
- *stream* – Use the specified stream to initialize the [`StreamHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler). Note that this argument is incompatible with *filename* - if both are present, a `ValueError` is raised.
- *handlers* – If specified, this should be an iterable of already created handlers to add to the ~~root~~ logger. Any handlers which don’t already have a formatter set will be assigned the default formatter created in this function. Note that this argument is incompatible with *filename* or *stream* - if both are present, a `ValueError` is raised.
- ~~*force* – If this keyword argument is specified as true, any existing handlers attached to the root logger are removed and closed, before carrying out the configuration as specified by the other arguments.~~
- *encoding* – If this keyword argument is specified along with *filename*, its value is used when the [`FileHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.FileHandler) is created, and thus used when opening the output file.
- *errors* – If this keyword argument is specified along with *filename*, its value is used when the [`FileHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.FileHandler) is created, and thus used when opening the output file. If not specified, the value ‘backslashreplace’ is used. Note that if `None` is specified, it will be passed as such to [`open()`](https://docs.python.org/3/library/functions.html#open), which means that it will be treated the same as passing ‘errors’.

Also, the `iilog.formatters.Formatter`, `iilog.filters.Filter`, `iilog.handlers.FileHandler`, `iilog.handlers.StreamHandler` classes and so on, which you should use when specifying *handlers*, are exactly the same as defined in the [`logging`](https://docs.python.org/3/library/logging.html) library.
</details>

<br>

## Example of loading a config file

config.yml:
```YAML
version: 1
formatters:
  simple:
    format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
  console:
    class: logging.StreamHandler
    level: DEBUG
    formatter: simple
    stream: ext://sys.stdout
loggers:
  foobarExample:
    level: DEBUG
    handlers: 
      - console
    propagate: no
```

sample2.py:
```python
import iilog
iilog.env.set_config(filename='config.yml', encoding='UTF-8')
logger = iilog.env.get_logger('foobarExample')
logger.info('I told you so')
```

The results are as follows:
```shell
$ python test.py
2023-07-01 02:03:04,005 - foobarExample - INFO - I told you so

```

<details>
<summary>For more details</summary>

Takes the logging configuration from a file or dictionary. The parameters are as follows:

- *filename* – Use the specified filename to read the logging configuration from the file.
- *fileformat* – If *filename* is specified, read it as a file written in this format. Accepts either `'yaml'` or `'json'`. If not specified, it will be determined based on *filename*'s extension.
- *encoding* – If this keyword argument is specified along with *filename*, its value is used when opening the file.
- *config* – Takes the logging configuration from the specified dictionary, as accepted by the [`logging.config`](https://docs.python.org/3/library/logging.config.html) module's [`dictConfig()`](https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig). Note that this argument is incompatible with *filename* or *config* - if both are present, a `ValueError` is raised.

</details>

<br>

For any grammar or examples not listed here, please refer to the documentation (sorry, currently under construction).

<br>

# License

This software is released under the MIT License, see LICENSE.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kyasuda516/iilog-pckg",
    "name": "iilog-pckg",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "iilog,iilog-pckg,logging,logger,log",
    "author": "Kanta Yasuda",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/70/41/066278593cd6c6b3487bbf3400975909687329ff629979cfbad0a5bfc5e8/iilog-pckg-0.0.4.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\r\n\r\n![iilog_logo](https://github.com/kyasuda516/iilog-pckg/assets/127583471/a16a4431-83fb-479a-8609-785c2c66d7a1)\r\n\r\n[![Python](https://img.shields.io/pypi/pyversions/iilog-pckg)](https://www.python.org/)\r\n[![PyPI](https://img.shields.io/pypi/v/iilog-pckg?color=blue)](https://pypi.org/project/iilog-pckg/)\r\n[![LICENSE](https://img.shields.io/pypi/l/iilog-pckg?color=blue)](https://github.com/kyasuda516/iilog/blob/master/LICENSE)\r\n\r\n</div>\r\n\r\n<div align=\"center\">\r\n\r\n## iilog is an alternative library to `logging`\r\n\r\n</div>\r\n\r\niilog provides a little more comfortable logging experience.\r\nIt is my ([@kyasuda516](https://github.com/kyasuda516)) own reconfiguration of Python's stdlib [`logging`](https://docs.python.org/3/library/logging.html).\r\n\r\n<br>\r\n\r\n# Features\r\n\r\n- A solution for those who feel slightly dissatisfied with the usability of the built-in logging library.\r\n- Logger instances can be created in a way that is very similar to using the [`logging.basicConfig`](https://docs.python.org/3/library/logging.html#logging.basicConfig) function.\r\n- The usage of accessing the root logger is designed to be as invisible as possible.\r\n\r\n<br>\r\n\r\n# Installation\r\n\r\nYou can install iilog with\r\n\r\n```shell\r\npython -m pip install iilog-pckg\r\n```\r\n\r\nOtherwise, you can install directly from the github repo using\r\n\r\n```shell\r\npython -m pip install git+https://github.com/kyasuda516/iilog-pckg.git\r\n```\r\n\r\n<br>\r\n\r\n# Example Usage\r\n\r\n## Simple example\r\n\r\nsample.py:\r\n```python\r\nfrom iilog.loggers import Logger\r\nimport iilog\r\n\r\n# define loggers\r\nlogger1 = Logger(\r\n    filename='myapp.log', filemode='w', encoding='UTF-8')\r\n\r\nimport sys\r\nlogger2 = Logger(\r\n    format=r'%(asctime)s %(levelname)-8s %(name)-15s %(message)s', \r\n    datefmt=r'%Y-%m-%d %H:%M:%S',\r\n    stream=sys.stdout, level=iilog.env.WARNING)\r\n\r\nformatter = iilog.formatters.Formatter(iilog.formatters.BASIC_FORMAT)\r\nhandler = iilog.handlers.RotatingFileHandler(\r\n    filename='dev.log', maxBytes=256, backupCount=3)\r\nhandler.setFormatter(formatter)\r\nlogger3 = Logger(handlers=[handler])\r\n\r\n# logging\r\nlogger1.warning('Watch out!')\r\nlogger1.info('I told you so')\r\n\r\nlogger2.warning('Watch out!')\r\nlogger2.info('I told you so')\r\n\r\nlogger3.error('An unknown error occured.')\r\nlogger3.error('An unknown error occured.')\r\nlogger3.error('An unknown error occured.')\r\nlogger3.error('An unknown error occured.')\r\nlogger3.error('An unknown error occured.')\r\n```\r\n\r\nThe results are as follows:\r\n```shell\r\n$ python sample.py\r\n2023-07-01 02:03:04 WARNING  iilog.loggers.Logger.i1 Watch out!\r\n\r\n$ cat myapp.log\r\nWatch out!\r\nI told you so\r\n\r\n$ cat dev.log\r\nERROR:iilog.loggers.Logger.i2:An unknown error occured.\r\n\r\n$ cat dev.log.1\r\nERROR:iilog.loggers.Logger.i2:An unknown error occured.\r\nERROR:iilog.loggers.Logger.i2:An unknown error occured.\r\nERROR:iilog.loggers.Logger.i2:An unknown error occured.\r\nERROR:iilog.loggers.Logger.i2:An unknown error occured.\r\n\r\n```\r\n\r\n<details>\r\n<summary>For more details</summary>\r\n\r\nThe `iilog.loggers.Logger` constructor works in much the same way as the [`logging`](https://docs.python.org/3/library/logging.html) library's [`basicConfig`](https://docs.python.org/3/library/logging.html#logging.basicConfig) function. The following is the description of [`logging.basicConfig()`](https://docs.python.org/3/library/logging.html#logging.basicConfig)'s parameters taken from the official documentation and added with strikethrough decoration according to the unique specification:\r\n\r\n- *filename* \u2013 Specifies that a [`FileHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.FileHandler) be created, using the specified filename, rather than a [`StreamHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler).\r\n- *filemode* \u2013 If *filename* is specified, open the file in this [mode](https://docs.python.org/3/library/functions.html#filemodes). Defaults to `'a'`.\r\n- *format* \u2013 Use the specified format string for the handler. Defaults to attributes `levelname`, `name` and `message` separated by colons.\r\n- *datefmt* \u2013 Use the specified date/time format, as accepted by [`time.strftime()`](https://docs.python.org/3/library/time.html#time.strftime).\r\n- *style* \u2013 If *format* is specified, use this style for the format string. One of `'%'`, `'{'` or `'$'` for [printf-style](https://docs.python.org/3/library/stdtypes.html#old-string-formatting), [`str.format()`](https://docs.python.org/3/library/stdtypes.html#str.format) or [`string.Template`](https://docs.python.org/3/library/string.html#string.Template) respectively. Defaults to `'%'`.\r\n- *level* \u2013 Set the ~~root~~ logger level to the specified [level](https://docs.python.org/3/library/logging.html#levels).\r\n- *stream* \u2013 Use the specified stream to initialize the [`StreamHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler). Note that this argument is incompatible with *filename* - if both are present, a `ValueError` is raised.\r\n- *handlers* \u2013 If specified, this should be an iterable of already created handlers to add to the ~~root~~ logger. Any handlers which don\u2019t already have a formatter set will be assigned the default formatter created in this function. Note that this argument is incompatible with *filename* or *stream* - if both are present, a `ValueError` is raised.\r\n- ~~*force* \u2013 If this keyword argument is specified as true, any existing handlers attached to the root logger are removed and closed, before carrying out the configuration as specified by the other arguments.~~\r\n- *encoding* \u2013 If this keyword argument is specified along with *filename*, its value is used when the [`FileHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.FileHandler) is created, and thus used when opening the output file.\r\n- *errors* \u2013 If this keyword argument is specified along with *filename*, its value is used when the [`FileHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.FileHandler) is created, and thus used when opening the output file. If not specified, the value \u2018backslashreplace\u2019 is used. Note that if `None` is specified, it will be passed as such to [`open()`](https://docs.python.org/3/library/functions.html#open), which means that it will be treated the same as passing \u2018errors\u2019.\r\n\r\nAlso, the `iilog.formatters.Formatter`, `iilog.filters.Filter`, `iilog.handlers.FileHandler`, `iilog.handlers.StreamHandler` classes and so on, which you should use when specifying *handlers*, are exactly the same as defined in the [`logging`](https://docs.python.org/3/library/logging.html) library.\r\n</details>\r\n\r\n<br>\r\n\r\n## Example of loading a config file\r\n\r\nconfig.yml:\r\n```YAML\r\nversion: 1\r\nformatters:\r\n  simple:\r\n    format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'\r\nhandlers:\r\n  console:\r\n    class: logging.StreamHandler\r\n    level: DEBUG\r\n    formatter: simple\r\n    stream: ext://sys.stdout\r\nloggers:\r\n  foobarExample:\r\n    level: DEBUG\r\n    handlers: \r\n      - console\r\n    propagate: no\r\n```\r\n\r\nsample2.py:\r\n```python\r\nimport iilog\r\niilog.env.set_config(filename='config.yml', encoding='UTF-8')\r\nlogger = iilog.env.get_logger('foobarExample')\r\nlogger.info('I told you so')\r\n```\r\n\r\nThe results are as follows:\r\n```shell\r\n$ python test.py\r\n2023-07-01 02:03:04,005 - foobarExample - INFO - I told you so\r\n\r\n```\r\n\r\n<details>\r\n<summary>For more details</summary>\r\n\r\nTakes the logging configuration from a file or dictionary. The parameters are as follows:\r\n\r\n- *filename* \u2013 Use the specified filename to read the logging configuration from the file.\r\n- *fileformat* \u2013 If *filename* is specified, read it as a file written in this format. Accepts either `'yaml'` or `'json'`. If not specified, it will be determined based on *filename*'s extension.\r\n- *encoding* \u2013 If this keyword argument is specified along with *filename*, its value is used when opening the file.\r\n- *config* \u2013 Takes the logging configuration from the specified dictionary, as accepted by the [`logging.config`](https://docs.python.org/3/library/logging.config.html) module's [`dictConfig()`](https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig). Note that this argument is incompatible with *filename* or *config* - if both are present, a `ValueError` is raised.\r\n\r\n</details>\r\n\r\n<br>\r\n\r\nFor any grammar or examples not listed here, please refer to the documentation (sorry, currently under construction).\r\n\r\n<br>\r\n\r\n# License\r\n\r\nThis software is released under the MIT License, see LICENSE.\r\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "iilog: alternative library to logging",
    "version": "0.0.4",
    "project_urls": {
        "Download": "https://github.com/kyasuda516/iilog-pckg",
        "Homepage": "https://github.com/kyasuda516/iilog-pckg"
    },
    "split_keywords": [
        "iilog",
        "iilog-pckg",
        "logging",
        "logger",
        "log"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0b697251cf346b233addafc958441467dbc7aa69b27c1b5019dd55b926740a40",
                "md5": "226d5458e13fc2e0e7c5f229ab8fbb8d",
                "sha256": "b0b2f1a44b8388ffe957b7051918933f4f38549e2eff8f840cab8d590fd5c459"
            },
            "downloads": -1,
            "filename": "iilog_pckg-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "226d5458e13fc2e0e7c5f229ab8fbb8d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 9632,
            "upload_time": "2023-07-01T12:40:48",
            "upload_time_iso_8601": "2023-07-01T12:40:48.810270Z",
            "url": "https://files.pythonhosted.org/packages/0b/69/7251cf346b233addafc958441467dbc7aa69b27c1b5019dd55b926740a40/iilog_pckg-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7041066278593cd6c6b3487bbf3400975909687329ff629979cfbad0a5bfc5e8",
                "md5": "7f8edda374168038606307e732280897",
                "sha256": "2f03d00e9b44b16726278ed121a7caea9712eb08406d6d3e716960b5f95849e3"
            },
            "downloads": -1,
            "filename": "iilog-pckg-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "7f8edda374168038606307e732280897",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10531,
            "upload_time": "2023-07-01T12:40:51",
            "upload_time_iso_8601": "2023-07-01T12:40:51.068406Z",
            "url": "https://files.pythonhosted.org/packages/70/41/066278593cd6c6b3487bbf3400975909687329ff629979cfbad0a5bfc5e8/iilog-pckg-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-01 12:40:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kyasuda516",
    "github_project": "iilog-pckg",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "iilog-pckg"
}
        
Elapsed time: 0.10442s