Skip to content

Commit

Permalink
Merge pull request #6 from otter18/beta
Browse files Browse the repository at this point in the history
version 3.3
  • Loading branch information
otter18 authored Dec 31, 2021
2 parents 66d5c20 + 1ebbc9e commit 69c60ba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Demo is available [@tg_logger_demo_bot](https://t.me/tg_logger_demo_bot), [[repo
- [Examples](#-examples)
* [Simple logging](#simple-logging)
* [Flask logging](#flask-logging)
* [Setting extra parameters to handler](#setting-extra-parameters-to-handler)
* [TgFileLogger example](#tgfilelogger-example)
- [FQA](#-fqa)
* [How to create a telegram bot?](#how-to-create-a-telegram-bot)
Expand Down Expand Up @@ -80,6 +81,30 @@ if __name__ == '__main__':

```

### Setting extra parameters to handler

```python
import logging
import tg_logger

# Telegram data
token = "1234567890:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
users = [1111111111]

# Base logger
logger = logging.getLogger('foo')
logger.setLevel(logging.INFO)

# Logging bridge setup
handler = tg_logger.setup(logger, token=token, users=users)

# Setting extra params
handler.setLevel(logging.DEBUG)

# Test
logger.info("Hello from tg_logger by otter18")
```

### TgFileLogger example
```python
import tg_logger
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="tg_logger",
version="3.1",
version="3.3",
description="A tool to bridge python logging and user files to telegram bot",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand All @@ -11,7 +11,7 @@
url="https://github.com/otter18/tg_logger",
packages=find_packages(),
install_requires=[
"pyTelegramBotAPI==3.7.6",
"pyTelegramBotAPI>=3.7.6",
],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
4 changes: 3 additions & 1 deletion tg_logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setup(base_logger: logging.Logger = logging.getLogger(),
:param timeout: seconds for retrying to send log if error occupied
:param tg_format: logging format for tg messages (html parse mode)
:return: None
:return: logging.StreamHandler
"""
# Logging format
formatter = logging.Formatter(tg_format)
Expand All @@ -34,3 +34,5 @@ def setup(base_logger: logging.Logger = logging.getLogger(),
)
tg_handler.setFormatter(formatter)
base_logger.addHandler(tg_handler)

return tg_handler

0 comments on commit 69c60ba

Please sign in to comment.