pyTelegramLogger


NamepyTelegramLogger JSON
Version 1.0.4 PyPI version JSON
download
home_pagehttps://github.com/V-ampire/pyTelegramLogger
SummaryThis package provides handlers to send logging messages to telegram chats.
upload_time2022-12-18 08:55:21
maintainer
docs_urlNone
authorV-ampire
requires_python>=3.6.0
licenseMIT
keywords telegram logger logging telegram_logger
VCS
bugtrack_url
requirements requests
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# pyTelegramLogger

## Description
This package provides handlers to send logging messages to telegram chats. It uses a separate thread for handling messages (see [logging.QueueHandler](https://docs.python.org/3/library/logging.handlers.html#queuehandler) for details). You can send messages to multiple chats, including big messages (over 4096 chars). Big messages will be split into several parts and tagged by unique hashtag for current log record.

## Installation

```
$ pip install pyTelegramLogger
$ pipenv install pyTelegramLogger
```

## Usage

1. Configure logger
```
LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'telegram': {
            'class': 'telegram_logger.TelegramHandler',
            'chat_ids': [123456, 123456789],
            'token': 'bot_token,
        },
    },
    'loggers': {
        'telegram': {
            'handlers': ['telegram'],
        }
    }
}
```

2. Usage
```
# Run once at startup:
logging.config.dictConfig(LOGGING_CONFIG)

# Include to send logging messages to telegram
logger = logging.getLogger('telegram')

logger.warning('Warning message!')
```

## FAQ

### 1. Can I use my own formatter class for messages?

Yes you can. You can inherit from base class `telegram_logger.TelegramFormatter` and define how to send big messages (over 4096 chars) in method `format_by_fragments(self, record: logging.LogRecord, start: int=0) -> List[str]`.
Also you can use your own formatter class.
Then configure using standart configuration dictionary schema:
```
LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'myFormattrer': {
            'class': 'MyFormatterClass',
            'fmt': '%(levelname)_%(name) : %(funcName)'
        }
    }
    'handlers': {
        'telegram': {
            'class': 'telegram_logger.TelegramHandler',
            'chat_ids': [123456, 123456789],
            'token': 'bot_token,
            'formatter': 'myFormattrer',
        },
    },
    'loggers': {
        'telegram': {
            'handlers': ['telegram'],
        }
    }
}
```


### 2. What if I don't want to send messages to telegram during development?

Sometimes, when you just develope you app and you dont want to send log messages to telegram, but want to control it use `telegram_logger.TelegramStreamHandler(cht_ids, token, stream=None)` which streams dict with message text and params instead of send it to telegram.


### 3. Can I use a proxy for sending messages?

Yes you can. You can specify proxy in key of config `proxies` using dict format as [requests](https://requests.readthedocs.io/en/master/):

```
proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}

LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'telegram': {
            'class': 'telegram_logger.TelegramHandler',
            'chat_ids': [123456, 123456789],
            'token': 'bot_token,
            'proxies': proxies,
        },
    },
    'loggers': {
        'telegram': {
            'handlers': ['telegram'],
        }
    }
}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/V-ampire/pyTelegramLogger",
    "name": "pyTelegramLogger",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6.0",
    "maintainer_email": "",
    "keywords": "telegram,logger,logging,telegram_logger",
    "author": "V-ampire",
    "author_email": "webjob010@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6f/a1/e6d7d95fef33590b8cff32bdd8c94459a0e3529356ad53d57f817fd44832/pyTelegramLogger-1.0.4.tar.gz",
    "platform": null,
    "description": "\n# pyTelegramLogger\n\n## Description\nThis package provides handlers to send logging messages to telegram chats. It uses a separate thread for handling messages (see [logging.QueueHandler](https://docs.python.org/3/library/logging.handlers.html#queuehandler) for details). You can send messages to multiple chats, including big messages (over 4096 chars). Big messages will be split into several parts and tagged by unique hashtag for current log record.\n\n## Installation\n\n```\n$ pip install pyTelegramLogger\n$ pipenv install pyTelegramLogger\n```\n\n## Usage\n\n1. Configure logger\n```\nLOGGING_CONFIG = {\n    'version': 1,\n    'disable_existing_loggers': False,\n    'handlers': {\n        'telegram': {\n            'class': 'telegram_logger.TelegramHandler',\n            'chat_ids': [123456, 123456789],\n            'token': 'bot_token,\n        },\n    },\n    'loggers': {\n        'telegram': {\n            'handlers': ['telegram'],\n        }\n    }\n}\n```\n\n2. Usage\n```\n# Run once at startup:\nlogging.config.dictConfig(LOGGING_CONFIG)\n\n# Include to send logging messages to telegram\nlogger = logging.getLogger('telegram')\n\nlogger.warning('Warning message!')\n```\n\n## FAQ\n\n### 1. Can I use my own formatter class for messages?\n\nYes you can. You can inherit from base class `telegram_logger.TelegramFormatter` and define how to send big messages (over 4096 chars) in method `format_by_fragments(self, record: logging.LogRecord, start: int=0) -> List[str]`.\nAlso you can use your own formatter class.\nThen configure using standart configuration dictionary schema:\n```\nLOGGING_CONFIG = {\n    'version': 1,\n    'disable_existing_loggers': False,\n    'formatters': {\n        'myFormattrer': {\n            'class': 'MyFormatterClass',\n            'fmt': '%(levelname)_%(name) : %(funcName)'\n        }\n    }\n    'handlers': {\n        'telegram': {\n            'class': 'telegram_logger.TelegramHandler',\n            'chat_ids': [123456, 123456789],\n            'token': 'bot_token,\n            'formatter': 'myFormattrer',\n        },\n    },\n    'loggers': {\n        'telegram': {\n            'handlers': ['telegram'],\n        }\n    }\n}\n```\n\n\n### 2. What if I don't want to send messages to telegram during development?\n\nSometimes, when you just develope you app and you dont want to send log messages to telegram, but want to control it use `telegram_logger.TelegramStreamHandler(cht_ids, token, stream=None)` which streams dict with message text and params instead of send it to telegram.\n\n\n### 3. Can I use a proxy for sending messages?\n\nYes you can. You can specify proxy in key of config `proxies` using dict format as [requests](https://requests.readthedocs.io/en/master/):\n\n```\nproxies = {\n  'http': 'http://10.10.1.10:3128',\n  'https': 'http://10.10.1.10:1080',\n}\n\nLOGGING_CONFIG = {\n    'version': 1,\n    'disable_existing_loggers': False,\n    'handlers': {\n        'telegram': {\n            'class': 'telegram_logger.TelegramHandler',\n            'chat_ids': [123456, 123456789],\n            'token': 'bot_token,\n            'proxies': proxies,\n        },\n    },\n    'loggers': {\n        'telegram': {\n            'handlers': ['telegram'],\n        }\n    }\n}\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "This package provides handlers to send logging messages to telegram chats.",
    "version": "1.0.4",
    "split_keywords": [
        "telegram",
        "logger",
        "logging",
        "telegram_logger"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "037a7ae9555be3661ad1e96138c88d73",
                "sha256": "f0845c7651a367bce50a407059006a1dfbd2d84a7f9f0cb713b527053de73eb0"
            },
            "downloads": -1,
            "filename": "pyTelegramLogger-1.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "037a7ae9555be3661ad1e96138c88d73",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.0",
            "size": 7812,
            "upload_time": "2022-12-18T08:55:19",
            "upload_time_iso_8601": "2022-12-18T08:55:19.659767Z",
            "url": "https://files.pythonhosted.org/packages/08/f1/a8eaffb58f0f504232b4fc45a2c67b9e6808139c9ea0d255250cdbbbcdc1/pyTelegramLogger-1.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "f6aab5d15456e5f15f978b1d6b08ca07",
                "sha256": "313b3aa2aed283a65d255e2353b0bf34bfc2df547240844def30cb65a3f203e3"
            },
            "downloads": -1,
            "filename": "pyTelegramLogger-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "f6aab5d15456e5f15f978b1d6b08ca07",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.0",
            "size": 7981,
            "upload_time": "2022-12-18T08:55:21",
            "upload_time_iso_8601": "2022-12-18T08:55:21.399384Z",
            "url": "https://files.pythonhosted.org/packages/6f/a1/e6d7d95fef33590b8cff32bdd8c94459a0e3529356ad53d57f817fd44832/pyTelegramLogger-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-18 08:55:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "V-ampire",
    "github_project": "pyTelegramLogger",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.24.0"
                ]
            ]
        }
    ],
    "lcname": "pytelegramlogger"
}
        
Elapsed time: 0.01983s