From 6a18cef002be39973b9efc9c6e20134cc93b51eb Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sat, 23 Jan 2021 20:48:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20=E4=BF=AE=E5=A4=8D=E8=87=B4?= =?UTF-8?q?=E5=91=BD=E6=97=A5=E5=BF=97=E5=8A=A0=E8=BD=BD=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20(#45)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update __init__.py --- pagermaid/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pagermaid/__init__.py b/pagermaid/__init__.py index d88a63c..982c1c1 100644 --- a/pagermaid/__init__.py +++ b/pagermaid/__init__.py @@ -7,6 +7,7 @@ from sys import version_info, platform from yaml import load, FullLoader from shutil import copyfile from redis import StrictRedis +from logging import getLogger, INFO, DEBUG, StreamHandler, basicConfig from distutils2.util import strtobool from coloredlogs import ColoredFormatter from telethon import TelegramClient @@ -17,6 +18,14 @@ working_dir = getcwd() config = None help_messages = {} posthog.api_key = '1WepU-o7JwNKYqPNymWr_mrCu3RVPD-p28PUikPDfsI' +logs = getLogger(__name__) +logging_format = "%(levelname)s [%(asctime)s] [%(name)s] %(message)s" +logging_handler = StreamHandler() +logging_handler.setFormatter(ColoredFormatter(logging_format)) +logs.addHandler(logging_handler) +basicConfig(level=INFO) +getLogger('telethon').setLevel(INFO) +logs.setLevel(INFO) try: config = load(open(r"config.yml"), Loader=FullLoader) @@ -26,6 +35,12 @@ except FileNotFoundError: exit(1) +if strtobool(config['debug']): + logs.setLevel(DEBUG) +else: + logs.setLevel(INFO) + + if platform == "linux" or platform == "linux2" or platform == "darwin" or platform == "freebsd7" \ or platform == "freebsd8" or platform == "freebsdN" or platform == "openbsd6": logs.info(