prevent creating dupliacted log handler and remove unused
This commit is contained in:
parent
a96f40f7a2
commit
4c11286f95
2 changed files with 24 additions and 27 deletions
47
log.py
47
log.py
|
@ -2,32 +2,33 @@ import logging
|
||||||
|
|
||||||
|
|
||||||
def getlogger():
|
def getlogger():
|
||||||
# create a custom logger
|
# create a custom logger if no log handler
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
if not logger.hasHandlers():
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
# create handlers
|
||||||
|
warn_handler = logging.StreamHandler()
|
||||||
|
info_handler = logging.StreamHandler()
|
||||||
|
error_handler = logging.FileHandler('bot.log', mode='a')
|
||||||
|
warn_handler.setLevel(logging.WARNING)
|
||||||
|
error_handler.setLevel(logging.ERROR)
|
||||||
|
info_handler.setLevel(logging.INFO)
|
||||||
|
|
||||||
# create handlers
|
# create formatters
|
||||||
warn_handler = logging.StreamHandler()
|
warn_format = logging.Formatter(
|
||||||
info_handler = logging.StreamHandler()
|
'%(name)s - %(funcName)s - %(levelname)s - %(message)s')
|
||||||
error_handler = logging.FileHandler('bot.log', mode='a')
|
error_format = logging.Formatter(
|
||||||
warn_handler.setLevel(logging.WARNING)
|
'%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
|
||||||
error_handler.setLevel(logging.ERROR)
|
info_format = logging.Formatter('%(message)s')
|
||||||
info_handler.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
# create formatters
|
# set formatter
|
||||||
warn_format = logging.Formatter(
|
warn_handler.setFormatter(warn_format)
|
||||||
'%(name)s - %(funcName)s - %(levelname)s - %(message)s')
|
error_handler.setFormatter(error_format)
|
||||||
error_format = logging.Formatter(
|
info_handler.setFormatter(info_format)
|
||||||
'%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
|
|
||||||
info_format = logging.Formatter('%(message)s')
|
|
||||||
|
|
||||||
# set formatter
|
# add handlers to logger
|
||||||
warn_handler.setFormatter(warn_format)
|
logger.addHandler(warn_handler)
|
||||||
error_handler.setFormatter(error_format)
|
logger.addHandler(error_handler)
|
||||||
info_handler.setFormatter(info_format)
|
logger.addHandler(info_handler)
|
||||||
|
|
||||||
# add handlers to logger
|
|
||||||
logger.addHandler(warn_handler)
|
|
||||||
logger.addHandler(error_handler)
|
|
||||||
logger.addHandler(info_handler)
|
|
||||||
|
|
||||||
return logger
|
return logger
|
||||||
|
|
4
main.py
4
main.py
|
@ -1,8 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import signal
|
|
||||||
from functools import partial
|
|
||||||
from bot import Bot
|
from bot import Bot
|
||||||
from log import getlogger
|
from log import getlogger
|
||||||
|
|
||||||
|
@ -53,6 +51,4 @@ async def main():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logger.info("matrix chatgpt bot start.....")
|
logger.info("matrix chatgpt bot start.....")
|
||||||
print("matrix chatgpt bot start.....")
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue