A lightweight and efficient asynchronous logging package for logging messages to the console and files. Supports colored output, dynamic log paths, and customizable log levels.
- Asynchronous Logging: Non-blocking logging for improved performance.
- Console and File Logging: Supports simultaneous logging to console and files.
- Colored Output: Differentiates log levels using colors for better readability.
- Dynamic Log Paths: Change log file paths dynamically without restarting.
- Custom Log Levels: Define and configure custom logging levels.
pip install asynclogger
from asynclogger import logger
logger.config('./logs/test.log', log_to_console=True)
async def main():
await logger.info('Hello, world!')
if __name__ == '__main__':
asyncio.run(main())
Option | Type | Default | Description |
---|---|---|---|
log_format |
String | {isoformat} {group} {level} {message} |
Format used for logging messages. |
output |
List | ["console"] |
Specifies outputs. |
colorize |
Boolean or Dict | True |
Takes either a boolean or a dict specifying a color for each log level. |
wrapper |
Dict | {} |
Contains a dict of wrapper functions for each format variable (isoformat, group, level ...). |
logger.config('./logs/%Y/%B/{safedate}.log', log_to_console=True)
await logger.log('custom', 'This is a custom log level message')
from colorist import Color
logger.config('./logs/test.log', log_to_console=True, colorize={
'ERROR': Color.GREEN
})
logger.config('./logs/test.log', log_to_console=True, wrapper={'group': lambda x: f'({x})'})
MIT