High-level wrapper for aiologger. Asynchronous logging with automatic log directory management and daily file rotation.
Project description
Asynchronous high-level logging wrapper (via aiologger)
📦 Package Info
Attention! ⚠
This wrapper is not complete, the functionality may change depending on the versions
🔹Main function:
🔶 Asynchronous logging with recording to a file of "today" day
🔹Installation?:🧩
pip install aiologger_x9_wrapper
Attention! This module will not work without the libraries: aiofiles, aiologger
🔹Import the dependencies:
from aiologger_x9_wrapper import (
# Enums: (Required)
"Levels",
"LogFormats",
# Main classes: (Required)
"LogFormatter",
"FolderHandler",
"Logger",
# Functions:
"shutdown_loggers", # Required if you want to manually clean up storage
# Internals: (Optional)
"LOGGERS_STORAGE",
"FormatterDTO",
"FolderHandlerDTO",
"AsyncLogger",
)
🔹Quick Reference on Dependencies:
Levels -> Enum class with allowed logging levels
LogFormats -> Enum class with allowed parts of log output format
LogFormatter -> Determines the format of log output (What will be written to the log, with what separator, in what time format)
FolderHandler -> Determines the name and location of the directory for log files.
Logger -> Main logging configuration class. Accepts formatter and file handler and also a logger storage (Optional)
shutdown_loggers -> logger storage clearing function. If no storage is passed, the base one is cleared
LOGGERS_STORAGE -> Basic Logger Storage
FormatterDTO -> handler dataclass
FolderHandlerDTO -> handler dataclass
AsyncLogger -> A custom type used for annotations, typically logger store values: Dict[str, AsyncLogger]
🔹How to use?:
Define the required log output format using LogFormatter:
MY_LOG_FORMATTER: LogFormatter = LogFormatter(
log_format=(LogFormats.TIME, LogFormats.NAME, LogFormats.LEVEL, LogFormats.MESSAGE), # default
separator=" - ", # default
datettime_format= "%d.%m.%Y %H:%M" # default
)
Define the attributes of the created folder via the FolderHandler class:
MY_FOLDER_HANDLER: FolderHandler = FolderHandler(
path=Path(__file__).parent, # Required, or path="log_folder"
name="logs" # default
)
Define a logger with created configurations:
# Optional: create our own logger storage
CUSTOM_LOGGER_STORAGE: Dict[str, AsyncLogger] = {}
MY_LOGGER: Logger = Logger(
log_formatter=MY_LOG_FORMATTER,
folder_handler=MY_FOLDER_HANDLER,
loggers_storage=CUSTOM_LOGGER_STORAGE
)
Use the write_log method of the created class instance:
await MY_LOGGER.write_log(
log_level=Levels.INFO/DEBUG/WARNING/ERROR/CRITICAL,
message="Hello world!",
logger_name="SERVICE" # Optional
)
If you want to manually clear the storage, use the shutdown_loggers function:
await shutdown_loggers(loggers_storage=CUSTOM_LOGGER_STORAGE)
# If loggers_storage was not passed, the underlying storage is used
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiologger_x9_wrapper-0.2.2.tar.gz.
File metadata
- Download URL: aiologger_x9_wrapper-0.2.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
601d10fdb0844dc62e168d3af949885c89ba9e62722c12c3d74db02c173f8131
|
|
| MD5 |
ac9aa27aa296bda9bccb48a5e488f1eb
|
|
| BLAKE2b-256 |
6268a83336aa1e8d65de247a0cb4c83150ea348f592a9be8fcb8097fc2ffeff5
|
File details
Details for the file aiologger_x9_wrapper-0.2.2-py3-none-any.whl.
File metadata
- Download URL: aiologger_x9_wrapper-0.2.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f23ba54b1d0a93ace7b0db5defae4f3b72c4a5050d48680d9cf52d630e162c2a
|
|
| MD5 |
ca5e8cd17e7b2e95bf39c04de28b1c1d
|
|
| BLAKE2b-256 |
2e078322fce916285dd1f87b55546faf9aa2dde041565278dddc736ee29742ad
|