如果我在PDB中,为什么不将Python记录模块显示我的记录到屏幕?
我想让我的logging.info
在 Python Debugger(PDB)和文件。但是,它没有出现在屏幕上。它可以在单独的python控制台中工作。为什么它在PDB中不起作用?请参阅:
bot@18f71e53b3f5:~/pycoq/tutorial$ python brandos_pycoq_tutorial.py
> /home/bot/pycoq/tutorial/brandos_pycoq_tutorial.py(142)<module>()
-> main()
(Pdb) import logging
(Pdb)
(Pdb) level = logging.INFO
(Pdb) format = ' %(message)s'
(Pdb) handlers = [logging.FileHandler('./filename.log'), logging.StreamHandler()]
(Pdb)
(Pdb) logging.basicConfig(level = level, format = format, handlers = handlers)
(Pdb) logging.info('Hey, this is working!')
(Pdb) --KeyboardInterrupt--
(Pdb)
在控制台中的作品:
bot@18f71e53b3f5:~/pycoq/tutorial$ python
Python 3.9.12 (main, Jun 1 2022, 11:38:51)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>>
>>> level = logging.INFO
>>> format = ' %(message)s'
>>> handlers = [logging.FileHandler('./filename.log'), logging.StreamHandler()]
>>>
>>> logging.basicConfig(level = level, format = format, handlers = handlers)
>>> logging.info('Hey, this is working!')
Hey, this is working!
>>>
KeyboardInterrupt
>>>
该级别的设置正确如下所述:打印到屏幕上并同时写入文件
I want to have my logging.info
show in the terminal/screen in the Python debugger (pdb) and on file. However, it does not appear on the screen. It works in a seperate python console just fine. Why does it not work in pdb? See:
bot@18f71e53b3f5:~/pycoq/tutorial$ python brandos_pycoq_tutorial.py
> /home/bot/pycoq/tutorial/brandos_pycoq_tutorial.py(142)<module>()
-> main()
(Pdb) import logging
(Pdb)
(Pdb) level = logging.INFO
(Pdb) format = ' %(message)s'
(Pdb) handlers = [logging.FileHandler('./filename.log'), logging.StreamHandler()]
(Pdb)
(Pdb) logging.basicConfig(level = level, format = format, handlers = handlers)
(Pdb) logging.info('Hey, this is working!')
(Pdb) --KeyboardInterrupt--
(Pdb)
works in console:
bot@18f71e53b3f5:~/pycoq/tutorial$ python
Python 3.9.12 (main, Jun 1 2022, 11:38:51)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>>
>>> level = logging.INFO
>>> format = ' %(message)s'
>>> handlers = [logging.FileHandler('./filename.log'), logging.StreamHandler()]
>>>
>>> logging.basicConfig(level = level, format = format, handlers = handlers)
>>> logging.info('Hey, this is working!')
Hey, this is working!
>>>
KeyboardInterrupt
>>>
the level is set right as refered here: Printing to screen and writing to a file at the same time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是因为您的
brandos_pycoq_tutorial.py
脚本对sys.stderr
做点事。如果在pdb
中,它可以正常工作,如果您尝试过:我在Windows中进行了此操作,但是我希望它能在其他平台上以相同的方式工作。
It might be because your
brandos_pycoq_tutorial.py
script does something tosys.stderr
. It works fine if inpdb
if you try this:I did this in Windows, but I expect it will work the same way on other platforms.