Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用项目logger而不是系统默认logging全局记录 #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dc3l1ne
Copy link

@dc3l1ne dc3l1ne commented Aug 31, 2023

  • BUG描述:在pycqBot中,默认使用logging.debug()输出日志,而不是首先通过logging.getLogger设置logger来输出日志,这样如果我在其他项目中使用logging模块记录自己的日志时候,就会导致输出混乱,以下代码可以复现输出结果。最后一行logger.debug('Log 3, BAD!'),理应只输出2023-08-31 22:16:16,799 - mylogger - DEBUG - Log 3, BAD!这一行,但是却多了DEBUG:mylogger:Log 3, BAD!
import logging

logger = logging.getLogger('mylogger')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.debug('Log 1, OK!')
logger.debug('Log 2, OK!')
logging.critical('Log using logging')
logger.debug('Log 3, BAD!')
#example output
#2023-08-31 22:16:16,799 - mylogger - DEBUG - Log 1, OK!
#2023-08-31 22:16:16,799 - mylogger - DEBUG - Log 2, OK!
#CRITICAL:root:Log using logging
#2023-08-31 22:16:16,799 - mylogger - DEBUG - Log 3, BAD!
#DEBUG:mylogger:Log 3, BAD!
  • PR描述:在pycqLogger.py中定义了logger,通过该logger去输出日志则不会导致输出混乱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant