Skip to content

Commit

Permalink
Add configuration value to disable database logging
Browse files Browse the repository at this point in the history
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
  • Loading branch information
r4rdsn committed Jun 13, 2020
1 parent 3139422 commit 400e9f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ DATABASE_NAME=tellerbot
# Logging
LOGGER_LEVEL=INFO
LOG_FILENAME=/var/log/tellerbot.log
DATABASE_LOGGING_ENABLED=true

# Chat IDs
SUPPORT_CHAT_ID=-123456789
Expand Down
20 changes: 13 additions & 7 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@ class TellerBot(Bot):
async def request(self, method, data=None, *args, **kwargs):
"""Make a request and save it in the database."""
result = await super().request(method, data, *args, **kwargs)
if result and method not in (
api.Methods.GET_UPDATES,
api.Methods.SET_WEBHOOK,
api.Methods.DELETE_WEBHOOK,
api.Methods.GET_WEBHOOK_INFO,
api.Methods.GET_ME,
if (
config.DATABASE_LOGGING_ENABLED
and result
and method
not in (
api.Methods.GET_UPDATES,
api.Methods.SET_WEBHOOK,
api.Methods.DELETE_WEBHOOK,
api.Methods.GET_WEBHOOK_INFO,
api.Methods.GET_ME,
)
):
# On requests Telegram either returns True on success or relevant object.
# To store only useful information, method's payload is saved if result is
Expand Down Expand Up @@ -92,7 +97,8 @@ def setup():

logging.basicConfig(level=config.LOGGER_LEVEL)
dp.middleware.setup(LoggingMiddleware())
dp.middleware.setup(IncomingHistoryMiddleware())
if config.DATABASE_LOGGING_ENABLED:
dp.middleware.setup(IncomingHistoryMiddleware())


def private_handler(*args, **kwargs):
Expand Down

0 comments on commit 400e9f2

Please sign in to comment.