logger-tg


Namelogger-tg JSON
Version 0.1.7 PyPI version JSON
download
home_pagehttps://github.com/Nezhinskiy/logger-tg
SummaryAsynchronous Telegram logging for Python applications
upload_time2024-04-04 16:35:38
maintainerNone
docs_urlNone
authorMikhail Nezhinsky
requires_python>=3.6.0
licenseMIT
keywords logger logging telegram async asyncio telegram_logger tg_logger python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# logger-tg
[![PyPI version](https://badge.fury.io/py/logger-tg.svg)](https://badge.fury.io/py/logger-tg)
[![Downloads](https://pepy.tech/badge/logger-tg)](https://pepy.tech/project/logger-tg)
[![Downloads](https://pepy.tech/badge/logger-tg/month)](https://pepy.tech/project/logger-tg)
[![Downloads](https://pepy.tech/badge/logger-tg/week)](https://pepy.tech/project/logger-tg)

`logger-tg` is a Python package that seamlessly integrates logging with Telegram, allowing developers to receive log messages directly in a Telegram chat. This tool is especially useful for monitoring applications in real-time, receiving immediate error notifications, and keeping track of important information without the need to constantly check log files.

## Features
- **Easy Integration:** Set up with just a few lines of code.
- **Real-Time Notifications:** Receive log messages instantly on your Telegram.
- **Flexible Logging Levels:** Supports all standard logging levels (DEBUG, INFO, WARNING, ERROR, CRITICAL).
- **Customizable:** Easily configure the logger to suit your needs, including custom message formatting.
- **Asynchronous Support:** Utilizes asynchronous communication with Telegram for efficient message delivery.
- **Dynamic Logging Methods:** Use custom method names to dynamically log messages at any level, enhancing code readability and simplifying the search for log output locations.

## Installation
`logger-tg` can be installed using pip. Ensure you have Python 3.6 or newer.

```bash
pip install logger-tg
```

## Quick Start
To get started with `logger-tg`, you need to configure it with your Telegram bot token and recipient chat ID. Here's a quick guide:

1. **Create a Telegram Bot:** If you haven't already, create a bot by chatting with [BotFather](https://t.me/botfather) on Telegram and save the bot token.
2. **Find Your Chat ID:** You can use the `@userinfobot` on Telegram to find your chat ID.

## Basic Setup
```python
from logger_tg import configure_logger, BaseLogger

# Configure global settings
configure_logger(bot_token='your_bot_token', recipient_id=your_chat_id)

# Initialize the logger
logger = BaseLogger('MyAppLogger')

# Start logging
logger.info('This is a test message!')
```

## Configuration
Custom Log Handlers
`logger-tg` allows for custom log handlers, enabling you to log to files, console, and Telegram simultaneously.

```python
from logging.handlers import TimedRotatingFileHandler
from logger_tg import BaseLogger, TgLoggerSettings, get_logger

# File handler for logging to a file
file_handler = TimedRotatingFileHandler('app.log', when='midnight', interval=1)
file_handler.suffix = '%Y-%m-%d'

# Console handler for logging to stderr
console_handler = logging.StreamHandler()

# Initialize the logger with custom handlers
logger = get_logger(
    'MyAppLogger',
    console_log_handler=console_handler,
    file_log_handler=file_handler
)

logger.info('Logging to console and file.')
```

## Dynamic Logging Methods
`logger-tg` supports dynamic logging methods, allowing you to log messages at any level with a single line of code. This feature enhances flexibility and readability by letting you specify the log level directly in the method call.

### Example
```python
from logger_tg import BaseLogger

logger = BaseLogger(__name__)
logger.dynamic_method('error', 'An error occurred!')
# output:
# ERROR: dynamic_method: An error occurred!
```
This will log an error message "dynamic_method: An error occurred!" using the dynamic method feature. The first argument after the method name specifies the log level, making it straightforward to adjust the severity of your logs on the fly.

Using dynamic methods not only makes your code more intuitive but also simplifies locating where specific logs are generated, especially when debugging or monitoring your application.

## Advanced Usage
`logger-tg` also supports asynchronous logging to Telegram, which can be particularly useful for applications with high logging throughput or when you wish to avoid blocking the main thread.

Asynchronous Error Logging
To log errors asynchronously to Telegram:

```python
import asyncio
from logger_tg import BaseLogger

logger = BaseLogger('AsyncAppLogger')

async def log_error():
    logger.error('Asynchronous error logging.')

# Running the asynchronous log function
asyncio.run(log_error())
```
This approach ensures that your application remains responsive, even when sending multiple log messages to Telegram.

## Contributing
Contributions are welcome! If you'd like to contribute, please fork the repository and use a main branch. Pull requests are warmly welcome.

## License
`logger-tg` is available under the MIT license. See the [LICENSE](LICENSE) file for more info.

## Acknowledgments
Thanks to the authors of `aiohttp`.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Nezhinskiy/logger-tg",
    "name": "logger-tg",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6.0",
    "maintainer_email": null,
    "keywords": "logger logging telegram async asyncio telegram_logger tg_logger python",
    "author": "Mikhail Nezhinsky",
    "author_email": "mikhail.nezhinsky@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/1b/f9/e0e113a027a49e280d533395fb2431b88c0503fab37ec610d6b4e1812aa2/logger-tg-0.1.7.tar.gz",
    "platform": null,
    "description": "\r\n# logger-tg\r\n[![PyPI version](https://badge.fury.io/py/logger-tg.svg)](https://badge.fury.io/py/logger-tg)\r\n[![Downloads](https://pepy.tech/badge/logger-tg)](https://pepy.tech/project/logger-tg)\r\n[![Downloads](https://pepy.tech/badge/logger-tg/month)](https://pepy.tech/project/logger-tg)\r\n[![Downloads](https://pepy.tech/badge/logger-tg/week)](https://pepy.tech/project/logger-tg)\r\n\r\n`logger-tg` is a Python package that seamlessly integrates logging with Telegram, allowing developers to receive log messages directly in a Telegram chat. This tool is especially useful for monitoring applications in real-time, receiving immediate error notifications, and keeping track of important information without the need to constantly check log files.\r\n\r\n## Features\r\n- **Easy Integration:** Set up with just a few lines of code.\r\n- **Real-Time Notifications:** Receive log messages instantly on your Telegram.\r\n- **Flexible Logging Levels:** Supports all standard logging levels (DEBUG, INFO, WARNING, ERROR, CRITICAL).\r\n- **Customizable:** Easily configure the logger to suit your needs, including custom message formatting.\r\n- **Asynchronous Support:** Utilizes asynchronous communication with Telegram for efficient message delivery.\r\n- **Dynamic Logging Methods:** Use custom method names to dynamically log messages at any level, enhancing code readability and simplifying the search for log output locations.\r\n\r\n## Installation\r\n`logger-tg` can be installed using pip. Ensure you have Python 3.6 or newer.\r\n\r\n```bash\r\npip install logger-tg\r\n```\r\n\r\n## Quick Start\r\nTo get started with `logger-tg`, you need to configure it with your Telegram bot token and recipient chat ID. Here's a quick guide:\r\n\r\n1. **Create a Telegram Bot:** If you haven't already, create a bot by chatting with [BotFather](https://t.me/botfather) on Telegram and save the bot token.\r\n2. **Find Your Chat ID:** You can use the `@userinfobot` on Telegram to find your chat ID.\r\n\r\n## Basic Setup\r\n```python\r\nfrom logger_tg import configure_logger, BaseLogger\r\n\r\n# Configure global settings\r\nconfigure_logger(bot_token='your_bot_token', recipient_id=your_chat_id)\r\n\r\n# Initialize the logger\r\nlogger = BaseLogger('MyAppLogger')\r\n\r\n# Start logging\r\nlogger.info('This is a test message!')\r\n```\r\n\r\n## Configuration\r\nCustom Log Handlers\r\n`logger-tg` allows for custom log handlers, enabling you to log to files, console, and Telegram simultaneously.\r\n\r\n```python\r\nfrom logging.handlers import TimedRotatingFileHandler\r\nfrom logger_tg import BaseLogger, TgLoggerSettings, get_logger\r\n\r\n# File handler for logging to a file\r\nfile_handler = TimedRotatingFileHandler('app.log', when='midnight', interval=1)\r\nfile_handler.suffix = '%Y-%m-%d'\r\n\r\n# Console handler for logging to stderr\r\nconsole_handler = logging.StreamHandler()\r\n\r\n# Initialize the logger with custom handlers\r\nlogger = get_logger(\r\n    'MyAppLogger',\r\n    console_log_handler=console_handler,\r\n    file_log_handler=file_handler\r\n)\r\n\r\nlogger.info('Logging to console and file.')\r\n```\r\n\r\n## Dynamic Logging Methods\r\n`logger-tg` supports dynamic logging methods, allowing you to log messages at any level with a single line of code. This feature enhances flexibility and readability by letting you specify the log level directly in the method call.\r\n\r\n### Example\r\n```python\r\nfrom logger_tg import BaseLogger\r\n\r\nlogger = BaseLogger(__name__)\r\nlogger.dynamic_method('error', 'An error occurred!')\r\n# output:\r\n# ERROR: dynamic_method: An error occurred!\r\n```\r\nThis will log an error message \"dynamic_method: An error occurred!\" using the dynamic method feature. The first argument after the method name specifies the log level, making it straightforward to adjust the severity of your logs on the fly.\r\n\r\nUsing dynamic methods not only makes your code more intuitive but also simplifies locating where specific logs are generated, especially when debugging or monitoring your application.\r\n\r\n## Advanced Usage\r\n`logger-tg` also supports asynchronous logging to Telegram, which can be particularly useful for applications with high logging throughput or when you wish to avoid blocking the main thread.\r\n\r\nAsynchronous Error Logging\r\nTo log errors asynchronously to Telegram:\r\n\r\n```python\r\nimport asyncio\r\nfrom logger_tg import BaseLogger\r\n\r\nlogger = BaseLogger('AsyncAppLogger')\r\n\r\nasync def log_error():\r\n    logger.error('Asynchronous error logging.')\r\n\r\n# Running the asynchronous log function\r\nasyncio.run(log_error())\r\n```\r\nThis approach ensures that your application remains responsive, even when sending multiple log messages to Telegram.\r\n\r\n## Contributing\r\nContributions are welcome! If you'd like to contribute, please fork the repository and use a main branch. Pull requests are warmly welcome.\r\n\r\n## License\r\n`logger-tg` is available under the MIT license. See the [LICENSE](LICENSE) file for more info.\r\n\r\n## Acknowledgments\r\nThanks to the authors of `aiohttp`.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Asynchronous Telegram logging for Python applications",
    "version": "0.1.7",
    "project_urls": {
        "Homepage": "https://github.com/Nezhinskiy/logger-tg"
    },
    "split_keywords": [
        "logger",
        "logging",
        "telegram",
        "async",
        "asyncio",
        "telegram_logger",
        "tg_logger",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1bf9e0e113a027a49e280d533395fb2431b88c0503fab37ec610d6b4e1812aa2",
                "md5": "26b25e62d9c7edef8816e8a7578b9339",
                "sha256": "b25b8b89ec06f06c15324cd391db311b98703ab790766a6b63ecee9bb05ee388"
            },
            "downloads": -1,
            "filename": "logger-tg-0.1.7.tar.gz",
            "has_sig": false,
            "md5_digest": "26b25e62d9c7edef8816e8a7578b9339",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.0",
            "size": 9175,
            "upload_time": "2024-04-04T16:35:38",
            "upload_time_iso_8601": "2024-04-04T16:35:38.778568Z",
            "url": "https://files.pythonhosted.org/packages/1b/f9/e0e113a027a49e280d533395fb2431b88c0503fab37ec610d6b4e1812aa2/logger-tg-0.1.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-04 16:35:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Nezhinskiy",
    "github_project": "logger-tg",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "logger-tg"
}
        
Elapsed time: 0.21762s