1

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

Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323

1 Answers1

1

It might be because your brandos_pycoq_tutorial.py script does something to sys.stderr. It works fine if in pdb if you try this:

C:\Users\Vinay>python -c "import pdb; pdb.set_trace()"
--Return--
> <string>(1)<module>()->None
(Pdb) import logging
(Pdb) level = logging.INFO
(Pdb) format   = '  %(message)s'
(Pdb) handlers = [logging.FileHandler('./filename.log'), logging.StreamHandler()]
(Pdb) logging.basicConfig(level = level, format = format, handlers = handlers)
(Pdb) logging.info('Hey, this is working!')
  Hey, this is working!
(Pdb)

I did this in Windows, but I expect it will work the same way on other platforms.

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191