Skip to content

Commit

Permalink
v3.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
ddc committed Jan 3, 2025
1 parent 1ee758e commit 47ac3b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 158 deletions.
153 changes: 4 additions & 149 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,152 +10,7 @@
[![Python](https://img.shields.io/pypi/pyversions/ddclogs.svg)](https://www.python.org)



# Logs
+ Parameters for all classes are declared as OPTIONAL
+ If any [.env](./ddcLogs/.env.example) variable is omitted, it falls back to default values here: [settings.py](ddcLogs/settings.py)
+ Function arguments will overwrite any env variable
+ 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 ddcLogs
```



# BasicLog
+ Setup Logging
+ This is just a basic log, it does not use any file
```python
from ddcLogs 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 ddcLogs 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 ddcLogs 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 tests
```



# 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)
# DISCONTINUED
### This project moved to:
+ https://github.com/ddc/pythonLogs
+ https://pypi.org/project/pythonLogs
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "ddcLogs"
version = "3.0.11"
version = "3.0.12"
description = "Easy logs with rotations"
license = "MIT"
readme = "README.md"
Expand Down Expand Up @@ -44,7 +44,7 @@ pytz = "^2024.2"

[tool.poetry.group.test.dependencies]
coverage = "^7.6.9"
poethepoet = "^0.31.1"
poethepoet = "^0.32.0"
pytest = "^8.3.4"


Expand Down

0 comments on commit 47ac3b5

Please sign in to comment.