# Simple python logs with file rotation
[![Donate](https://img.shields.io/badge/Donate-PayPal-brightgreen.svg?style=plastic)](https://www.paypal.com/ncp/payment/6G9Z78QHUD4RJ)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![PyPi](https://img.shields.io/pypi/v/pythonLogs.svg)](https://pypi.python.org/pypi/pythonLogs)
[![PyPI Downloads](https://static.pepy.tech/badge/pythonLogs)](https://pepy.tech/projects/pythonLogs)
[![codecov](https://codecov.io/gh/ddc/pythonLogs/graph/badge.svg?token=QsjwsmYzgD)](https://codecov.io/gh/ddc/pythonLogs)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A//actions-badge.atrox.dev/ddc/pythonLogs/badge?ref=main&label=build&logo=none)](https://actions-badge.atrox.dev/ddc/pythonLogs/goto?ref=main)
[![Python](https://img.shields.io/pypi/pyversions/pythonLogs.svg)](https://www.python.org)
# Notes
+ Arguments for all classes are declared as OPTIONAL
+ arguments takes priority over environment variables
+ If any [.env](./pythonLogs/.env.example) variable is omitted, it falls back to default values here: [settings.py](pythonLogs/settings.py)
+ Timezone parameter can also accept `localtime`, default to `UTC`
+ This parameter is only to display the timezone datetime inside the log file
+ For timed rotation, only UTC and localtime are supported, meaning it will rotate at UTC or localtime
+ env variable to change between UTC and localtime is `LOG_ROTATE_AT_UTC` and default to True
+ Streamhandler parameter will add stream handler along with file handler
+ Showlocation parameter will show the filename and the line number where the message originated
# Install
```shell
pip install pythonLogs
```
# BasicLog
+ Setup Logging
+ This is just a basic log, it does not use any file
```python
from pythonLogs import BasicLog
logger = BasicLog(
level="debug",
name="app",
timezone="America/Sao_Paulo",
showlocation=False,
).init()
logger.warning("This is a warning example")
```
#### Example of output
`[2024-10-08T19:08:56.918-0300]:[WARNING]:[app]:This is a warning example`
# SizeRotatingLog
+ Setup Logging
+ Logs will rotate based on the file size using the `maxmbytes` variable
+ Rotated logs will have a sequence number starting from 1: `app.log_1.gz, app.log_2.gz`
+ Logs will be deleted based on the `daystokeep` variable, defaults to 30
```python
from pythonLogs import SizeRotatingLog
logger = SizeRotatingLog(
level="debug",
name="app",
directory="/app/logs",
filenames=["main.log", "app1.log"],
maxmbytes=5,
daystokeep=7,
timezone="America/Chicago",
streamhandler=True,
showlocation=False
).init()
logger.warning("This is a warning example")
```
#### Example of output
`[2024-10-08T19:08:56.918-0500]:[WARNING]:[app]:This is a warning example`
# TimedRotatingLog
+ Setup Logging
+ Logs will rotate based on `when` variable to a `.gz` file, defaults to `midnight`
+ Rotated log will have the sufix variable on its name: `app_20240816.log.gz`
+ Logs will be deleted based on the `daystokeep` variable, defaults to 30
+ Current 'when' events supported:
+ midnight — roll over at midnight
+ W{0-6} - roll over on a certain day; 0 - Monday
```python
from pythonLogs import TimedRotatingLog
logger = TimedRotatingLog(
level="debug",
name="app",
directory="/app/logs",
filenames=["main.log", "app2.log"],
when="midnight",
daystokeep=7,
timezone="UTC",
streamhandler=True,
showlocation=False
).init()
logger.warning("This is a warning example")
```
#### Example of output
`[2024-10-08T19:08:56.918-0000]:[WARNING]:[app]:This is a warning example`
## Env Variables (Optional)
```
LOG_LEVEL=DEBUG
LOG_TIMEZONE=America/Chicago
LOG_ENCODING=UTF-8
LOG_APPNAME=app
LOG_FILENAME=app.log
LOG_DIRECTORY=/app/logs
LOG_DAYS_TO_KEEP=30
LOG_STREAM_HANDLER=True
LOG_SHOW_LOCATION=False
LOG_DATE_FORMAT=%Y-%m-%dT%H:%M:%S
# SizeRotatingLog
LOG_MAX_FILE_SIZE_MB=10
# TimedRotatingLog
LOG_ROTATE_WHEN=midnight
LOG_ROTATE_AT_UTC=True
```
# Source Code
### Build
```shell
poetry build -f wheel
```
# Run Tests and Get Coverage Report using Poe
```shell
poetry update --with test
poe test
```
# License
Released under the [MIT License](LICENSE)
# Buy me a cup of coffee
+ [GitHub Sponsor](https://github.com/sponsors/ddc)
+ [ko-fi](https://ko-fi.com/ddcsta)
+ [Paypal](https://www.paypal.com/ncp/payment/6G9Z78QHUD4RJ)
Raw data
{
"_id": null,
"home_page": "https://pypi.org/project/pythonLogs",
"name": "pythonLogs",
"maintainer": "Daniel Costa",
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "python3, python-3, python, log, logging, logger, logutils, log-utils, pythonLogs",
"author": "Daniel Costa",
"author_email": "danieldcsta@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/98/82/5db22a0be75fe19ab59b1d1b2d82aaf3a2b06e5b379c95d91db39bcc91b0/pythonlogs-3.0.13.tar.gz",
"platform": null,
"description": "# Simple python logs with file rotation\n\n[![Donate](https://img.shields.io/badge/Donate-PayPal-brightgreen.svg?style=plastic)](https://www.paypal.com/ncp/payment/6G9Z78QHUD4RJ)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![PyPi](https://img.shields.io/pypi/v/pythonLogs.svg)](https://pypi.python.org/pypi/pythonLogs)\n[![PyPI Downloads](https://static.pepy.tech/badge/pythonLogs)](https://pepy.tech/projects/pythonLogs)\n[![codecov](https://codecov.io/gh/ddc/pythonLogs/graph/badge.svg?token=QsjwsmYzgD)](https://codecov.io/gh/ddc/pythonLogs)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A//actions-badge.atrox.dev/ddc/pythonLogs/badge?ref=main&label=build&logo=none)](https://actions-badge.atrox.dev/ddc/pythonLogs/goto?ref=main)\n[![Python](https://img.shields.io/pypi/pyversions/pythonLogs.svg)](https://www.python.org)\n\n\n\n# Notes\n+ Arguments for all classes are declared as OPTIONAL \n + arguments takes priority over environment variables\n+ If any [.env](./pythonLogs/.env.example) variable is omitted, it falls back to default values here: [settings.py](pythonLogs/settings.py)\n+ Timezone parameter can also accept `localtime`, default to `UTC`\n + This parameter is only to display the timezone datetime inside the log file\n + For timed rotation, only UTC and localtime are supported, meaning it will rotate at UTC or localtime\n + env variable to change between UTC and localtime is `LOG_ROTATE_AT_UTC` and default to True\n+ Streamhandler parameter will add stream handler along with file handler\n+ Showlocation parameter will show the filename and the line number where the message originated\n\n\n\n\n# Install\n```shell\npip install pythonLogs\n```\n\n\n\n# BasicLog\n+ Setup Logging\n + This is just a basic log, it does not use any file\n```python\nfrom pythonLogs import BasicLog\nlogger = BasicLog(\n level=\"debug\",\n name=\"app\",\n timezone=\"America/Sao_Paulo\",\n showlocation=False,\n).init()\nlogger.warning(\"This is a warning example\")\n```\n#### Example of output\n`[2024-10-08T19:08:56.918-0300]:[WARNING]:[app]:This is a warning example`\n\n\n\n\n\n# SizeRotatingLog\n+ Setup Logging\n + Logs will rotate based on the file size using the `maxmbytes` variable\n + Rotated logs will have a sequence number starting from 1: `app.log_1.gz, app.log_2.gz`\n + Logs will be deleted based on the `daystokeep` variable, defaults to 30\n```python\nfrom pythonLogs import SizeRotatingLog\nlogger = SizeRotatingLog(\n level=\"debug\",\n name=\"app\",\n directory=\"/app/logs\",\n filenames=[\"main.log\", \"app1.log\"],\n maxmbytes=5,\n daystokeep=7,\n timezone=\"America/Chicago\",\n streamhandler=True,\n showlocation=False\n).init()\nlogger.warning(\"This is a warning example\")\n```\n#### Example of output\n`[2024-10-08T19:08:56.918-0500]:[WARNING]:[app]:This is a warning example`\n\n\n\n\n\n# TimedRotatingLog\n+ Setup Logging\n + Logs will rotate based on `when` variable to a `.gz` file, defaults to `midnight`\n + Rotated log will have the sufix variable on its name: `app_20240816.log.gz`\n + Logs will be deleted based on the `daystokeep` variable, defaults to 30\n + Current 'when' events supported:\n + midnight \u2014 roll over at midnight\n + W{0-6} - roll over on a certain day; 0 - Monday\n```python\nfrom pythonLogs import TimedRotatingLog\nlogger = TimedRotatingLog(\n level=\"debug\",\n name=\"app\",\n directory=\"/app/logs\",\n filenames=[\"main.log\", \"app2.log\"],\n when=\"midnight\",\n daystokeep=7,\n timezone=\"UTC\",\n streamhandler=True,\n showlocation=False\n).init()\nlogger.warning(\"This is a warning example\")\n```\n#### Example of output\n`[2024-10-08T19:08:56.918-0000]:[WARNING]:[app]:This is a warning example`\n\n\n\n\n\n## Env Variables (Optional)\n```\nLOG_LEVEL=DEBUG\nLOG_TIMEZONE=America/Chicago\nLOG_ENCODING=UTF-8\nLOG_APPNAME=app\nLOG_FILENAME=app.log\nLOG_DIRECTORY=/app/logs\nLOG_DAYS_TO_KEEP=30\nLOG_STREAM_HANDLER=True\nLOG_SHOW_LOCATION=False\nLOG_DATE_FORMAT=%Y-%m-%dT%H:%M:%S\n\n# SizeRotatingLog\nLOG_MAX_FILE_SIZE_MB=10\n\n# TimedRotatingLog\nLOG_ROTATE_WHEN=midnight\nLOG_ROTATE_AT_UTC=True\n```\n\n\n\n\n# Source Code\n### Build\n```shell\npoetry build -f wheel\n```\n\n\n\n# Run Tests and Get Coverage Report using Poe\n```shell\npoetry update --with test\npoe test\n```\n\n\n\n# License\nReleased under the [MIT License](LICENSE)\n\n\n\n\n# Buy me a cup of coffee\n+ [GitHub Sponsor](https://github.com/sponsors/ddc)\n+ [ko-fi](https://ko-fi.com/ddcsta)\n+ [Paypal](https://www.paypal.com/ncp/payment/6G9Z78QHUD4RJ)\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple python logs with file rotation",
"version": "3.0.13",
"project_urls": {
"Homepage": "https://pypi.org/project/pythonLogs",
"Repository": "https://github.com/ddc/pythonLogs"
},
"split_keywords": [
"python3",
" python-3",
" python",
" log",
" logging",
" logger",
" logutils",
" log-utils",
" pythonlogs"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "35de39bf56ee84be57236eb2422f4be2d400e42902dabfe102eeb64011f426f2",
"md5": "2a55c6640064f0c1ec7aeffe467044e5",
"sha256": "992a4a96dd4b9e26ada39fc0f7a8dcaf735d9c3b34d1fbf8f0593c916978ca74"
},
"downloads": -1,
"filename": "pythonlogs-3.0.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2a55c6640064f0c1ec7aeffe467044e5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 11151,
"upload_time": "2024-12-31T15:26:10",
"upload_time_iso_8601": "2024-12-31T15:26:10.692380Z",
"url": "https://files.pythonhosted.org/packages/35/de/39bf56ee84be57236eb2422f4be2d400e42902dabfe102eeb64011f426f2/pythonlogs-3.0.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "98825db22a0be75fe19ab59b1d1b2d82aaf3a2b06e5b379c95d91db39bcc91b0",
"md5": "64348f6a759feda0e8ec89c38e3a7b20",
"sha256": "5a779da4d2f29dce16c9449aab1aa3c32b5b2f3889756264f708ab9013ae32d8"
},
"downloads": -1,
"filename": "pythonlogs-3.0.13.tar.gz",
"has_sig": false,
"md5_digest": "64348f6a759feda0e8ec89c38e3a7b20",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 9910,
"upload_time": "2024-12-31T15:26:12",
"upload_time_iso_8601": "2024-12-31T15:26:12.098877Z",
"url": "https://files.pythonhosted.org/packages/98/82/5db22a0be75fe19ab59b1d1b2d82aaf3a2b06e5b379c95d91db39bcc91b0/pythonlogs-3.0.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-31 15:26:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ddc",
"github_project": "pythonLogs",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pythonlogs"
}