loggerbot


Nameloggerbot JSON
Version 3.8.8 PyPI version JSON
download
home_pagehttps://ubix.pro/
SummaryA Telegram logging library with rate limiting and message queuing
upload_time2024-10-26 14:59:51
maintainerNone
docs_urlNone
authorN.Sikharulidze
requires_python>=3.6
licenseMIT License Copyright (c) 2023 N.Sikharulidze (https://ubix.pro/) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords telegram logging bot rate-limiting message-queuing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![<img src="https://github.com/NSb0y/loggerbot/raw/main/images/loggerbot.png" width="288"/>](https://github.com/NSb0y/loggerbot/raw/main/images/loggerbot.png)
# LoggerBot

© N.Sikharulidze (https://ubix.pro/)

LoggerBot is a Telegram logging library that allows you to send log messages to one or multiple Telegram chats using a bot. It provides an easy-to-use interface for logging various types of messages and includes features like rate limiting and message queuing.

## Table of Contents

- [Features](#features)
- [Examples](#Examples)
- [Installation](#installation)
- [Usage](#usage)
  - [Basic Usage](#basic-usage)
  - [Advanced Usage](#advanced-usage)
    - [Rate Limiting](#rate-limiting)
    - [Setting Log Level](#setting-log-level)
    - [Using with Python's logging module](#using-with-pythons-logging-module)
    - [HTML Formatting for Log Messages](#html-formatting-for-log-messages)
- [Register a Telegram Bot](#Register-a-Telegram-Bot)
- [Contributing](#contributing)
- [License](#license)

## Features

- Send log messages to one or multiple Telegram chats
- Support for different log levels: debug, info, warning, error, critical, alert, and complete
- Rate limiting to prevent excessive API calls
- Message queuing for smooth operation
- Easy integration with existing Python logging
- Backward compatibility with the `LogBot` alias
- HTML formatting support for log messages

## Examples

### HTML Formatting log example

![<img src="https://github.com/NSb0y/loggerbot/raw/main/images/alertExample2.png" width="248"/>](https://github.com/NSb0y/loggerbot/raw/main/images/alertExample2.png)

### Regular log examples

![<img src="https://github.com/NSb0y/loggerbot/raw/main/images/alertExample.png" width="248"/>](https://github.com/NSb0y/loggerbot/raw/main/images/alertExample.png)

## Installation

You can install LoggerBot using pip:

```
pip install loggerbot
```

Pypi.org (https://pypi.org/project/loggerbot/)

## Usage

Here's a basic example of how to use LoggerBot:

```python
from loggerbot import TelegramLoggingBot

# Initialize the bot with your Telegram bot token and chat ID(s)
log_bot = TelegramLoggingBot("YOUR_BOT_TOKEN", ["CHAT_ID_1", "CHAT_ID_2"])

# Send log messages
log_bot.info("This is an informational message")
log_bot.warning("This is a warning message")
log_bot.error("An error occurred")
log_bot.alert("This is an important alert")
log_bot.complete("Task completed successfully")
```

## Advanced Usage

### Rate Limiting

LoggerBot includes built-in rate limiting to prevent excessive API calls. You can customize the rate limit when initializing the bot:

```python
log_bot = TelegramLoggingBot("YOUR_BOT_TOKEN", "CHAT_ID", rate_limit=20, time_window=60)
```

This sets a limit of 20 messages per 60 seconds.

### Setting Log Level

You can set the minimum log level for the bot:

```python
import logging
log_bot.set_log_level(logging.DEBUG)
```

### Using with Python's logging module

LoggerBot can be integrated with Python's built-in logging module:

```python
import logging
from loggerbot import TelegramLoggingBot

# Create a logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# Create a TelegramLoggingBot instance
tg_handler = TelegramLoggingBot("YOUR_BOT_TOKEN", "CHAT_ID")

# Add the TelegramLoggingBot as a handler to the logger
logger.addHandler(tg_handler)

# Now you can use the logger as usual
logger.info("This message will be sent to Telegram")
```

### HTML Formatting for Log Messages

LoggerBot supports HTML formatting in log messages, allowing you to enhance the readability and structure of your logs in Telegram. Here are some examples of how to use HTML formatting:

```python
# Bold text
log_bot.info("This is an <b>important</b> message")

# Italic text
log_bot.warning("Please <i>be cautious</i> when proceeding")

# Code formatting
log_bot.error("An error occurred: <code>ValueError: Invalid input</code>")

# Underlined text
log_bot.alert("This requires <u>immediate attention</u>")

# Combining multiple formats
log_bot.complete("Task <b><i>successfully</i></b> completed")

# Using line breaks
log_bot.info("This is a multi-line message.<br>It has two lines.")

# Creating a list
log_bot.info("Steps to reproduce:<br>1. Open the app<br>2. Click on settings<br>3. Select 'Advanced'")

# Adding a hyperlink
log_bot.info("For more information, visit our <a href='https://example.com'>documentation</a>")
```

Note: Make sure to use HTML entities for special characters like `<` (`&lt;`), `>` (`&gt;`), and `&` (`&amp;`) when they're not part of HTML tags.

## Register a Telegram Bot

![<img src="https://github.com/NSb0y/loggerbot/raw/main/images/tg2.webp" width="188"/>](https://github.com/NSb0y/loggerbot/raw/main/images/tg2.webp)

To register a Telegram bot and obtain an API key, follow these steps:

1. Open the Telegram app and search for [BotFather](https://t.me/BotFather).
2. Start a chat with BotFather and use the `/newbot` command to create a new bot.
3. Follow the instructions to name your bot and get a unique username.
4. Once your bot is created, you will receive a **Bot Token**. This token is used to authenticate your bot with the Telegram API.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://ubix.pro/",
    "name": "loggerbot",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "telegram, logging, bot, rate-limiting, message-queuing",
    "author": "N.Sikharulidze",
    "author_email": "\"N.Sikharulidze\" <info@ubix.pro>",
    "download_url": "https://files.pythonhosted.org/packages/29/f8/5be8bc2a01c114d88c87fcb2ea7c56adb9e3132c648c584f36c7c30b2f73/loggerbot-3.8.8.tar.gz",
    "platform": null,
    "description": "![<img src=\"https://github.com/NSb0y/loggerbot/raw/main/images/loggerbot.png\" width=\"288\"/>](https://github.com/NSb0y/loggerbot/raw/main/images/loggerbot.png)\r\n# LoggerBot\r\n\r\n\u00a9 N.Sikharulidze (https://ubix.pro/)\r\n\r\nLoggerBot is a Telegram logging library that allows you to send log messages to one or multiple Telegram chats using a bot. It provides an easy-to-use interface for logging various types of messages and includes features like rate limiting and message queuing.\r\n\r\n## Table of Contents\r\n\r\n- [Features](#features)\r\n- [Examples](#Examples)\r\n- [Installation](#installation)\r\n- [Usage](#usage)\r\n  - [Basic Usage](#basic-usage)\r\n  - [Advanced Usage](#advanced-usage)\r\n    - [Rate Limiting](#rate-limiting)\r\n    - [Setting Log Level](#setting-log-level)\r\n    - [Using with Python's logging module](#using-with-pythons-logging-module)\r\n    - [HTML Formatting for Log Messages](#html-formatting-for-log-messages)\r\n- [Register a Telegram Bot](#Register-a-Telegram-Bot)\r\n- [Contributing](#contributing)\r\n- [License](#license)\r\n\r\n## Features\r\n\r\n- Send log messages to one or multiple Telegram chats\r\n- Support for different log levels: debug, info, warning, error, critical, alert, and complete\r\n- Rate limiting to prevent excessive API calls\r\n- Message queuing for smooth operation\r\n- Easy integration with existing Python logging\r\n- Backward compatibility with the `LogBot` alias\r\n- HTML formatting support for log messages\r\n\r\n## Examples\r\n\r\n### HTML Formatting log example\r\n\r\n![<img src=\"https://github.com/NSb0y/loggerbot/raw/main/images/alertExample2.png\" width=\"248\"/>](https://github.com/NSb0y/loggerbot/raw/main/images/alertExample2.png)\r\n\r\n### Regular log examples\r\n\r\n![<img src=\"https://github.com/NSb0y/loggerbot/raw/main/images/alertExample.png\" width=\"248\"/>](https://github.com/NSb0y/loggerbot/raw/main/images/alertExample.png)\r\n\r\n## Installation\r\n\r\nYou can install LoggerBot using pip:\r\n\r\n```\r\npip install loggerbot\r\n```\r\n\r\nPypi.org (https://pypi.org/project/loggerbot/)\r\n\r\n## Usage\r\n\r\nHere's a basic example of how to use LoggerBot:\r\n\r\n```python\r\nfrom loggerbot import TelegramLoggingBot\r\n\r\n# Initialize the bot with your Telegram bot token and chat ID(s)\r\nlog_bot = TelegramLoggingBot(\"YOUR_BOT_TOKEN\", [\"CHAT_ID_1\", \"CHAT_ID_2\"])\r\n\r\n# Send log messages\r\nlog_bot.info(\"This is an informational message\")\r\nlog_bot.warning(\"This is a warning message\")\r\nlog_bot.error(\"An error occurred\")\r\nlog_bot.alert(\"This is an important alert\")\r\nlog_bot.complete(\"Task completed successfully\")\r\n```\r\n\r\n## Advanced Usage\r\n\r\n### Rate Limiting\r\n\r\nLoggerBot includes built-in rate limiting to prevent excessive API calls. You can customize the rate limit when initializing the bot:\r\n\r\n```python\r\nlog_bot = TelegramLoggingBot(\"YOUR_BOT_TOKEN\", \"CHAT_ID\", rate_limit=20, time_window=60)\r\n```\r\n\r\nThis sets a limit of 20 messages per 60 seconds.\r\n\r\n### Setting Log Level\r\n\r\nYou can set the minimum log level for the bot:\r\n\r\n```python\r\nimport logging\r\nlog_bot.set_log_level(logging.DEBUG)\r\n```\r\n\r\n### Using with Python's logging module\r\n\r\nLoggerBot can be integrated with Python's built-in logging module:\r\n\r\n```python\r\nimport logging\r\nfrom loggerbot import TelegramLoggingBot\r\n\r\n# Create a logger\r\nlogger = logging.getLogger(__name__)\r\nlogger.setLevel(logging.INFO)\r\n\r\n# Create a TelegramLoggingBot instance\r\ntg_handler = TelegramLoggingBot(\"YOUR_BOT_TOKEN\", \"CHAT_ID\")\r\n\r\n# Add the TelegramLoggingBot as a handler to the logger\r\nlogger.addHandler(tg_handler)\r\n\r\n# Now you can use the logger as usual\r\nlogger.info(\"This message will be sent to Telegram\")\r\n```\r\n\r\n### HTML Formatting for Log Messages\r\n\r\nLoggerBot supports HTML formatting in log messages, allowing you to enhance the readability and structure of your logs in Telegram. Here are some examples of how to use HTML formatting:\r\n\r\n```python\r\n# Bold text\r\nlog_bot.info(\"This is an <b>important</b> message\")\r\n\r\n# Italic text\r\nlog_bot.warning(\"Please <i>be cautious</i> when proceeding\")\r\n\r\n# Code formatting\r\nlog_bot.error(\"An error occurred: <code>ValueError: Invalid input</code>\")\r\n\r\n# Underlined text\r\nlog_bot.alert(\"This requires <u>immediate attention</u>\")\r\n\r\n# Combining multiple formats\r\nlog_bot.complete(\"Task <b><i>successfully</i></b> completed\")\r\n\r\n# Using line breaks\r\nlog_bot.info(\"This is a multi-line message.<br>It has two lines.\")\r\n\r\n# Creating a list\r\nlog_bot.info(\"Steps to reproduce:<br>1. Open the app<br>2. Click on settings<br>3. Select 'Advanced'\")\r\n\r\n# Adding a hyperlink\r\nlog_bot.info(\"For more information, visit our <a href='https://example.com'>documentation</a>\")\r\n```\r\n\r\nNote: Make sure to use HTML entities for special characters like `<` (`&lt;`), `>` (`&gt;`), and `&` (`&amp;`) when they're not part of HTML tags.\r\n\r\n## Register a Telegram Bot\r\n\r\n![<img src=\"https://github.com/NSb0y/loggerbot/raw/main/images/tg2.webp\" width=\"188\"/>](https://github.com/NSb0y/loggerbot/raw/main/images/tg2.webp)\r\n\r\nTo register a Telegram bot and obtain an API key, follow these steps:\r\n\r\n1. Open the Telegram app and search for [BotFather](https://t.me/BotFather).\r\n2. Start a chat with BotFather and use the `/newbot` command to create a new bot.\r\n3. Follow the instructions to name your bot and get a unique username.\r\n4. Once your bot is created, you will receive a **Bot Token**. This token is used to authenticate your bot with the Telegram API.\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a Pull Request.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 N.Sikharulidze (https://ubix.pro/)  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A Telegram logging library with rate limiting and message queuing",
    "version": "3.8.8",
    "project_urls": {
        "Bug Tracker": "https://github.com/NSb0y/loggerbot/issues",
        "Documentation": "https://github.com/NSb0y/loggerbot",
        "Homepage": "https://ubix.pro/",
        "Repository": "https://github.com/NSb0y/loggerbot"
    },
    "split_keywords": [
        "telegram",
        " logging",
        " bot",
        " rate-limiting",
        " message-queuing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4fb5405e4411b82dc8d8ba6107f3d3287ab2366cf584b92b2d2ee71b8b389840",
                "md5": "7a96102cc7362a3692b68aa6c780cbdf",
                "sha256": "d31303911f58f67a6baefabcfb859f68e03224e8f0011241bf3ed1a32ae907ed"
            },
            "downloads": -1,
            "filename": "loggerbot-3.8.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7a96102cc7362a3692b68aa6c780cbdf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 8090,
            "upload_time": "2024-10-26T14:59:49",
            "upload_time_iso_8601": "2024-10-26T14:59:49.800499Z",
            "url": "https://files.pythonhosted.org/packages/4f/b5/405e4411b82dc8d8ba6107f3d3287ab2366cf584b92b2d2ee71b8b389840/loggerbot-3.8.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "29f85be8bc2a01c114d88c87fcb2ea7c56adb9e3132c648c584f36c7c30b2f73",
                "md5": "e72e3d9f5d6e9420c51b75fe27a8034a",
                "sha256": "50f154ca614430698c456e2963b2340b0f08f050a4bee46203bfe9c6e7cf6e00"
            },
            "downloads": -1,
            "filename": "loggerbot-3.8.8.tar.gz",
            "has_sig": false,
            "md5_digest": "e72e3d9f5d6e9420c51b75fe27a8034a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 8895,
            "upload_time": "2024-10-26T14:59:51",
            "upload_time_iso_8601": "2024-10-26T14:59:51.246940Z",
            "url": "https://files.pythonhosted.org/packages/29/f8/5be8bc2a01c114d88c87fcb2ea7c56adb9e3132c648c584f36c7c30b2f73/loggerbot-3.8.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-26 14:59:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NSb0y",
    "github_project": "loggerbot",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "loggerbot"
}
        
Elapsed time: 0.37315s