Logging can be configured now, just like in Nextbot
This commit is contained in:
parent
d1f722ff0d
commit
7267588e74
29
bot.py
29
bot.py
@ -16,22 +16,31 @@ from telegram.ext.dispatcher import run_async
|
|||||||
|
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
# Logging
|
|
||||||
logging.basicConfig(
|
|
||||||
format="%(asctime)s - %(levelname)s: %(message)s",
|
|
||||||
datefmt="%d.%m.%Y %H:%M:%S",
|
|
||||||
level=logging.INFO
|
|
||||||
)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
# Bot configuration
|
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
try:
|
try:
|
||||||
config.read_file(open('config.ini'))
|
config.read_file(open('config.ini'))
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.critical('Config.ini nicht gefunden')
|
logging.critical('Config.ini nicht gefunden')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
try:
|
||||||
|
logging_conf = config["LOGGING"]
|
||||||
|
logging_level = logging_conf.get("level", "INFO")
|
||||||
|
logging_format = logging_conf.get("format", "%(asctime)s - %(levelname)s: %(message)s", raw=True)
|
||||||
|
if logging_level not in ["DEBUG", "INFO", "CRITICAL", "ERROR", "WARNING"]:
|
||||||
|
logging.warning("Logging Level invalid. Will be changed to WARNING")
|
||||||
|
logging.basicConfig(format=logging_format, level=logging.INFO, datefmt="%d.%m.%Y %H:%M:%S")
|
||||||
|
else:
|
||||||
|
logging.basicConfig(format=logging_format,
|
||||||
|
level=eval("logging.{0}".format(logging_level.upper())),
|
||||||
|
datefmt="%d.%m.%Y %H:%M:%S")
|
||||||
|
except KeyError:
|
||||||
|
logging.basicConfig(format="%(asctime)s - %(levelname)s: %(message)s",
|
||||||
|
level=logging.INFO,
|
||||||
|
datefmt="%d.%m.%Y %H:%M:%S")
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Bot token
|
# Bot token
|
||||||
try:
|
try:
|
||||||
bot_token = config['DEFAULT']['token']
|
bot_token = config['DEFAULT']['token']
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
token = 1337:1234567890abcdefgh
|
token = 1337:1234567890abcdefgh
|
||||||
|
|
||||||
|
[LOGGING]
|
||||||
|
# Valid options are ERROR, INFO, DEBUG, CRITICAL, WARNING
|
||||||
|
#level = INFO
|
||||||
|
#format = %(asctime)s - %(levelname)s: %(message)s
|
||||||
|
|
||||||
[REDIS]
|
[REDIS]
|
||||||
#db = 0
|
#db = 0
|
||||||
#host = localhost
|
#host = localhost
|
||||||
|
Reference in New Issue
Block a user