-
Notifications
You must be signed in to change notification settings - Fork 1
/
usage.py
38 lines (29 loc) · 930 Bytes
/
usage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
""" telegram-logging usage example
"""
import logging
from telegram_logging import TelegramFormatter, TelegramHandler
formatter = TelegramFormatter(
fmt="[%(asctime)s %(name)s] %(levelname)8s\n\n%(message)s",
datefmt="%d/%m/%Y %H:%M:%S",
use_emoji=True,
# (Optional) If you want to use custom emojis:
emoji_map={
logging.DEBUG: "🐛",
logging.INFO: "💡",
logging.ERROR: "🚨",
})
handler = TelegramHandler(bot_token="<Your Telegram Bot Token>",
chat_id="<Your Telegram Chat ID>")
handler.setFormatter(formatter)
_log = logging.getLogger(__name__)
_log.addHandler(handler)
_log.setLevel(logging.DEBUG)
def main():
_log.debug("Debug message")
_log.info("Info message")
_log.warning("Warning message")
_log.error("Error message")
_log.critical("Critical message")
if __name__ == "__main__":
main()