Custom log with rotations
Project description
Log Functions
Install
pip install ddcLogs
BasicLog
- Setup Logging
from ddcLogs import BasicLog
logger = BasicLog(level="info").init()
logger.warning("This is a warning example")
SizeRotatingLog
- Setup Logging
- Logs will rotate based on the file size
- Logs will be deleted based on the
days_to_keep
variable, defaults to 30
from ddcLogs import SizeRotatingLog
logger = SizeRotatingLog(
level = "info",
directory = "logs",
filenames = ["app.log", "app1.log"],
days_to_keep = 7,
max_mbytes = 5,
name = "app_name",
stream_handler = True, # Add stream handler along with file handler
show_location = False # This will show the filename and the line number where the message originated
).init()
logger.warning("This is a warning example")
TimedRotatingLog
- Setup Logging
- Logs will rotate based on
when
variable to a.gz
file, defaults tomidnight
- Logs will be deleted based on the
days_to_keep
variable, defaults to 30 - Current 'when' events supported:
- midnight - roll over at midnight
- W{0-6} - roll over on a certain day; 0 - Monday
- Logs will rotate based on
from ddcLogs import TimedRotatingLog
logger = TimedRotatingLog(
level = "info",
directory = "logs",
filenames = ["app.log", "app1.log"],
days_to_keep = 7,
when = "midnight",
utc = True,
name = "app_name",
stream_handler = True, # Add stream handler along with file handler
show_location = False # This will show the filename and the line number where the message originated
).init()
logger.warning("This is a warning example")
Example of output
[2024-10-08T19:08:56.918]:[WARNING]:[app_name]:This is a warning example
Source Code
Build
poetry build -f wheel
Publish to test pypi
poetry publish -r test-pypi
Publish to pypi
poetry publish
Run Tests
poetry run coverage run -m pytest -v
Get Coverage Report
poetry run coverage report
License
Released under the MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ddclogs-2.0.5.tar.gz
(6.1 kB
view hashes)