def get_logger(name, user_id): temp_logger = logging.getLogger(name) while temp_logger.handlers: temp_logger.removeHandler(temp_logger.handlers[0]) temp_logger.setLevel(logging.INFO) tg_logger.setup(temp_logger, token=BOT_TOKEN, users=[user_id]) return temp_logger
def instance(cls): if cls._instance is None: cls._instance = logging.getLogger('app.tg') cls._instance.setLevel(logging.ERROR) tg_logger.setup(cls._instance, token=os.getenv('TELEGRAM_LOGGER_BOT_TOKEN'), users=[int(os.getenv('TELEGRAM_LOGGER_CHAT_ID'))]) return cls._instance
# ------------- flask config ------------- ADMIN_PASSWORD = os.environ.get('ADMIN_PASSWORD') app = Flask(__name__) # ------------- bot config ------------- WEBHOOK_TOKEN = os.environ.get('WEBHOOK_TOKEN') BOT_TOKEN = os.environ.get('BOT_TOKEN') bot = telebot.TeleBot(BOT_TOKEN) # ------------- log --------------- users = [int(os.environ.get("ADMIN_ID"))] alpha_logger = logging.getLogger() alpha_logger.setLevel(logging.INFO) tg_logger.setup(alpha_logger, token=os.environ.get("LOG_BOT_TOKEN"), users=users) tg_logger.setup(app.logger, token=os.environ.get("LOG_BOT_TOKEN"), users=users) logger = logging.getLogger("wifi-qr-bot") # --------------- temp folder & qr-code setup --------------- TEMP_FOLDER = 'temp' SPECIAL_CHARACTERS = '\;,:"' AuthType = {'WPA': 'WPA', 'WPA2': 'WPA', 'WEP': 'WEP', 'nopass': '******'} # -------------- status webpage -------------- @app.route('/')
# Copyright (c) ChernV (@otter18), 2021. 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 tg_logger.setup(logger, token=token, users=users) # Test logger.info("Hello from tg_logger by otter18") # TgFileLogger example tg_files_logger = tg_logger.TgFileLogger( token=token, # tg bot token users=users, # list of user_id timeout=10 # default is 10 seconds ) file_name = "test.txt" with open(file_name, 'w') as example_file: example_file.write("Hello from tg_logger by otter18")